Furthermore, there are several rules you should follow. Now, I will give you a clear explanation here.
Rule #1: For each thread, you have to call CoInitialize() before you call any of the COM library funtions except CoGetMalloc() and the memory allocation functions.
Rule #2: For each successful call made by CoInitialize(), you have to call CoUninitialize() to free the COM library.
Rule #3: Do not call CoInitialize() or CoUninitialize() from the DllMain() function.
Rule #4: The first thread in the application that calls CoInitialize() must be the last thread to call CoUninitialize().
Reference in MSDN:
CoInitialize