Why does mapi32.dll on Windows Server 2022 prevent calling CoInitializeSecurity within the same application?

253 Views Asked by At

I'm working on a project that uses mapi32.dll to access Microsoft Exchange Server from a Windows Server 2022 machine. I noticed that whenever CoInitializeSecurity is called within the same application after calling MAPIInitialize, it fails with the error "RPC_E_TOO_LATE: The call to CoInitializeSecurity has already been made and cannot be called again within the same application."

This isn't a new project. It has been in production for years, but after a customer upgraded to Windows Server 2022 they reported this issue and the above is what I found after investigating it.

After doing some research, I found that mapi32.dll in Windows Server 2022 seems to call CoInitializeSecurity during initialization. I swapped this DLL with one from Windows Server 2019 and everything work as expected. CoInitializeSecurity was able to be called afterwards with no failure.

One solution is to move the call to CoInitializeSecurity to just before calling MAPIInitialize, but my concern is that the security needed by MAPI would be different, or somehow cause problems with it.

Does anyone know why mapi32.dll in Windows Server 2022 prevents calling CoInitializeSecurity within the same application? Is there a way to work around this issue? Any help would be greatly appreciated.

0

There are 0 best solutions below