Microsoft KB Archive/185139

{|
 * width="100%"|

PRB: MAPILogonEx Returns 0x80070057- MAPI_E_INVALID_PARAMETER

 * }

Q185139

-

The information in this article applies to:


 * Extended Messaging Application Programming Interface (MAPI), version 1.0
 * Microsoft Outlook 97, version 8.00
 * Microsoft Exchange Server, version 4.0

-

SYMPTOMS
When you attempt to execute MAPILogonEx from within a service without using the MAPI_NO_MAIL flag, the following error occurs:

0x80070057 (MAPI_E_INVALID_PARAMETER)

MAPILogon will not fail when executed from within a service because MAPILogon automatically adds the MAPI_NO_MAIL flag when executed from within a service.

CAUSE
Prior to Exchange 5.0 and Windows NT 4.0 SP3, the MAPI spooler was not designed to be used within a Windows NT service.

A Windows NT service runs in a security context distinct from the desktop's security context and distinct from that of other Windows NT services. In fact, each thread within a service may have its own security context. In versions previous to 5.0, MAPI design failed to accommodate this fact on two points:


 * The MAPI spooler executes certain background operations on behalf of MAPI client applications, including transferring mail. The MAPI spooler inherits the security context of the first MAPI client application to log on. The MAPI spooler is not a service itself and cannot change its security context to match that of the client it is working on behalf of, so it may not have permission to access resources it needs to do its work. As a result, MAPI requires that Windows NT services set the MAPI_NT_SERVICE flag (in the MAPIINIT_0 structure) when calling MAPIInitialize, and the MAPI_NO_MAIL flag when calling MAPILogonEx. The MAPI_NO_MAIL flag prevents spooler startup. Therefore, the client application is able to send and receive mail only if its message store provider supports those operations directly, without the spooler's help. This type of provider is known as a tightly coupled store and transport. Microsoft Exchange Server is the only such provider currently available. This problem was fixed in MAPI in Windows NT version 4.0 SP3. It will not be fixed in Windows NT 4.0, and the fixes will not be back-ported to Windows NT 3.51.
 * MAPI internally maintains context for client applications on a per- process basis, not on a per-thread basis. This means MAPI cannot support two threads running in different security contexts, the second thread to initialize MAPI uses some of the first thread's resources. MAPI takes no action to prevent this from happening. This problem was fixed in MAPI in Windows NT version 4.0 SP3. It will not be fixed in Windows NT 4.0, and the fixes will not be back-ported to Windows NT 3.51.

The information above was obtained from the article "Using MAPI From a Windows NT Service," available on the Microsoft Web site at the following address:

"http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/mapi/book_9jqc.htm"

RESOLUTION
Update the MAPI DLLs to at least 4.00.995.51. These updates come with Office 97 Service Release 1, as well as updates to the Exchange Client and Server. Alternately, you could add the MAPI_NO_MAIL flag when calling MAPILogonEx from within a service.