Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


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

Search Results for "CoInitialize" in [All]

Enums

.
Summary
A set of values from the COINIT enumeration is passed as the second parameter to CoInitializeEx. This value determines the concurrency model used for incoming calls to objects created by the thread making the call. However, since pinvoke is a dotNET construct you should be aware that dotNET already does a COM initialization and therefore calling a CoInitializeEx function most likely will not do what you expect. This problem occurs when trying to instantiate a COM object from within dotNET where the COM objects threading model is different from dotNETs. Search on Common Language Runtime or CLR and COINIT_APARTMENTTHREADED to find posts on this issue.
.

    ///There was an attempt to call CoInitialize a second time while single threaded

.

    [Description("There was an attempt to call CoInitialize a second time while single threaded")]

.

    ///CoInitialize has not been called on the current thread.

.

    [Description("CoInitialize has not been called on the current thread.")]

.

    ///CoInitialize has not been called.

.

    [Description("CoInitialize has not been called.")]

.

    ///CoInitialize has already been called.

.

    [Description("CoInitialize has already been called.")]

.

    '''There was an attempt to call CoInitialize a second time while single threaded

.

    <Description("There was an attempt to call CoInitialize a second time while single threaded")> _

.

    '''CoInitialize has not been called on the current thread.

.

    <Description("CoInitialize has not been called on the current thread.")> _

.

    '''CoInitialize has not been called.

.

    <Description("CoInitialize has not been called.")> _

.

    '''CoInitialize has already been called.

.

    <Description("CoInitialize has already been called.")> _

Constants

.

        /// There was an attempt to call CoInitialize a second time while single threaded

.

        /// CoInitialize has not been called.

.

        /// CoInitialize has not been called.

.

        /// CoInitialize has already been called.

.

        /// CoInitialize has not been called on the current thread.

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
.
Summary
CoInitializeEx initializes the COM library for use by the calling thread, sets the thread's concurrency model, and creates a new apartment for the thread if one is required. Values for the dwCoInit parameter are taken from the COINIT enumeration. However, since pinvoke is a dotNET construct you should be aware that dotNET already does a COM initialization and therefore calling a CoInitializeEx function most likely will not do what you expect. This problem occurs when trying to instantiate a COM object from within dotNET where the COM objects threading model is different from dotNETs. Search on Common Language Runtime or CLR and COINIT_APARTMENTTHREADED to find posts on this issue.
.

    public static extern int CoInitializeEx(

.
Documentation
[CoInitializeEx] 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

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.

glossary

.

             System.AIPCC.Pinvoke.COM       <- contains base functions such as CoInitialize()


 
Access PInvoke.net directly from VS: