Skip to main content
gamedev.net
🔒 Locked

Initializing COM

Started by moucard Jul 5, 2004 at 10:51 AM 3 replies 500+ views
Original Post
moucard
moucard
Hi to everyone, I've got a simple question (I hope). I have 2 classes in my application, one being an interface for DirectSound and the other for DirectPlay. Both need CoInitialize to function. I'd like them to be a little bit independent like calling CoInitializeEx in both of them. Would it create a problem if I call CoInitializeEx after I have called it before? If I give it different parameters will it change them (or leave them unchanged)? Thank you in advance.
circlesoft
circlesoft
Quote:
From MSDN
CoInitializeEx must be called at least once, and is usually called only once, for each thread that uses the COM library. Multiple calls to CoInitializeEx by the same thread are allowed as long as they pass the same concurrency flag, but subsequent valid calls return S_FALSE. To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.
Yes, you can do it. However, you have to pass the same parameters in (it will return RPC_E_CHANGED_MODE otherwise). It's going to return S_FALSE (which indicates the COM library is already initialized on the calling thread) everytime you make a valid call to it after the first time.
IFooBar
IFooBar
from MSDN

"Typically, the COM library is initialized on a thread only once. Subsequent calls to CoInitialize or CoInitializeEx on the same thread will succeed, as long as they do not attempt to change the concurrency model, but will return S_FALSE. To close the COM library gracefully, each successful call to CoInitialize or CoInitializeEx, including those that return S_FALSE, must be balanced by a corresponding call to CoUninitialize. However, the first thread in the application that calls CoInitialize(0) or CoInitializeEx(COINIT_APARTMENTTHREADED) must be the last thread to call CoUninitialize(). If the call sequence is not in this order, then subsequent calls to CoInitialize on the STA will fail and the application will not work. "
[size=2]aliak.net
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by IFooBar
ok, um... woops?

Circle beat you to it, eh?
nenebouricua just did that a bazillion times with me today [smile]

You can't beat the MVPs, my friend!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.