Using DLL that using COM in C#

Posted by chekalin-v on Stack Overflow See other posts from Stack Overflow or by chekalin-v
Published on 2010-03-16T11:43:13Z Indexed on 2010/03/16 11:46 UTC
Read the original article Hit count: 432

Filed under:
|
|

I have been writing DLL on C++, that will be use in C#. DLL have some function, where I call

hres =  CoInitializeEx(NULL, COINIT_MULTITHREADED); 

and next call

hres =  CoInitializeSecurity(
        NULL, 
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_PKT,   // Default authentication 
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
        NULL,                        // Authentication info
        EOAC_NONE,                   // Additional capabilities 
        NULL                         // Reserved
        );

There are no error then I trying to use this dll in C++. But if I call function from DLL via C# application I see Error (80010106) Cannot change thread mode after it is set. I changed

hres =  CoInitializeEx(NULL, COINIT_MULTITHREADED);

to

hres = CoInitialize(NULL);

After this changes error appear after CoInitializeSecurity:

(80010119)    Security must be initialized before any
                          interfaces are marshalled or unmarshalled. It
                          cannot be changed once initialized.

How resolve this trouble?

© Stack Overflow or respective owner

Related posts about dll

Related posts about com