Crashing when Calling CoUninitialize

0

Based on this link, I am creating Windows Processing Monitoring and Windows Service Monitoring DLLs that are to be called by the main application and run them in thread(using boost::thread) to get the data asynchronously. Consider that these both dll are run by my application. I get the error Failed to initialize security. Error code = 0x80010119 for one of my app. And also when stopping the threads for these dll, CoUninitialize is called in both of them. Here I get a crash. It might be because the CoUninitialize in latter thread might attempt to clear memory that was cleared by former thread.

If so, how can I check whether the CoUninitialize in one thread was successful so that I would not call it in another thread.

c++
wmi
asked on Stack Overflow Feb 23, 2015 by Pant

2 Answers

0

CoUninitialize is a part of COM library, WMI can use COM interface, but has nothing to do with its initialization or disposal. Don't call CoUninitialize twice within one process. Note, that both of your DLL's probably share application context and are executed within it.

answered on Stack Overflow Mar 1, 2015 by Basilevs
0

"how can I check whether the CoUninitialize in one thread was successful so that I would not call it in another thread."

That tells me your error, but it's not in CoUninitialize. You are assuming that CoUninitialize is process-wide. In reality, CoUninitialize mirrors CoInitializeEx, and that should have de done on every thread. So your crash is almost certainly caused by a CoInitializeEx on one thread and the CoUninitialize on another thread.

The fix is to do CoInitializeEx on both threads, and CoUninitialize also on both threads.

answered on Stack Overflow Mar 1, 2018 by MSalters

User contributions licensed under CC BY-SA 3.0