CoInitializeSecurity (ole32)
Last changed: RobertChipperfield-


C# Signature:

static extern int CoInitializeSecurity(IntPtr pVoid, int cAuthSvc,
   SOLE_AUTHENTICATION_SERVICE [] asAuthSvc, IntPtr pReserved1,
   uint dwAuthnLevel, uint dwImpLevel, IntPtr pAuthList, uint dwCapabilities,
   IntPtr pReserved3);

User-Defined Types:



You can't call CoInitializeSecurity from managed code. That's because the CLR will always call CoInitialize upon startup before execution enters your main method, and CoInitialize will implicitly call CoInitializeSecurity if it hasn't already been called. Therefore, calling this from managed code returns RPC_E_TOO_LATE.

The workaround is to write an unmanaged "shim" that will call CoInitializeSecurity, then activate and call into managed code. You can do this via an export from a mixed-mode C++ DLL, by registering a managed component for use by COM, or by using the CLR hosting API.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!