I am trying to trace a bug in our handling of com objects. Our program is launched from our activeX control, and there is some com issue when the app is closed again. I would like to attach the visual studio (2008) debugger to our app when it is first launched from the OCX. How can I do that?
Some details:
a) OCX and app written primarily in c/c++ with just a little c++/cli (that play no role in the launching of the app)
b) If I attach to the program while it is running I get an assertion on exit in olelock.cpp
void AFXAPI AfxOleUnlockApp()
{
AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
ASSERT(pModuleState->m_nObjectCount != 0); <--- Triggers this
if (InterlockedDecrement(&pModuleState->m_nObjectCount) == 0)
{
// allow application to shut down when all the objects have
// been released
::AfxOleOnReleaseAllObjects();
}
}
So I would like to attach the debugger to our program when it is first launched from the OCX so I can attempt to track the lifetime of the COM objects. Or perhaps there is another way to trace these objects?
gflags is what you would look into for complex scenarios in general. Specifically this page for debugging an app unconditionally when it is launched.
However, I think this is overkill for what you want. I usually just dump some code in my program that will wait for a debugger to be attached if it was built in DEBUG mode and the F1 key is being pressed when the code starts up. Code like this shouldn’t get left in, but it’s pretty handy.