COM - CoInitializeEx(...) not found...

Started by
1 comment, last by TheHermit 21 years, 5 months ago
I am trying to initialize a COM interface in a win32 project (VC.net) with the following(ish) code:
  
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  //start COM


if (SUCCEEDED(hr))
 {
  hr = CoCreateInstance(CLSID_DOMDocument,
			NULL,
			CLSCTX_INPROC_SERVER,
			IID_IXMLDOMDocument,
			(void**)&pXMLDoc);	
  
For some reason, I am getting
  
d:\Documents and Settings\Josh\My Documents\Visual Studio Projects\Fly! V2\SettingsFile.cpp(13): error C2065: ''CoInitializeEx'' : undeclared identifier
  
I am including , , in due course of the files, yet still, ''tis broken... The program does work if i use CoInitialize(...) instead, and also in the original program i used to build the class with the ...Ex(...) version. But my main program code refuses to find the function as per the error above... Any suggestions would be great - as you can see I am struggling for answers, and am currently suffering a distinct lack of references for this problem... Anyway, thanks!
Advertisement
Got an answer - may not be perfectly understood but it works...

>From Codeguru.com forum post:-----------------

Re: CoinitializeEx problem
#if (_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) // DCOM
WINOLEAPI CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
#endif // DCOM

You should go to Project/Settings/C++/Preprocessor definitions and put there _WIN32_DCOM and _WIN32_WINNT=0x0400

-----------------------------------------------

This has worked, but if possible can someone explain to me a little more about why this works in such a way...

Because CoInitialiseEx is supported only with Windows 98 (or Windows 95 with DCOM installed) or windows NT 4.0. That means you need to explicitly define _WIN32_WINNT to 0x0400 (or greater).

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

This topic is closed to new replies.

Advertisement