// JP opened flex table

Click to See Complete Forum and Search --> : three questions about CoInitialize/CoUninitialize


George2
June 29th, 2008, 11:35 PM
Hello everyone,


Am I correct for the understanding of the following three questions about CoInitialize/CoUninitialize?

1.

For each thread which utilizes COM, we need to call CoInitialize/CoUninitialize. Not for each process.

2.

There is no harm to call CoUninitialize even if we do not call CoInitialize? And if we call CoInitialize N times on a thread, we need to call CoUninitialize the same of times (N times, not only 1 time) on a thread to release all resources?

3.

CoInitializeEx will invoke CoInitialize?


thanks in advance,
George

Igor Vartanov
June 30th, 2008, 06:27 AM
MSDN, CoInitializeEx Function
Remarks

CoInitializeEx must be called at least once, and is usually called only once, for each thread that uses the COM library. Multiple calls to CoInitializeEx by the same thread are allowed as long as they pass the same concurrency flag, but subsequent valid calls return S_FALSE. To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.

CoInitializeEx will invoke CoInitialize?As far as I understand WinAPI principles, I would say the exactly opposite thing: CoInitialize eventually invokes CoInitializeEx. :)

George2
June 30th, 2008, 07:20 AM
Thanks Igor!


Great man with great answer! :-)

MSDN, CoInitializeEx Function


As far as I understand WinAPI principles, I would say the exactly opposite thing: CoInitialize eventually invokes CoInitializeEx. :)


regards,
George

//JP added flex table