MAPIProviderSess.h
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // Session.h : Declaration of the CMAPIProviderSession
  2. #ifndef __CMAPIProviderSession_H_
  3. #define __CMAPIProviderSession_H_
  4. #include "resource.h"       // main symbols
  5. #include "MAPIProviderRS.h"
  6. class CMAPIProviderSessionTRSchemaRowset;
  7. class CMAPIProviderSessionColSchemaRowset;
  8. class CMAPIProviderSessionPTSchemaRowset;
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CMAPIProviderSession
  11. class ATL_NO_VTABLE CMAPIProviderSession : 
  12. public CComObjectRootEx<CComSingleThreadModel>,
  13. public IGetDataSourceImpl<CMAPIProviderSession>,
  14. public IOpenRowsetImpl<CMAPIProviderSession>,
  15. public ISessionPropertiesImpl<CMAPIProviderSession>,
  16. public IObjectWithSiteSessionImpl<CMAPIProviderSession>,
  17. public IDBSchemaRowsetImpl<CMAPIProviderSession>,
  18. public IDBCreateCommandImpl<CMAPIProviderSession, CMAPIProviderCommand>
  19. {
  20. public:
  21. CMAPIProviderSession()
  22. {
  23. }
  24. HRESULT FinalConstruct()
  25. {
  26. return FInit();
  27. }
  28. STDMETHOD(OpenRowset)(IUnknown *pUnk, DBID *pTID, DBID *pInID, REFIID riid,
  29.    ULONG cSets, DBPROPSET rgSets[], IUnknown **ppRowset)
  30. {
  31. CMAPIProviderRowset* pRowset;
  32. return CreateRowset(pUnk, pTID, pInID, riid, cSets, rgSets, ppRowset, pRowset);
  33. }
  34. BEGIN_PROPSET_MAP(CMAPIProviderSession)
  35. BEGIN_PROPERTY_SET(DBPROPSET_SESSION)
  36. PROPERTY_INFO_ENTRY(SESS_AUTOCOMMITISOLEVELS)
  37. END_PROPERTY_SET(DBPROPSET_SESSION)
  38. END_PROPSET_MAP()
  39. BEGIN_COM_MAP(CMAPIProviderSession)
  40. COM_INTERFACE_ENTRY(IGetDataSource)
  41. COM_INTERFACE_ENTRY(IOpenRowset)
  42. COM_INTERFACE_ENTRY(ISessionProperties)
  43. COM_INTERFACE_ENTRY(IObjectWithSite)
  44. COM_INTERFACE_ENTRY(IDBCreateCommand)
  45. COM_INTERFACE_ENTRY(IDBSchemaRowset)
  46. END_COM_MAP()
  47. BEGIN_SCHEMA_MAP(CMAPIProviderSession)
  48. SCHEMA_ENTRY(DBSCHEMA_TABLES, CMAPIProviderSessionTRSchemaRowset)
  49. SCHEMA_ENTRY(DBSCHEMA_COLUMNS, CMAPIProviderSessionColSchemaRowset)
  50. SCHEMA_ENTRY(DBSCHEMA_PROVIDER_TYPES, CMAPIProviderSessionPTSchemaRowset)
  51. END_SCHEMA_MAP()
  52. };
  53. class CMAPIProviderSessionTRSchemaRowset : 
  54. public CRowsetImpl< CMAPIProviderSessionTRSchemaRowset, CTABLESRow, CMAPIProviderSession>
  55. {
  56. public:
  57. HRESULT Execute(LONG* pcRowsAffected, ULONG, const VARIANT*)
  58. {
  59. USES_CONVERSION;
  60. CTABLESRow trData;
  61. lstrcpyW(trData.m_szType, OLESTR("TABLE"));
  62. lstrcpyW(trData.m_szDesc, OLESTR("The Mail Table"));
  63. lstrcpynW(trData.m_szTable, 
  64. T2OLE("Mail"), 
  65. SIZEOF_MEMBER(CTABLESRow, m_szTable));
  66. if (!m_rgRowData.Add(trData))
  67. return E_OUTOFMEMORY;
  68. *pcRowsAffected = 1;
  69. return S_OK;
  70. }
  71. };
  72. class CMAPIProviderSessionColSchemaRowset : 
  73. public CRowsetImpl< CMAPIProviderSessionColSchemaRowset, CCOLUMNSRow, CMAPIProviderSession>
  74. {
  75. public:
  76. HRESULT Execute(LONG* pcRowsAffected, ULONG, const VARIANT*)
  77. {
  78. const int NUMBERCOLUMNS = 4;
  79. USES_CONVERSION;
  80. CCOLUMNSRow crColumnInfo[NUMBERCOLUMNS];
  81. //******
  82.  
  83. // Initialize crColumnInfo to null
  84. memset(crColumnInfo, 0, sizeof(CCOLUMNSRow)*NUMBERCOLUMNS);
  85. // Fill out common fields between columns
  86. for (int column=0; column<NUMBERCOLUMNS; column++) {
  87. lstrcpyW(crColumnInfo[column].m_szTableName, 
  88. T2OLE("Mail"));
  89. crColumnInfo[column].m_ulOrdinalPosition = column+1;
  90. crColumnInfo[column].m_bIsNullable = VARIANT_FALSE;
  91. crColumnInfo[column].m_bColumnHasDefault = VARIANT_FALSE;
  92. crColumnInfo[column].m_ulColumnFlags = 0;
  93. crColumnInfo[column].m_nDataType = DBTYPE_STR;
  94. // Declare new schema row
  95. m_rgRowData.Add(crColumnInfo[column]);
  96. }
  97. // column names
  98. lstrcpyW(crColumnInfo[0].m_szColumnName, OLESTR("Author"));
  99. lstrcpyW(crColumnInfo[1].m_szColumnName, OLESTR("Subject"));
  100. lstrcpyW(crColumnInfo[2].m_szColumnName, OLESTR("Date"));
  101. lstrcpyW(crColumnInfo[3].m_szColumnName, OLESTR("Body"));
  102. // column descriptions
  103. lstrcpyW(crColumnInfo[0].m_szDescription, OLESTR("Class"));
  104. lstrcpyW(crColumnInfo[1].m_szDescription, OLESTR("Subject"));
  105. lstrcpyW(crColumnInfo[2].m_szDescription, OLESTR("Date"));
  106. lstrcpyW(crColumnInfo[3].m_szDescription, OLESTR("Body"));
  107. // column sizes
  108. crColumnInfo[0].m_ulCharMaxLength = 50;
  109. crColumnInfo[1].m_ulCharMaxLength = 256;
  110. crColumnInfo[2].m_ulCharMaxLength = 20;
  111. crColumnInfo[3].m_ulCharMaxLength = 1024;
  112. *pcRowsAffected = NUMBERCOLUMNS;  // for the four columns
  113. //******
  114. return S_OK;
  115. }
  116. };
  117. class CMAPIProviderSessionPTSchemaRowset : 
  118. public CRowsetImpl< CMAPIProviderSessionPTSchemaRowset, CPROVIDER_TYPERow, CMAPIProviderSession>
  119. {
  120. public:
  121. HRESULT Execute(LONG* pcRowsAffected, ULONG, const VARIANT*)
  122. {
  123. return S_OK;
  124. }
  125. };
  126. #endif //__CMAPIProviderSession_H_