Using the MAPI_DEFERRED_ERRORS Flag

The primary purpose of the MAPI_DEFERRED_ERRORS flag is to defer error reporting. You can also use this flag to reduce RPCs generated by an application. When the MAPI_DEFERRED_ERRORS flag is set, error reporting is deferred until the IMAPIProp::GetHierarchyTable method or the GetProps method is called. A secondary effect is that function calls are also deferred until the information is actually required. For example, when the MAPI_DEFERRED_ERRORS flag is set, the MAPI OpenEntry function will execute. It will not, however, actually open a folder and require an RPC until information is requested from the folder. The OpenEntry call and the information request are cached at the client.

Using the MAPI_DEFERRED_ERRORS flag makes error handling slightly more difficult because the calling application does not immediately receive the information for the OpenEntry call. If the folder you want to open does not exist, you will not see the error until you actually try to retrieve information from the server. To minimize this problem, make your error handling more generic and plan for events that may occur in later function calls.

The MAPI_DEFERRED_ERRORS flag also adds some complexity to the client and even more complexity to providers, but it dramatically reduces the number of RPCs. Testing shows that using MAPI_DEFERRED_ERRORS can reduce network overhead as much as 50 percent by reducing the number of round trips to the server, as well as increasing scalability of the server.

Example: Using the MAPI_DEFERRED_ERRORS Flag

A client application requests information from the server every 30 seconds by calling the GetContentsTable, SetColumns, and GetRowCount methods. The first call to GetContentsTable causes an RPC, and then SetColumns and GetRowCount each cause an RPC.

If the MAPI_DEFERRED_ERRORS flag is set on the GetContentsTable function call, all three operations are combined into one RPC. This significantly enhances the application’s performance.

Note The advantage gained by using the MAPI_DEFERRED_ERRORS flag varies according to service provider. A client application working with an information store service provider running on a remote server may perform much more quickly with the MAPI_DEFERRED_ERRORS flag set. However, if the same client application is working with an information store service provider running on the local computer, it may show no improvement at all because the data is retrieved locally and no RPCs result.