/** * @file XTPCalendarMAPIWrapper.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #ifndef _XTP_INCLUDE_CALENDAR_MAPI # error Use _XTP_INCLUDE_CALENDAR_MAPI to enable Calendar MAPI support. #else # if !defined(__XTPCALENDARMAPIWRAPPER_H__) # define __XTPCALENDARMAPIWRAPPER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" # define TYPEDEF_WRAPPER_POINTER(val, type, proc) \ const int xtpWrapper##proc = val; \ const LPCSTR xtpWrapperProc##proc = #proc; \ typedef type(__stdcall* PFN##proc) # define TYPEDEF_WRAPPER_PTR_NUM(val, type, proc, num) \ const int xtpWrapper##proc = val; \ const LPCSTR xtpWrapperProc##proc = #proc "@" #num; \ typedef type(__stdcall* PFN##proc) TYPEDEF_WRAPPER_POINTER(0, HRESULT, MAPIInitialize)(LPVOID); TYPEDEF_WRAPPER_POINTER(1, void, MAPIUninitialize)(); TYPEDEF_WRAPPER_POINTER(2, HRESULT, MAPILogonEx)(ULONG, LPTSTR, LPTSTR, FLAGS, LPMAPISESSION FAR*); TYPEDEF_WRAPPER_POINTER(3, ULONG, MAPIFreeBuffer)(LPVOID); TYPEDEF_WRAPPER_PTR_NUM(4, ULONG, UlRelease, 4)(LPVOID); TYPEDEF_WRAPPER_PTR_NUM(5, void, FreeProws, 4)(LPSRowSet); TYPEDEF_WRAPPER_PTR_NUM(6, HRESULT, HrQueryAllRows, 24) (LPMAPITABLE, LPSPropTagArray, LPSRestriction, LPSSortOrderSet, LONG, LPSRowSet FAR*); TYPEDEF_WRAPPER_PTR_NUM(7, HRESULT, HrGetOneProp, 12)(LPMAPIPROP, ULONG, LPSPropValue FAR*); TYPEDEF_WRAPPER_PTR_NUM(8, HRESULT, HrSetOneProp, 8)(LPMAPIPROP, LPSPropValue); TYPEDEF_WRAPPER_POINTER(9, SCODE, MAPIAllocateBuffer)(ULONG, LPVOID FAR*); TYPEDEF_WRAPPER_PTR_NUM(10, HRESULT, HrThisThreadAdviseSink, 8) (LPMAPIADVISESINK, LPMAPIADVISESINK FAR*); TYPEDEF_WRAPPER_PTR_NUM(11, HRESULT, HrAllocAdviseSink, 12) (LPNOTIFCALLBACK, LPVOID, LPMAPIADVISESINK FAR*); /** * @brief * The CXTPCalendarMAPIWrapper class wraps the mapi32.dll API. */ class _XTP_EXT_CLASS CXTPCalendarMAPIWrapper { public: /** * @brief * Constructs a CXTPCalendarMAPIWrapper object. */ CXTPCalendarMAPIWrapper(); /** * @brief * Destroys a CXTPCalendarMAPIWrapper object, handles cleanup and * deallocation. */ virtual ~CXTPCalendarMAPIWrapper(); ///////////////////////////////////////////////////////////////////////// // Wrapped methods /** * @brief * Increments the MAPI subsystem reference count and initializes * global data for the MAPI DLL. * * @param lpMapiInit [in] Pointer to a MAPIINIT_0 structure. * The lpMapiInit parameter can be set to NULL. * * @return Returns S_OK if MAPI subsystem was initialized successfully, * or an error value otherwise. */ HRESULT MAPIInitialize(LPVOID lpMapiInit); /** * @brief * Decrements the reference count, cleans up, and deletes * per-instance global data for the MAPI DLL. */ void MAPIUninitialize(); /** * @brief * Logs a client application on to a session with the messaging system.. * * @param ulUIParam [in] Handle to the window to which the logon dialog box is modal. * If no dialog box is displayed during the call, * the ulUIParam parameter is ignored. This parameter can be zero.. * @param lpszProfileName [in] Pointer to a string containing the name of the profile to use * when logging on. This string is limited to 64 characters. * @param lpszPassword [in] Pointer to a string containing the password of the profile. * The lpszPassword parameter can be NULL whether or not the * lpszProfileName parameter is NULL. This string is limited to 64 * characters. . * @param flFlags [in] Bitmask of flags used to control how logon is performed. * See API MAPILogonEx description for more info. * @param lppSession [out] Pointer to a pointer to the MAPI session interface. * * @return S_OK - The logon succeeded. * MAPI_E_LOGON_FAILED - The logon did not succeed, either because one or more of the * parameters to MAPILogonEx were invalid or because there were * too many sessions open already. * MAPI_E_TIMEOUT - MAPI serializes all logons through a mutex. This is returned if * the MAPI_TIMEOUT_SHORT flag was set and another thread held the * mutex. * MAPI_E_USER_CANCEL - The user canceled the operation, typically by clicking * the Cancel button in a dialog box. */ HRESULT MAPILogonEx(ULONG ulUIParam, LPTSTR lpszProfileName, LPTSTR lpszPassword, FLAGS flFlags, LPMAPISESSION FAR* lppSession); /** * @brief * Frees a memory buffer allocated with a call to the MAPIAllocateBuffer * function or the MAPIAllocateMore function. * * @param lpBuffer [in] Pointer to a previously allocated memory buffer. * If NULL is passed in the lpBuffer parameter, MAPIFreeBuffer does nothing. . * * @return Returns S_OK if the call succeeded and freed the memory requested. * MAPIFreeBuffer can also return S_OK on already freed locations or * if memory block is not allocated with MAPIAllocateBuffer and MAPIAllocateMore. */ ULONG MAPIFreeBuffer(LPVOID lpBuffer); /** * @brief * Provides an alternative way to invoke the OLE method IUnknown::Release. . * * @param punk [in] Pointer to an interface derived from the IUnknown interface, * in other words any MAPI interface. * * @return Returns S_OK if the call succeeded and has returned the expected value or values. * MAPI_E_CALL_FAILED - An error of unexpected or unknown origin * prevented the operation from completing. */ ULONG UlRelease(LPVOID punk); /** * @brief * Destroys an SRowSet structure and frees associated memory, including * memory allocated for all member arrays and structures. * * @param prows [in] Pointer to the SRowSet structure to be destroyed. */ void FreeProws(LPSRowSet prows); /** * @brief * Retrieves all rows of a table. * * @param ptable [in] Pointer to the MAPI table from which rows are * retrieved. * @param ptaga [in] Pointer to an SPropTagArray structure containing * an array of property tags indicating table columns. * These tags are used to select the specific columns to * be retrieved. If the ptaga parameter is NULL, * HrQueryAllRows retrieves the entire column set of the * current table view passed in the ptable parameter. * @param pres [in] Pointer to an SRestriction structure containing * retrieval restrictions. If the pres parameter is NULL, * HrQueryAllRows makes no restrictions * @param psos [in] Pointer to an SSortOrderSet structure identifying * the sort order of the columns to be retrieved. If the * psos parameter is NULL, the default sort order for the * table is used. * @param crowsMax [in] Maximum number of rows to be retrieved. * If the value of the crowsMax parameter is zero, * no limit on the number of rows retrieved is set. * @param pprows [out] Pointer to a pointer to the returned SRowSet * structure containing an array of pointers to the * retrieved table rows. * * @return \Returns S_OK if the call succeeded and retrieved the expected * rows of a table. MAPI_E_TABLE_TOO_BIG - The number of rows in the * table is larger than the number passed for the crowsMax parameter. */ HRESULT HrQueryAllRows(LPMAPITABLE ptable, LPSPropTagArray ptaga, LPSRestriction pres, LPSSortOrderSet psos, LONG crowsMax, LPSRowSet FAR* pprows); /** * @brief * Retrieves the value of a single property from a property interface, * that is, an interface derived from IMAPIProp. * * @param pmp [in] Pointer to the IMAPIProp interface from which * the property value is to be retrieved. * @param ulPropTag [in] Property tag of the property to be retrieved. * @param ppprop [out] Pointer to a pointer to the returned SPropValue * structure defining the retrieved property value. * * @return MAPI_E_NOT_FOUND - The requested property is not available from * the specified interface. */ HRESULT HrGetOneProp(LPMAPIPROP pmp, ULONG ulPropTag, LPSPropValue FAR* ppprop); /** * @brief * Sets or changes the value of a single property on a property * interface, that is, an interface derived from IMAPIProp. * * @param pmp [in] Pointer to an IMAPIProp interface on which the * property value is to be set or changed. * @param pprop [in] Pointer to the SPropValue structure defining the * property to be set or changed. * * @return MAPI_E_NOT_FOUND - The requested property is not available from * the specified interface. */ HRESULT HrSetOneProp(LPMAPIPROP pmp, LPSPropValue pprop); /** * @brief * Allocates a memory buffer. * * @param cbSize [in] Size, in bytes, of the buffer to be allocated. * @param lppBuffer [out] Pointer to the returned allocated buffer. * * @return Returns S_OK if the call succeeded and has returned * the expected value or values. */ SCODE MAPIAllocateBuffer(ULONG cbSize, LPVOID FAR* lppBuffer); /** * @brief * Creates an advise sink that wraps an existing advise sink for * thread safety. * * @param lpAdviseSink [in] Pointer to the advise sink to be wrapped. * @param lppAdviseSink [out] Pointer to a pointer to a new advise sink * that wraps the advise sink pointed to by the * lpAdviseSink parameter. * * @return Returns S_OK if the call succeeded and has returned * the expected value or values,else E_FAIL */ HRESULT HrThisThreadAdviseSink(LPMAPIADVISESINK lpAdviseSink, LPMAPIADVISESINK FAR* lppAdviseSink); /** * @brief * Creates an advise sink object, given a context specified by the * calling implementation and a callback function to be triggered by * an event notification.. * * @param lpfnCallback [in] Pointer to a callback function based on the * NOTIFCALLBACK prototype that MAPI is to call when * a notification event occurs for the newly created * advise sink. . * @param lpvContext [in] Pointer to caller data passed to the callback * function when MAPI calls it. The caller data can * represent an address of significance to the client * or provider. Typically, for C++ code, the lpvContext * parameter represents a pointer to the address of * an object. * @param lppAdviseSink [out] Pointer to a pointer to an advise sink object. * * @return Returns S_OK if the call succeeded and has returned * the expected value or values,else E_FAIL */ HRESULT HrAllocAdviseSink(LPNOTIFCALLBACK lpfnCallback, LPVOID lpvContext, LPMAPIADVISESINK FAR* lppAdviseSink); private: LPVOID m_ptrWrappers[12]; /**< Wrapper pointer*/ HMODULE m_hMapiDll; /**< Handle to the mapi32 .dll.*/ }; ///////////////////////////////////////////////////////////////////////////// # endif // !defined(__XTPCALENDARMAPIWRAPPER_H__) # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif /*!_XTP_INCLUDE_CALENDAR_MAPI*/