Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "CoInitializeSecurity" in [All]

misc

.

"Folks like you are sharing gotchas, tips, and samples specific to managed code. For example, check out why you shouldn't call CoInitializeSecurity from managed code."

.

There is a workaround to call CoInitializeSecurity from managed code, I added the information to the documentation.

ole32

.

public static extern int CoInitializeSecurity( IntPtr pVoid, int

.

Declare Function CoInitializeSecurity Lib "ole32.dll" (pVoid As IntPtr, _

.

You shouldn't call CoInitializeSecurity from managed code. That's because the CLR will almost 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 will usually return 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.

.

Usually RPC_E_TOO_LATE happens when CoInitializeSecurity already called (implicitly or explicitly, it does no matter). When you using Visual Studio, it use so called "Visual Studio Hosting Process" where CoInitializeSecurity already called. Turn off Visual Studio hosting process and have fun, now you can debug your application that calls CoInitializeSecurity with no RPC_E_TOO_LATE error.

.

/// Do not set STAThread since CoInitializeSecurity is called

.

    CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,

.
Documentation
[CoInitializeSecurity] on MSDN
.

public static extern int CoInitializeSecurity( IntPtr pVoid, int

.

Declare Function CoInitializeSecurity Lib "ole32.dll" (pVoid As IntPtr, _

.

You shouldn't call CoInitializeSecurity from managed code. That's because the CLR will almost 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 will usually return 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.

.

Usually RPC_E_TOO_LATE happens when CoInitializeSecurity already called (implicitly or explicitly, it does no matter). When you using Visual Studio, it use so called "Visual Studio Hosting Process" where CoInitializeSecurity already called. Turn off Visual Studio hosting process and have fun, now you can debug your application that calls CoInitializeSecurity with no RPC_E_TOO_LATE error.

.

/// Do not set STAThread since CoInitializeSecurity is called

.

    CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,

.
Documentation
[CoInitializeSecurity] on MSDN

 
Access PInvoke.net directly from VS: