Checking Error Returns

When an error is returned, checking the error code can save time, even if the error seems obvious. For example, an error returned from MAPIAllocate_Buffer would seem to indicate insufficient memory, but actually this could be caused by several different problems, including an invalid parameter in the call. Checking the exact error returned is important.

Windows NT Server, OLE, MAPI, and Microsoft Exchange Server use a unified error structure, which means their error codes are defined in the same format.

In these error codes, the first four bytes are the facility code. The final four bytes identify a specific error. Most common Windows NT Server error codes are between 0 and hex 100. MAPI error codes start at hex 0102 (0xnnnn0102). For a description of how these 32-bit error codes are built and the macros used to construct them, see the MAPICODE.H header file.

You can usually find the error code by searching for the final four digits in the previously listed header files. If the search turns up more than one match, check the facility code to determine which component generated the error. First check the Microsoft Exchange Server codes for a match, then the MAPI codes, and finally the Windows NT Server codes.

A given error code can be returned by more than one component, such as both Windows NT Server and MAPI. In general, if a MAPI function returns the error, MAPI generated the error. If the MAPI function is simply passing through an error from a call MAPI made to Windows NT Server, the facility code usually identifies the error as one generated by Windows NT Server.

Microsoft Exchange Server functions also return HRESULTs. For information on these functions and their return values, see Functions.