COMWINDS.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:26k
源码类别:

Windows编程

开发平台:

Visual C++

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  File Name 
  4. //      COMWINDS.H
  5. //
  6. //  Description
  7. //      Common remote call and client-side utility functions for provider
  8. //      communicating with the WINDS messaging host.
  9. //
  10. //  Author
  11. //      Irving De la Cruz
  12. //
  13. //  Revision: 1.7
  14. //
  15. // Written for Microsoft Windows Developer Support
  16. // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
  17. //
  18. #ifndef _COMWINDS_H
  19. #define _COMWINDS_H
  20. #define STRICT
  21. #include <WINDOWS.H>
  22. #include <WINDOWSX.H>
  23. #include <CTL3D.H>
  24. #include <MAPIWIN.H>
  25. #include <MAPISPI.H>
  26. #include <MAPIUTIL.H>
  27. #include <MAPICODE.H>
  28. #include <MAPIVAL.H>
  29. #include <MAPIWZ.H>
  30. // Constants for communicating with the WINDS Server Messaging Host
  31. #include "WINDSGBL.H"
  32. // Header file for the trace and logging functions.
  33. #include "TRACES.H"
  34. // This header file is generated by the MIDL compiler
  35. #include "WINDS.H"
  36. #include "UISRVCS.H"
  37. #ifdef UNICODE
  38. #define RemoteChangePassword            RemoteChangePasswordW
  39. #define RemoteLogonMailBox              RemoteLogonMailBoxW
  40. #define RemoteLogonMailBoxAndSetNotif   RemoteLogonMailBoxAndSetNotifW
  41. #define RemoteTerminateNotif            RemoteTerminateNotifW
  42. #define RemoteValidateNotif             RemoteValidateNotifW
  43. #define RemoteOpenMsgUploadPipe         RemoteOpenMsgUploadPipeW
  44. #define RemoteSendMsgToAccount          RemoteSendMsgToAccountW
  45. #define RemoteOpenMsgDownloadPipe       RemoteOpenMsgDownloadPipeW
  46. #define RemoteOpenHeaderDownloadPipe    RemoteOpenHeaderDownloadPipeW
  47. #define RemoteCheckNewMail              RemoteCheckNewMailW
  48. #define RemoteOpenOneMsgDownloadPipe    RemoteOpenOneMsgDownloadPipeW
  49. #define RemoteGetRecipientProps         RemoteGetRecipientPropsW
  50. #define RemoteGetDistListProps          RemoteGetDistListPropsW
  51. #else
  52. #define RemoteChangePassword            RemoteChangePasswordA
  53. #define RemoteLogonMailBox              RemoteLogonMailBoxA
  54. #define RemoteLogonMailBoxAndSetNotif   RemoteLogonMailBoxAndSetNotifA
  55. #define RemoteTerminateNotif            RemoteTerminateNotifA
  56. #define RemoteValidateNotif             RemoteValidateNotifA
  57. #define RemoteOpenMsgUploadPipe         RemoteOpenMsgUploadPipeA
  58. #define RemoteSendMsgToAccount          RemoteSendMsgToAccountA
  59. #define RemoteOpenMsgDownloadPipe       RemoteOpenMsgDownloadPipeA
  60. #define RemoteOpenHeaderDownloadPipe    RemoteOpenHeaderDownloadPipeA
  61. #define RemoteCheckNewMail              RemoteCheckNewMailA
  62. #define RemoteOpenOneMsgDownloadPipe    RemoteOpenOneMsgDownloadPipeA
  63. #define RemoteGetRecipientProps         RemoteGetRecipientPropsA
  64. #define RemoteGetDistListProps          RemoteGetDistListPropsA
  65. #endif // UNICODE
  66. // Custom properties used by this service provider. These properties are
  67. // non-transmittable and only used in the configuration and private
  68. // profile section of this provider/service.
  69. #define BASE_PROVIDER_ID                    0x6600  // Look at the comments in MAPITAGS.H
  70. // Common Custom Properties for all WINDS service providers
  71. #define PR_SMP_REMOTE_SERVER            PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0000))
  72. #define PR_SMP_USER_NAME                PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0001))
  73. #define PR_SMP_BROWSE_MB                PROP_TAG (PT_OBJECT,     (BASE_PROVIDER_ID + 0x0002))
  74. #define PR_SMP_CHANGE_PASSWORD          PROP_TAG (PT_OBJECT,     (BASE_PROVIDER_ID + 0x0003))
  75. #define PR_SMP_SESSION_UID              PROP_TAG (PT_BINARY,     (BASE_PROVIDER_ID + 0x0004))
  76. #define PR_SMP_CONNECTION_TYPE          PROP_TAG (PT_LONG,       (BASE_PROVIDER_ID + 0x0005))
  77. // Secured properties that users should not see by looking at the registry.
  78. // On Windows NT the registry is secured by the system. On Windows 95, this
  79. // properties are stored encrypted, along with the system's list of passwords
  80. #define PR_SMP_MAILBOX_NAME         PROP_TAG (PT_TSTRING,    (PROP_ID_SECURE_MIN + 0x0001))
  81. #define PR_SMP_MAILBOX_ID           PROP_TAG (PT_LONG,       (PROP_ID_SECURE_MIN + 0x0002))
  82. #define PR_SMP_MAILBOX_PASSWORD     PROP_TAG (PT_TSTRING,    (PROP_ID_SECURE_MIN + 0x0003))
  83.                                                              
  84. // Address books                                             
  85. #define PR_SMP_LUL_LAST_UPDATE      PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0020))
  86. #define PR_SMP_LUL_FILENAME         PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0021))
  87. #define PR_SMP_LUL_DOWNLOAD         PROP_TAG (PT_OBJECT,     (BASE_PROVIDER_ID + 0x0022))
  88. #define PR_SMP_MANAGER_NAME_TBL     PROP_TAG (PT_OBJECT,     (BASE_PROVIDER_ID + 0x0023))
  89. // Custom properties for IMailUser and IDistList objects. This properties are in the named
  90. // property range so that PAB address books and other writeable address books may copy them.
  91. // Address book service providers should not use the 0x6600-0x67FF property ID range for
  92. // custom properties in the recipient objects. Instead user NAMED properties
  93. #define PR_WINDS_AB_MANAGER_NAME        PROP_TAG (PT_TSTRING, 0x8000)
  94. #define PR_WINDS_AB_MANAGER_ENTRYID     PROP_TAG (PT_BINARY,  0x8001)
  95. #define PR_WINDS_AB_DL_OWNER_ACCT       PROP_TAG (PT_TSTRING, 0x8002)
  96. #define PR_WINDS_AB_DL_OWNER_NAME       PROP_TAG (PT_TSTRING, 0x8003)
  97. // Address entry named property names. They have to be UNICODE strings
  98. #define WINDS_AB_MANAGER_NAME       L"WINDS AB - Manager Name"
  99. #define WINDS_AB_MANAGER_EID        L"WINDS AB - Manager Entry ID"
  100. #define WINDS_AB_DL_OWNER_ACCT      L"WINDS AB - DL Owner Account"
  101. #define WINDS_AB_DL_OWNER_NAME      L"WINDS AB - DL Owner Name"
  102. // Transports                                                
  103. #define PR_SMP_UPLOAD_TIME          PROP_TAG (PT_SYSTIME,    (BASE_PROVIDER_ID + 0x0040))
  104. #define PR_SMP_HEADERS_FILENAME     PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0041))
  105. #define PR_TMP_UPLOAD_TIME          PROP_TAG (PT_TSTRING,    (BASE_PROVIDER_ID + 0x0042))
  106. #define PR_SMP_GET_HEADERS          PROP_TAG (PT_BOOLEAN,    (BASE_PROVIDER_ID + 0x0043))
  107. // Values available for PR_SMP_CONNECTION_TYPE
  108. typedef enum _CONNECTION_TYPE
  109. {
  110.     // Don't change the order of these unless the string resources ID's are modified accordingly
  111.     LAN_CONNECT         = 1,    
  112.     OFFLINE_CONNECT     = 2,
  113.     CONNECTION_BROKEN   = 3,
  114.     NOT_AVAIL_NO_ABD    = 4
  115. } CONNECTION_TYPE;
  116. // Index properties into the logon property array of ALL providers using the WINDS server
  117. enum
  118. {
  119.     SERVER_NAME             = 0,
  120.     MAILBOX_NAME            = 1,
  121.     MAILBOX_ID              = 2,
  122.     USER_NAME               = 3, 
  123.     PASSWORD                = 4,
  124.     NET_CON                 = 5,
  125.     // Number of properties the WIZARD setup pages collect for the configuration of the WINDS providers
  126.     WIZARD_PROPERTIES       = 5
  127. };
  128. // Number of controls in the configuration page of ALL WINDS Providers
  129. #define NUM_CFG_USERINFO_PAGE_CTLS     13
  130. // Structure passed to the configuration dialog.
  131. typedef struct _CFGDLG
  132. {
  133.     HINSTANCE      hInst;      // Instance of provider's DLL for loading resources for the UI
  134.     HWND           hWnd;       // Handle of parent window or NULL is not UI should be used
  135.     LPSPropValue * ppProps;    // Property array with the configuration properties
  136.     LPMAPISUP      pSupObj;    // IMAPISupport object for creating the UI property sheets
  137.     ULONG          ulFlags;    // 0 or UI_READONLY for access control to the configuration values
  138.     HANDLE         hUIMutex;   // Handle to the MUTEX to control exclusive access to the configuration UI
  139. } CFGDLG, *PCFGDLG;
  140. // This code is to protect on reentrancy in the function
  141. // that display the configuration UI for the WINDS services
  142. #define CONFIG_UI_MUTEX     TEXT("WINDS_SERVICE_CONFIG_UI_MUTEX")
  143. // PR_AB_PROVIDER_ID is the GUID that represents this Address Book Provider.
  144. // This GUID is available as a property in the hierarchy. The UID is hard coded.
  145. // This number is generated only once per provider during the developement
  146. // of it using the standard tools (GUIDGEN or UUIDGEN) in VC++ or the Win32 SDK.
  147. // With this number you could identify your provider across multiple platforms.
  148. // GUIDGEN: 0xe33c67a0, 0xc81f, 0x11ce, 0xb2, 0xe4, 0x0, 0xaa, 0x0, 0x51, 0xe, 0x3b
  149. // This is the UID of the entry ID of objects in the WINDS address book provider.
  150. #define AB_UID_PROVIDER { 0xe3, 0x3c, 0x67, 0xa0, 
  151.                           0xc8, 0x1f, 0x11, 0xce, 
  152.                           0xb2, 0xe4, 0x0,  0xaa, 
  153.                           0x0,  0x51, 0xe,  0x3b }
  154. // This is the UID in the entry ID's the a WINDS transport uses to open entries in
  155. // the WINDS address book, through the support object.
  156. // This UID is hard coded because we only allow one instance of our provider
  157. // to be installed in a single profile at any time.
  158. // GUIDGEN: 0x8B43A160, 0xDFAC, 0x11ce, 0xB2, 0xEC, 0x00, 0xAA, 0x00, 0x51, 0x0E, 0x3B
  159. #define XP_WINDS_AB_ENTRIES { 0x8b, 0x43, 0xa1, 0x60, 
  160.                               0xdf, 0xac, 0x11, 0xce, 
  161.                               0xb2, 0xec, 0x0,  0xaa, 
  162.                               0x0,  0x51, 0xe,  0x3b }
  163. // This is the private entry ID structure for entries that a WINDS transport
  164. // would like to open in the WINDS address book
  165. typedef struct _PRIVATE_XP_ENTRYID
  166. {
  167.     // MAPI-required fields
  168.     BYTE        abFlags[4];         // 4 bytes      // MAPI Flags
  169.     MAPIUID     uidGlobal;          // 16 bytes     // UID Unique for XP entries
  170.     // Provider-defined fields
  171.     MAPIUID     uidWINDSEntries;    // 16 bytes     // UID Unique for WINDS entries in the WINDS address book
  172.     char        szObjectAlias[34];  // 34 bytes
  173.                                     // 70 Bytes Total
  174. } PRIVATE_XP_ENTRYID;
  175. #define     CB_PRIVATE_XP_EID       70      // Size of the structure above
  176. // This is the subdirectory in the TEMP directoy where WINDS service
  177. // providers create temporary data files
  178. #define WINDS_DATA_DIRECTORY                TEXT("WINDS Messaging Services Data Files")
  179. // This is the directory where the temporary files for downloaded messages are stored
  180. #define WINDS_DOWNLOAD_DIR_NAME_FORMAT      TEXT("%s\Pending Downloads - %s")
  181. #define XP_MSG_FILE_PREFIX                  TEXT("XRM")
  182. #define XP_MSG_FILE_SUFFIX                  TEXT("TMP")
  183. // Variables and static data structure used by all WINDS providers 
  184. extern "C"
  185. {
  186.     extern HINSTANCE    ghInstance;
  187.     extern TCHAR        szBlank[];
  188.     extern TCHAR        szFilter[];
  189.     extern TCHAR        szPhoneFilter[];
  190.     extern TCHAR        szTimeFilter[];
  191.     extern DTBLLABEL    DtLabel;
  192.     extern DTBLGROUPBOX DtGroupBox;
  193.     extern DTBLPAGE     DtPage;
  194.     extern DTBLEDIT     DtObjAlias;
  195.     extern DTBLEDIT     DtObjFullName;
  196.     extern DTBLEDIT     DtUserName;
  197.     extern DTBLEDIT     DtServer;
  198.     extern DTBLEDIT     DtComment;
  199.     extern DTCTL        UserConfigPage[];
  200. };
  201. int WINAPI PrivateMessageBox
  202.                     (UINT                       ids, 
  203.                      HWND                       hOwnerWnd = NULL,
  204.                      UINT                       uFlags = MB_OK | MB_ICONSTOP,
  205.                      HINSTANCE                  hInst = NULL);
  206. extern "C"
  207. {
  208.     HRESULT WINAPI BindToServer
  209.                     (LPTSTR                     szServer);
  210.     BOOL WINAPI IsWINDSServerAvailable
  211.                     (LPTSTR                     szServerName);
  212.     BOOL WINAPI PingRemoteServer
  213.                     (HWND                       hOwnerWnd,
  214.                      LPSPropValue               pProps);
  215.     BOOL WINAPI IsValidServerName
  216.                     (LPTSTR                     szServerName);
  217.     HRESULT WINAPI DoServerLogon
  218.                     (PMAILBOX_INFO              pMBInfo,
  219.                      LPSPropValue               pProps,
  220.                      LPPROFSECT                 pProfileObj,
  221.                      BOOL                       fUIAllowed,
  222.                      HWND                       hOwnerWnd,
  223.                      BOOL                       fSetNotification,
  224.                      DWORD                      dwNotifMask,
  225.                      DWORD *                    pdwConnectID,
  226.                      BOOL                       fOffLineOK);
  227.     HRESULT WINAPI ChangeMBServerPassword
  228.                     (LPTSTR                     szServerName,
  229.                      LPTSTR                     szMailboxName,
  230.                      LPTSTR                     szOldPassword,
  231.                      LPTSTR                     szNewPassword);
  232.     HRESULT WINAPI TerminateServerNotifications
  233.                     (LPTSTR                     szServerName,
  234.                      DWORD                      dwConnectionID);
  235.     HRESULT WINAPI ResetServerNotifications
  236.                     (LPTSTR                     szServerName,
  237.                      LPTSTR                     szMailboxName,
  238.                      DWORD                      dwNotifMask,
  239.                      DWORD *                    pdwConnectionID);
  240.     void WINAPI TerminateRemoteConnections
  241.                     ();
  242.     HRESULT WINAPI MergeConfigProps
  243.                     (ULONG                      ulCfgProps,
  244.                      LPSPropValue               pCfgProps,
  245.                      LPSPropValue               pLogonProps);
  246.     HRESULT WINAPI OpenServiceProfileSection
  247.                     (LPMAPISUP                  pSupObj,
  248.                      LPPROFSECT *               ppProfSectObj,
  249.                      LPFREEBUFFER               pfnFreeBuffer);
  250.     // Transport Providers
  251.     HRESULT WINAPI OpenServerUploadPipe
  252.                     (LPTSTR                     szServerName,
  253.                      LPTSTR                     szSenderMailbox,
  254.                      HANDLE                     hMsgFile,
  255.                      LPTSTR                     szConnectionInfo,
  256.                      BOOL *                     pfErrorInTheServer);
  257.     HRESULT WINAPI SendMsgToAccount
  258.                     (LPTSTR                     szServerName,
  259.                      LPTSTR                     szRecipMailbox,
  260.                      LPTSTR                     szHeader,
  261.                      LPTSTR                     szConnectionInfo,
  262.                      BOOL *                     pfErrorInTheServer);
  263.     HRESULT WINAPI FinishUploadConnection
  264.                     (LPTSTR                     szServerName,
  265.                      LPTSTR                     szConnectionInfo);
  266.     HRESULT WINAPI GetHeadersFromServer
  267.                     (LPTSTR                     szServerName,
  268.                      LPTSTR                     szMailbox,
  269.                      LPTSTR                     szHeaderFile);
  270.     HRESULT WINAPI OpenRemoteServerDownLoadPipe
  271.                     (LPTSTR                     szServer,
  272.                      LPTSTR                     szMBox,
  273.                      HANDLE *                   phPipe);
  274.     HRESULT WINAPI GetNextMailboxMsg
  275.                     (LPTSTR                     szServer,
  276.                      LPTSTR                     szMailbox,
  277.                      LPTSTR                     szLocalMsgFile);
  278.     HRESULT WINAPI CheckForPendingMessages
  279.                     (LPTSTR                     szServerName,
  280.                      LPTSTR                     szMailboxName,
  281.                      ULONG *                    pulMsgWaiting);
  282. };
  283. // CTL3D Dynamic Loading Support
  284. void WINAPI PrivInitialize3DCtl
  285.                     (HINSTANCE                  hInstance);
  286. void WINAPI PrivUninitialize3DCtl
  287.                     (HINSTANCE                  hInstance);
  288. // Forward declarations
  289. class CUIMAPIProp;
  290. // Custom callback function prototype for the implementation
  291. // and activation of IMAPIControl on display tables on property sheets.
  292. typedef void (STDAPICALLTYPE BUTTONCALLBACK) (CUIMAPIProp * pObj, HWND hOwnerWnd, HINSTANCE hInstance);
  293. typedef BUTTONCALLBACK *LPBUTTONCALLBACK;
  294. class CUIMAPIProp : public IMAPIProp
  295. {
  296. public:
  297.     inline STDMETHODIMP QueryInterface
  298.                     (REFIID                     riid,
  299.                      LPVOID *                   ppvObj)
  300.                     { *ppvObj = NULL;
  301.                       HRESULT hResult = S_OK;
  302.                       EnterCriticalSection (&m_csObj);
  303.                       if (riid == IID_IMAPIProp || riid == IID_IUnknown)
  304.                       {
  305.                           *ppvObj = (LPVOID)this;
  306.                           AddRef();
  307.                       }
  308.                       else
  309.                       {
  310.                           hResult = E_NOINTERFACE;
  311.                       }
  312.                       LeaveCriticalSection (&m_csObj);
  313.                       return hResult; }
  314.     inline STDMETHODIMP_(ULONG) AddRef
  315.                     () { EnterCriticalSection (&m_csObj);
  316.                          ++m_cRef; ULONG ulCount = m_cRef;
  317.                          LeaveCriticalSection (&m_csObj);
  318.                          return ulCount; }
  319.     inline STDMETHODIMP_(ULONG) Release
  320.                     () { EnterCriticalSection (&m_csObj);
  321.                          ULONG ulCount = --m_cRef;
  322.                          LeaveCriticalSection (&m_csObj);
  323.                          if (!ulCount) { delete this; }
  324.                          return ulCount;}
  325.     inline STDMETHODIMP GetLastError
  326.                     (HRESULT                    hResult,
  327.                      ULONG                      ulFlags,
  328.                      LPMAPIERROR *              ppMAPIError)
  329.                     { return m_pImpObj->GetLastError (hResult, ulFlags, ppMAPIError); }
  330.     inline STDMETHODIMP SaveChanges
  331.                     (ULONG                      ulFlags)
  332.                     { return S_OK; }
  333.     inline STDMETHODIMP GetProps
  334.                     (LPSPropTagArray            pPropTagArray,
  335.                      ULONG                      ulFlags,
  336.                      ULONG *                    pcValues,
  337.                      LPSPropValue *             ppPropArray)
  338.                     { return m_pImpObj->GetProps (pPropTagArray, ulFlags, pcValues, ppPropArray); }
  339.     inline STDMETHODIMP GetPropList
  340.                     (ULONG                      ulFlags,
  341.                      LPSPropTagArray *          ppAllTags)
  342.                     { return m_pImpObj->GetPropList (ulFlags, ppAllTags); }
  343.     STDMETHODIMP OpenProperty
  344.                     (ULONG                      ulPropTag,
  345.                      LPCIID                     piid,
  346.                      ULONG                      ulInterfaceOptions,
  347.                      ULONG                      ulFlags,
  348.                      LPUNKNOWN *                ppUnk);
  349.     inline STDMETHODIMP SetProps
  350.                     (ULONG                      cValues,
  351.                      LPSPropValue               pPropArray,
  352.                      LPSPropProblemArray *      ppProblems)
  353.                     { return m_pImpObj->SetProps (cValues, pPropArray, ppProblems); }
  354.     inline STDMETHODIMP DeleteProps
  355.                     (LPSPropTagArray            pPropTagArray,
  356.                      LPSPropProblemArray *      ppProblems)
  357.                     { return m_pImpObj->DeleteProps (pPropTagArray, ppProblems); }
  358.     inline STDMETHODIMP CopyTo
  359.                     (ULONG                      ciidExclude,
  360.                      LPCIID                     rgiidExclude,
  361.                      LPSPropTagArray            pExcludeProps,
  362.                      ULONG                      ulUIParam,
  363.                      LPMAPIPROGRESS             pProgress,
  364.                      LPCIID                     pInterface,
  365.                      LPVOID                     pDestObj,
  366.                      ULONG                      ulFlags,
  367.                      LPSPropProblemArray *      ppProblems)
  368.                     { return m_pImpObj->CopyTo (ciidExclude, rgiidExclude, pExcludeProps, ulUIParam, pProgress, pInterface, pDestObj, ulFlags, ppProblems); }
  369.     inline STDMETHODIMP CopyProps
  370.                     (LPSPropTagArray            pIncludeProps,
  371.                      ULONG                      ulUIParam,
  372.                      LPMAPIPROGRESS             pProgress,
  373.                      LPCIID                     pInterface,
  374.                      LPVOID                     pDestObj,
  375.                      ULONG                      ulFlags,
  376.                      LPSPropProblemArray *      ppProblems)
  377.                     { return m_pImpObj->CopyProps (pIncludeProps, ulUIParam, pProgress, pInterface, pDestObj, ulFlags, ppProblems); }
  378.     inline STDMETHODIMP GetNamesFromIDs
  379.                     (LPSPropTagArray *          ppPropTags,
  380.                      LPGUID                     pPropSetGuid,
  381.                      ULONG                      ulFlags,
  382.                      ULONG *                    pcPropNames,
  383.                      LPMAPINAMEID **            pppPropNames)
  384.                     { return MAPI_E_NO_SUPPORT; }
  385.     inline STDMETHODIMP GetIDsFromNames
  386.                     (ULONG                      cPropNames,
  387.                      LPMAPINAMEID *             ppPropNames,
  388.                      ULONG                      ulFlags,
  389.                      LPSPropTagArray *          ppPropTags)
  390.                     { return MAPI_E_NO_SUPPORT; }
  391. ///////////////////////////////////////////////////////////////////////////////
  392. // Other methods private to this class
  393. //
  394.     inline void WINAPI SetTableData
  395.                     (LPTABLEDATA                pTable)
  396.                     { m_pTableData = pTable; m_pTableData->AddRef(); }
  397.     inline void WINAPI SetPropCallBack
  398.                     (ULONG                      ulPropTag,
  399.                      LPBUTTONCALLBACK           pfnCallBack)
  400.                     { m_ulCustomPropTag = ulPropTag; m_pfnCallBack = pfnCallBack; }
  401. ///////////////////////////////////////////////////////////////////////////////
  402. // Constructors and destructors
  403. //
  404. public :
  405.     CUIMAPIProp     (HINSTANCE                  hInstance,
  406.                      LPALLOCATEBUFFER           pfnAllocateBuffer,
  407.                      LPALLOCATEMORE             pfnAllocateMore,
  408.                      LPFREEBUFFER               pfnFreeBuffer,
  409.                      BOOL                       fReadOnly);
  410.     ~CUIMAPIProp    () { m_pImpObj->Release(); m_pImpObj = NULL;
  411.                          if (m_pTableData) { m_pTableData->Release(); }
  412.                          DeleteCriticalSection (&m_csObj);}
  413. ///////////////////////////////////////////////////////////////////////////////
  414. // Data members
  415. //
  416. private :
  417.     ULONG               m_cRef;
  418.     BOOL                m_fReadOnly;
  419.     LPPROPDATA          m_pImpObj;
  420.     ULONG               m_ulCustomPropTag;
  421.     LPBUTTONCALLBACK    m_pfnCallBack;
  422.     CRITICAL_SECTION    m_csObj;
  423. public :
  424.     LPTABLEDATA         m_pTableData;
  425.     HINSTANCE           m_hInstance;
  426. };
  427. class CMAPIControl : public IMAPIControl
  428. {
  429.     inline STDMETHODIMP QueryInterface
  430.                     (REFIID                     riid,
  431.                      LPVOID *                   ppvObj)
  432.                     { *ppvObj = NULL;
  433.                       HRESULT hResult = S_OK;
  434.                       EnterCriticalSection (&m_csObj);
  435.                       if (riid == IID_IMAPIControl || riid == IID_IUnknown)
  436.                       {
  437.                           *ppvObj = (LPVOID)this;
  438.                           // Increase usage count of this object
  439.                           AddRef();
  440.                       }
  441.                       else
  442.                       {
  443.                           hResult = E_NOINTERFACE;
  444.                       }
  445.                       LeaveCriticalSection (&m_csObj);
  446.                       return hResult; }
  447.     inline STDMETHODIMP_(ULONG) AddRef
  448.                     () { EnterCriticalSection (&m_csObj);
  449.                          ++m_cRef; ULONG ulCount = m_cRef;
  450.                          LeaveCriticalSection (&m_csObj);
  451.                          return ulCount; }
  452.     inline STDMETHODIMP_(ULONG) Release
  453.                     () { EnterCriticalSection (&m_csObj);
  454.                          ULONG ulCount = --m_cRef;
  455.                          LeaveCriticalSection (&m_csObj);
  456.                          if (!ulCount) { delete this; }
  457.                          return ulCount;}
  458.     inline STDMETHODIMP GetLastError
  459.                     (HRESULT                    hResult,
  460.                      ULONG                      ulFlags,
  461.                      LPMAPIERROR *              ppMAPIError)
  462.                     { return MAPI_E_NO_SUPPORT; }
  463.     inline STDMETHODIMP GetState
  464.                     (ULONG                      ulFlags,
  465.                      ULONG *                    pulState)
  466.                     { *pulState = (m_fReadOnly ? MAPI_DISABLED : MAPI_ENABLED); return S_OK; }
  467.     inline STDMETHODIMP Activate
  468.                     (ULONG                      ulFlags,
  469.                      ULONG                      ulUIParam)
  470.                     { (*m_pfnCallBack)(m_pProp, (HWND)ulUIParam, m_pProp->m_hInstance); return S_OK; }
  471. ///////////////////////////////////////////////////////////////////////////////
  472. // Constructors and destructors
  473. //
  474. public :
  475.     CMAPIControl    (CUIMAPIProp *              pProp,
  476.                      LPBUTTONCALLBACK           pfnCallBack,
  477.                      BOOL                       fReadOnly)
  478.                     { m_cRef = 1; m_pfnCallBack = pfnCallBack; m_fReadOnly = fReadOnly;
  479.                       m_pProp = pProp; m_pProp->AddRef();
  480.                       InitializeCriticalSection (&m_csObj); }
  481.     ~CMAPIControl   ()
  482.                     { m_pProp->Release();
  483.                       DeleteCriticalSection (&m_csObj);}
  484. ///////////////////////////////////////////////////////////////////////////////
  485. // Data members
  486. //
  487. private :
  488.     ULONG               m_cRef;
  489.     LPBUTTONCALLBACK    m_pfnCallBack;
  490.     BOOL                m_fReadOnly;
  491.     CUIMAPIProp *       m_pProp;
  492.     CRITICAL_SECTION    m_csObj;
  493. };
  494. #endif // _COMWINDS_H
  495. // End of file for COMWINDS.H