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

书籍源码

开发平台:

Visual C++

  1. // MAPIProviderRS.h : Declaration of the CMAPIProviderRowset
  2. #ifndef __CMAPIProviderRowset_H_
  3. #define __CMAPIProviderRowset_H_
  4. #include "resource.h"       // main symbols
  5. //Added by Chuck Wood -- #include mapi.h for MAPI support
  6. #include <mapi.h>
  7. //Added by Chuck Wood -- Now for a bunch of early '90s C 
  8. //stuff.  No object-oriented here!
  9. typedef ULONG (FAR PASCAL *pMAPILOGON)(HWND, LPSTR, LPSTR, FLAGS, ULONG, LPLHANDLE);
  10. typedef ULONG (FAR PASCAL *pMAPILOGOFF)(LHANDLE, HWND, FLAGS,ULONG);
  11. typedef ULONG (FAR PASCAL *pMAPIFINDNEXT)(LHANDLE, HWND, LPSTR, LPSTR, FLAGS,
  12.                                      ULONG, LPSTR);
  13. typedef ULONG (FAR PASCAL *pMAPIREADMAIL)(LHANDLE, HWND, LPSTR, FLAGS, ULONG,
  14.                                      lpMapiMessage FAR *);
  15. #ifdef MAIN
  16. pMAPILOGON pfnMAPILogon;
  17. pMAPILOGOFF pfnMAPILogoff;
  18. pMAPIFINDNEXT pfnMAPIFindNext;
  19. pMAPIREADMAIL pfnMAPIReadMail;
  20. #else
  21. extern pMAPILOGON pfnMAPILogon;
  22. extern pMAPILOGOFF pfnMAPILogoff;
  23. extern pMAPIFINDNEXT pfnMAPIFindNext;
  24. extern pMAPIREADMAIL pfnMAPIReadMail;
  25. #endif
  26. class CMAPILayout 
  27. {
  28. public:
  29. char m_strAuthor[50];
  30. char m_strSubject[256];
  31. char m_strDate[20];
  32. char m_strBody[1024];
  33. BEGIN_PROVIDER_COLUMN_MAP(CMAPILayout)
  34. PROVIDER_COLUMN_ENTRY("Author", 1, m_strAuthor)
  35. PROVIDER_COLUMN_ENTRY("Subject", 2, m_strSubject)
  36. PROVIDER_COLUMN_ENTRY("Date", 3, m_strDate)
  37. PROVIDER_COLUMN_ENTRY("Body", 4, m_strBody)
  38. END_PROVIDER_COLUMN_MAP()
  39. };
  40. // CMAPIProviderCommand
  41. class ATL_NO_VTABLE CMAPIProviderCommand : 
  42. public CComObjectRootEx<CComSingleThreadModel>,
  43. public IAccessorImpl<CMAPIProviderCommand>,
  44. public ICommandTextImpl<CMAPIProviderCommand>,
  45. public ICommandPropertiesImpl<CMAPIProviderCommand>,
  46. public IObjectWithSiteImpl<CMAPIProviderCommand>,
  47. public IConvertTypeImpl<CMAPIProviderCommand>,
  48. public IColumnsInfoImpl<CMAPIProviderCommand>
  49. {
  50. public:
  51. BEGIN_COM_MAP(CMAPIProviderCommand)
  52. COM_INTERFACE_ENTRY(ICommand)
  53. COM_INTERFACE_ENTRY(IObjectWithSite)
  54. COM_INTERFACE_ENTRY(IAccessor)
  55. COM_INTERFACE_ENTRY(ICommandProperties)
  56. COM_INTERFACE_ENTRY2(ICommandText, ICommand)
  57. COM_INTERFACE_ENTRY(IColumnsInfo)
  58. COM_INTERFACE_ENTRY(IConvertType)
  59. END_COM_MAP()
  60. // ICommand
  61. public:
  62. HRESULT FinalConstruct()
  63. {
  64. HRESULT hr = CConvertHelper::FinalConstruct();
  65. if (FAILED (hr))
  66. return hr;
  67. hr = IAccessorImpl<CMAPIProviderCommand>::FinalConstruct();
  68. if (FAILED(hr))
  69. return hr;
  70. return CUtlProps<CMAPIProviderCommand>::FInit();
  71. }
  72. void FinalRelease()
  73. {
  74. IAccessorImpl<CMAPIProviderCommand>::FinalRelease();
  75. }
  76. HRESULT WINAPI Execute(IUnknown * pUnkOuter, REFIID riid, DBPARAMS * pParams, 
  77.   LONG * pcRowsAffected, IUnknown ** ppRowset);
  78. static ATLCOLUMNINFO* GetColumnInfo(CMAPIProviderCommand* pv, ULONG* pcInfo)
  79. {
  80. return CMAPILayout::GetColumnInfo(pv,pcInfo);
  81. }
  82. BEGIN_PROPSET_MAP(CMAPIProviderCommand)
  83. BEGIN_PROPERTY_SET(DBPROPSET_ROWSET)
  84. PROPERTY_INFO_ENTRY(IAccessor)
  85. PROPERTY_INFO_ENTRY(IColumnsInfo)
  86. PROPERTY_INFO_ENTRY(IConvertType)
  87. PROPERTY_INFO_ENTRY(IRowset)
  88. PROPERTY_INFO_ENTRY(IRowsetIdentity)
  89. PROPERTY_INFO_ENTRY(IRowsetInfo)
  90. PROPERTY_INFO_ENTRY(IRowsetLocate)
  91. PROPERTY_INFO_ENTRY(BOOKMARKS)
  92. PROPERTY_INFO_ENTRY(BOOKMARKSKIPPED)
  93. PROPERTY_INFO_ENTRY(BOOKMARKTYPE)
  94. PROPERTY_INFO_ENTRY(CANFETCHBACKWARDS)
  95. PROPERTY_INFO_ENTRY(CANHOLDROWS)
  96. PROPERTY_INFO_ENTRY(CANSCROLLBACKWARDS)
  97. PROPERTY_INFO_ENTRY(LITERALBOOKMARKS)
  98. PROPERTY_INFO_ENTRY(ORDEREDBOOKMARKS)
  99. END_PROPERTY_SET(DBPROPSET_ROWSET)
  100. END_PROPSET_MAP()
  101. };
  102. class CMAPIProviderRowset : public CRowsetImpl< CMAPIProviderRowset, CMAPILayout, CMAPIProviderCommand>
  103. {
  104. public:
  105. HRESULT Execute(DBPARAMS * pParams, LONG* pcRowsAffected)
  106. {
  107. USES_CONVERSION;
  108. LHANDLE hMAPISession;
  109. CMAPILayout ml;
  110. lpMapiMessage lppMessage;
  111. HMODULE hLibrary = LoadLibrary("MAPI32.DLL");
  112. if (hLibrary < (HANDLE)32)
  113. return DB_E_INVALID;
  114. //Now to allocate the functions witht the 
  115. //right function address ********************************
  116. pfnMAPILogon = (pMAPILOGON)GetProcAddress(hLibrary,"MAPILogon");
  117. if (!pfnMAPILogon) 
  118. return DB_E_INVALID;
  119. pfnMAPILogoff = (pMAPILOGOFF)GetProcAddress(hLibrary,"MAPILogoff");
  120. if (!pfnMAPILogoff)
  121. return DB_E_INVALID;
  122. pfnMAPIFindNext= (pMAPIFINDNEXT)GetProcAddress(hLibrary,"MAPIFindNext");
  123. if (!pfnMAPIFindNext)
  124. return DB_E_INVALID;
  125. pfnMAPIReadMail= (pMAPIREADMAIL)GetProcAddress(hLibrary,"MAPIReadMail");
  126. if (!pfnMAPIReadMail)
  127. return DB_E_INVALID;
  128. //********************************************
  129. if (( (*pfnMAPILogon)(0, NULL, NULL, 
  130. MAPI_NEW_SESSION | MAPI_LOGON_UI, 0L, 
  131. &hMAPISession))
  132. != SUCCESS_SUCCESS)
  133. return DB_E_INVALID;
  134. char lpszMessageID[512];
  135. strcpy (lpszMessageID, "");
  136. //Null terminate my strings for later
  137. ml.m_strAuthor[49] = 0;
  138. ml.m_strSubject[255] = 0;
  139. ml.m_strDate[19] = 0;
  140. ml.m_strBody[1023] = 0;
  141. while ((*pfnMAPIFindNext)( hMAPISession, 0, NULL, 
  142. lpszMessageID,
  143. MAPI_LONG_MSGID, 0,
  144. lpszMessageID)
  145. == SUCCESS_SUCCESS) {
  146. (*pfnMAPIReadMail)( hMAPISession, 0, 
  147. lpszMessageID,
  148. MAPI_PEEK, 0,
  149. &lppMessage);
  150. strncpy(ml.m_strAuthor,
  151. lppMessage->lpOriginator->lpszName, 49);
  152. strncpy(ml.m_strSubject,
  153. lppMessage->lpszSubject,255);
  154. strncpy(ml.m_strDate,
  155. lppMessage->lpszDateReceived, 19);
  156. strncpy(ml.m_strBody,
  157. lppMessage->lpszNoteText, 1023);
  158. if (!m_rgRowData.Add(ml))
  159. return E_OUTOFMEMORY;
  160. *pcRowsAffected++;
  161. }
  162. (*pfnMAPILogoff)(hMAPISession, 0, 0, 0);
  163. FreeLibrary(hLibrary); //Close Mail Library
  164. return S_OK;
  165. }
  166. };
  167. #endif //__CMAPIProviderRowset_H_