Search code examples
c++commultithreading

CoInitializeEx and CoInitializeSecurity failure


I have a C# method that is calling a C++ method. The C++ method uses WMI, so it calls CoInitializeEx(0, COINIT_MULTITHREADED) and then CoInitializeSecurity etc... before making the WMI select. My Problem, CoInitializeEX if failing with code 2147417850 (RPC_E_CHANGED_MODE)

I tried to create a new STA thread from c# and call the c++ method from this thread (and i disabled the visual studio hosting process), no more error in CoInitilalize, but the error happens in CoInitializeSecurity (2147417831, RPC_E_TOO_LATE).

what is the best solution to correct all this?


Solution

  • I removed both calls, problem solved.