views:

11

answers:

0

I have two projects in my solution. One is a MFC project which shows a simple GUI saying "Hllo World"

If I compile the MFC Application Project as Application (exe) it runs without problems.

What I want to do now is to show the window from my UnitTest. (Doesn't make much sens, but it has to be like that). Therefore the MFC application is build as static library and included in the UnitTest.

The Gui won't show, it crashes with a debug assertion.

At this point in "afxstate.cpp" the exe always goes throu the if and the lib started from the UnitTest goes throu the else case, what causes the debug assertion.

Here is the part of the code:

AFX_MODULE_STATE* AFXAPI AfxGetModuleState()
{
    _AFX_THREAD_STATE* pState = _afxThreadState;
    ENSURE(pState);
    AFX_MODULE_STATE* pResult;
    // --> Is true for my application started as exe, but false when started from my unittest
    if (pState->m_pModuleState != NULL)
    {
        // thread state's module state serves as override
        pResult = pState->m_pModuleState;
    }
    else
    {
        // otherwise, use global app state
        pResult = _afxBaseModuleState.GetData();
    }
    ENSURE(pResult != NULL);
    return pResult;
}

I just want to know why it behaves like this and how to fix or bypass it.