Using DLL using COM in C #

I wrote a C ++ DLL that will be used in C #. The DLL has some function where I call

hres =  CoInitializeEx(NULL, COINIT_MULTITHREADED); 

and the 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 errors , then I try to use this DLL in C ++ . But if I call a function from a DLL through a C # application, I see Error (80010106) It is not possible to change the flow mode after installing it. I changed

hres =  CoInitializeEx(NULL, COINIT_MULTITHREADED);

to

hres = CoInitialize(NULL);

After that, an error message appears after CoInitializeSecurity :

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

How to solve this problem?

+3
source share
1 answer

CoInitializeEx CoInitializeSecurity DLL. - .

, DLL COM , # DLL , . , , COINIT_MULTITHREADED, , , -, , , , .

+2

Source: https://habr.com/ru/post/1737127/


All Articles