I make calls to CoInitializeEx, specifically:
CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
In threads that my application creates, but then terminates before the application exits. Is it important to pair these with CoUninitialize calls, or do those resources get freed when the threads terminate?
Resources are usually returned to the system when the process terminates, not when one of its threads does.
However, CoUninitialize() does not only free resources and unload DLLs, it also enters a modal message loop in order to pump the remaining COM messages before the thread terminates. The documentation says:
Therefore, in order to avoid RPC errors on the callers’ side, I’d recommend you follow the documentation’s advice and always call
CoUninitialize()before terminating threads that have calledCoInitializeEx().