I’m doing some debugging on a messy project I picked up where the previous developer didn’t know what they were doing, and the main issue is failed attempts to multi-thread the application. I’m now cleaning up the mess and trying to figure out where things are going wrong. One of the issues is inconsistent calls to CoInitialize in order to use ADO components.
Continued from my previous question, how can I identify how many levels of CoInitialize have been called?
For example, take this code into consideration:
CoInitialize(nil);
try
CoInitialize(nil);
try
//2 levels have been called, how to programatically check this?
finally
CoUninitialize;
end;
finally
CoUninitialize;
end;
You can do it like this:
Warning! Since the above function closes COM it cannot be used in COM applications, only to answer the particular question while debugging.