CoInitializeEx

Started by
4 comments, last by tj963 20 years, 6 months ago
Hey, My game makes use of multiple threads, one to handle the windows message loop and one to handle the main game loop. I have a problem though, becuase when trying to add DirectMusic into my game, it game me a lot of trouble. Function calls just didn''t work. Apparently you need to call CoInitializeEx instead of CoInitialize to set a parameter for multi-threading. However, the compiler can''t locate the definition for CoInitializeEx. Why would one work and not the other? How do I get CoInitializeEx to work? Is that even what I''m supposed to do? Thanks, tj963
tj963
Advertisement
Are you rynning Win2K? An older version of NT?
Are you sure the problem is CoInit vs. CoInitEx?

if so, then before including the windows master header try:

#define _WIN32_WINVER 0x0500#include <windows.h>


For info on this tidbit. open up windows.h and read the first few comments.

Also remember...Calls to CoInitializeEx with a CO_INIT parameter not of the current model will result in error!

Don''t forget to call CoInitializeEx before ANY other COM calls for clarity and success.
Hey,
Thanks for the reply. I would never have though to look there. When you say that it should be before and COM calls, does that include calls like DirectDrawCreateEx, which I assume use COM internally?

tj963
tj963
Perhaps someone w/more knowledge than I have would be better suited to answer this question.

I THINK that all DirectX interfaces (those being any that begin with I like IDirectInputDevice etc.) or those that need and interface ID (like IID_IDirectPlay8Address ) are all COM objects.

In regards to CoInit and CoInitEx both try to set the concurrency model and so if you call CoInitEx with a concurrency model is not the one currently being used (because of a previous call to CoInit either by you or a DirectX wrapper function )It is unable to change the model for fear of screwing with a previously instantiated object.

quote:Original post by tj963
When you say that it should be before and COM calls, does that include calls like DirectDrawCreateEx, which I assume use COM internally?
tj963

Sorry, I did not answer you question.
Yes, (DirectDraw, Direct3D, DirectPlay, DirectInput, DirectSound are all COM objects and you should call CoInitEx before you call any of these DirectX COM interface wrapper functions).

And it should be
#define _WIN32_WINNT 0x0500#include <windows.h>// ...not #define _WIN32_WINVER 0x0500#include <windows.h>


[edited by - citizen3019 on October 22, 2003 3:08:40 PM]
Thank you so much. That fixed the problem.

tj963
tj963

This topic is closed to new replies.

Advertisement