Usually resources are returned to the system when the process ends, and not when one of its threads occurs.
However, CoUninitialize () not only frees up resources and unloads DLLs, but also enters the modular message loop to pump the remaining COM messages until the stream ends. The documentation states:
If open conversations remain, CoUninitialize starts a modal message loop and sends any pending messages from the containers or server for this COM application. By sending messages, CoUninitialize ensures that the application does not stop before accepting all its pending messages. No COM messages are discarded.
Therefore, to avoid RPC errors by callers, I recommend that you follow the documentation tips and always call CoUninitialize() before terminating the threads that called CoInitializeEx() .
Frédéric hamidi
source share