Archived

This topic is now archived and is closed to further replies.

fferland

Questions about CoInitializeEx

Recommended Posts

Hi! I''m writing a small test program to learn DirectAudio8. At the beginning of my program, I called the CoInitializeEx() function. When I tried to compile, I got an "undeclared identifier" error message. I thus opened ''objbase.h'' to try to figure out why I was getting this message even though I had included the correct header file in my module. I found the following line preceeding the CoInitializeEx() declaration: #if (_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) // DCOM Now, my question is would I have gotten the same error message if I had been running VC++ on Windows 2000 or XP? In other words, does the _WIN32_WINNT automatically adapt to the OS that VC++ is running on (I''m temporarily running on Win98)? To get around the problem, I simply added _WIN32_DCOM to my project settings and my program now compiles fine. Is this the correct way to have CoInitializeEx() compile properly or is there some ''safer'' way that I should be using instead? Also, does anyone know what the COINIT_SPEED_OVER_MEMORY flag does exactly? I obviously already know that it uses more memory to achieve better speed, but I''d like to know how much more memory it uses and whether or not the speed increase is significant. I''ll use the flag even if the difference is insignificant, but I''d still like to know out of curiosity. Thanks a lot! Fred

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i have XP and am getting the same error...
it worked until i updated the system earlier today

Share this post


Link to post
Share on other sites
The OS you''re running has absolutely no effect on the code that your compiler produces. Defines such as WINVER, _WIN32_WINNT, and so on depend on what OS you''re targeting, not on the one you''re running. By defining _WIN32_WINNT, you''re telling the compiler: "I will be running this program on Windows NT or newer, so include the content that exists only on NT." Same thing with WINVER: you may be running on XP, but you want your program to function on Win98 as well, so you define WINVER to 0x0410 even though for XP WINVER is 0x0501.

CoInitializeEx exists on WinNT or on Win95 with the DCOM redistributable, which is detailed in the docs. Thus, the #if: "if you are targeting a computer which is running NT or has DCOM update then...".

Have this before you include windows.h:

#define _WIN32_WINNT 0x0400

and you will be fine.

Note: some _WIN32_WINNT content is actually available on newer 9x platforms as well. Win98, for example, implements a number of functions that were present in WinNT4 but not in Win95, even though they are typically marked by _WIN32_WINNT guards.

Share this post


Link to post
Share on other sites