I use a COM object that export one method. Since I want to use it in few places in the program, I've made a wrapper in order to do the "com initialisation stuff" in only one file.
Here's what I do : In a .cpp file I create a static object. In its constructor, I initialize COM and create an instance of this object. In the destructor, I release the object and uninitialize COM. Since that object is static, its ctor is called at the beginning of the program and its dtor is called at the end of the prog.
The ctor and dtor are called from the main thread.
A crash happend -rarely- on the CoInitialize()...
Here are some extra info to help you look the good direction :
- Windows NT sp6a.
- VC++ 6.0.
- The problem happen even if the COM object is not registred, so not created and "myExportedFunction" is never called.
- The main thread is CoInitialized with : CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- No other COM objects are created in the main thread (or in that app).
- The code resides in a .lib that is staticly link with the main exe.
- Here is the stack of the crash :
MyWrapperObj::~MyWrapperObj() line 123 <-= The CoUninitialize() line.
$E24() + 13 bytes
doexit(int 0, int 0, int 0) line 353
exit(int 0) line 279 + 13 bytes
WinMainCRTStartup() line 345
Here's the .cpp code :
#import "ACOMObject.dll" named_guids no_namespace
mpACOMObject = NULL;
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if ( SUCCEEDED(hr) )
hr = CoCreateInstance(CLSID_ACOMObject, NULL,
mIsReady = SUCCEEDED(hr);
mIsReady = false;
if (mpACOMObject != NULL)
static MyWrapperObj theObject;
Et voilà ! I think I included all important information. I ask your help because my solution bag is now empty and I hope yours contains the answer I need.
Thanks ans good luck,