Initializing MAPI

All client applications that use the MAPI libraries must call the MAPIInitialize function. MAPIInitialize initializes global data for the session and prepares the MAPI libraries to accept calls. There are two flags that are important to set in some situations:

MAPI_NT_SERVICE

MAPI_MULTITHREAD_NOTIFICATIONS

Set the MAPI_NT_SERVICE flag if your client is implemented as a Windows NT service. If your client is a Windows NT service and you do not set this flag, MAPI will not recognize it as a service.

The MAPI_MULTITHREAD_NOTIFICATIONS flag relates to how MAPI manages notifications. MAPI creates a hidden window that receives window messages when changes occur to an object generating notifications. The window messages are processed at some point, causing the notifications to be sent and the appropriate IMAPIAdviseSink::OnNotify methods to be called.

MAPI either creates the notification window on the thread that was used for your first MAPIInitialize call or on a separate thread — a thread dedicated to handling notifications. MAPI expects the thread that is used to create the hidden notification window to:

You can choose which thread is used by setting a flag in the first MAPIInitialize call. The danger in allowing one of your threads to handle the notifications is that if the thread disappears, the notification window is destroyed and notifications can no longer be sent to any of your other threads. Also, special processing might be needed to control the dispatching of the notification messages that are posted to the hidden window's message queue.

If you use a separate window to handle notifications, be assured that notifications will appear at the appropriate time on an appropriate thread. You will not need any special code to check for and process the Windows messages that are posted to the notification window.

MAPI recommends that the following types of client applications use a separate thread to create the hidden window for notification support:

To use the separate thread approach, call MAPIInitialize on every thread, setting the MAPI_MULTITHREAD_NOTIFICATIONS flag. Calls made from 16-bit clients operate as if the MAPI_MULTITHREAD_NOTIFICATIONS flag is not set.

Note Only a client's first call to MAPIInitialize causes a hidden window to be created to support notifications. Subsequent calls only cause a reference count to be incremented.