Forcing a Notification

When service providers use the IMAPISupport methods for notification, MAPI delivers notifications using a hidden window and its corresponding window procedure. For each process to receive a notification, MAPI posts a special message to the hidden window. This message is named with the constant szMAPINotificationMsg which is defined in MAPIDEFS.H.

You receive these notifications when the hidden window's window procedure processes the szMAPINotificationMsg message. To guarantee that notifications are delivered, it is necessary to wait for and dispatch this szMAPINotificationMsg message. Implementing the logic to achieve this can be done fairly simply, but MAPI provides an entry point into the MAPI(32) DLL called HrDispatchNotifications to make processing even simpler. Call HrDispatchNotifications as follows to receive notifications in your client:

HRESULT hr = HrDispatchNotifications(0);
 

Because the HrDispatchNotifications entry point was added as of MAPI version 1.0a, you might want to implement special logic if your client code predates this version. This special logic would bind dynamically to HrDispatchNotifications entry point if it is available and use the following code if it is not available:

#include <mapiwin.h>
HRESULT (STDAPICALLTYPE FAR *pDispatchFn)(ULONG ulFlags);
HINSTANCE hInst;
HRESULT hr;

hInst = GetModuleHandle("MAPI"szMAPIDLLSuffix".DLL");
pDispatchFn = GetProcAddress(hInst, "HrDispatchNotifications");
if (pDispatchFn)
    hr = (*pDispatchFn)(0);