March 04, 2009

error C3861: 'CoInitializeEx': identifier not found, even with argument-dependent lookup

You may get the following errors when trying to call CoInitializeEx(NULL, COINIT_MULTITHREADED).
 
error C2065: 'COINIT_MULTITHREADED' : undeclared identifier
error C3861: 'CoInitializeEx': identifier not found, even with argument-dependent lookup

The article in MSDN says "You must include the #define _WIN32_DCOM preprocessor directive at the beginning of your code to be able to use CoInitializeEx."

Look at the code snap in ObjBase.h:

#if (_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) // DCOM

WINOLEAPI  CoInitializeEx(IN LPVOID pvReserved, IN DWORD dwCoInit);
WINOLEAPI  CoGetCallerTID( LPDWORD lpdwTID );

#endif // DCOM

So, you need to follow the above rule if you want to call CoInitializeEx, of course you also need to include <objbase.h>.

Reference in MSDN: