See the question and my original answer on StackOverflow

CoInitialize(Ex) must be called at least once per thread, per developer, say.

If you, as a developer, own a thread (or a process) you have to call it once per thread if you use COM in that thread.

If you're unsure it has been called before or not because you don't own a thread, you can call it. The return value will tell you if you're the first one to call it or not. In this case, you should also check the return value for the dreaded code RPC_E_CHANGED_MODE which basically you're doomed and should use your own thread for what you have to do.

And as stated in the comment, each CoInitialize call must be paired with a CoUninitialize.