Archived

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

tj963

CoInitializeEx

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites