C++/COM: The activation context being deactivated is not active for the current threa

Started by
2 comments, last by SiCrane 14 years, 10 months ago
I'm working on an MFC/COM application, and since I've changed a certain part of the COM DLL we use, this errors show up when creating a new CDialog instance: The activation context being deactivated is not active for the current thread of execution. I'm having a little bit of trouble understanding the exception, because apparantly it has to do with activation contexts, but we don't seem to be using those in our COM interface. None of the calls ever calls one of the activation contexts. Googling doesn't help much because they all turn up the same information. Anyone has some information on this?

Advertisement
MFC implicitly uses activation contexts. One is setup when AfxWinInit() is called and each MFC User DLL has an activation context. IIRC, this problem usually goes away by placing AFX_MANAGE_STATE(AfxGetStaticModuleState()); at the beginning of exported functions in MFC User DLLs.
That's weird... I tried tracing through some of the MFC code, and I eventually stumbled upon the a call to AFX_MANAGE_STATE(pThis->m_pModuleState);

So it appears that part *is* already called underwater, which makes this even weirder...

Keep in mind that the AFX_MANAGE_STATE() calls are scoped global setters. When you use the AFX_MANAGE_STATE() macro, it sets the global state to the specified state for as long as the AFX_MANAGE_STATE()'s scope exists and then reverts the state when the scope exits. So the existence of one AFX_MANAGE_STATE() macro does not mean that the right module state is set as the global state for any contained scopes.

Alternately, it could mean that you have a buffer overrun somewhere that's causing a AFX_MANAGE_STATE() to revert to the wrong state, though that usually has other symptoms.

This topic is closed to new replies.

Advertisement