Sign in to follow this  
Toolmaker

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

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this