tags:

views:

61

answers:

0

Hi there,

i´ve got a problem porting a C++ MFC Project from Visual Studio 2003 to VS 2008. There is a problem creating Dialogs, that Ressources are in different Projects of the Solution.

The Project with the Main Frame starts a thread, that creates a little Splash Window. Another Project contains the code and the ressource to create the splash window Dialog. The Projects are linked through the variable gl_pGlobal. The gl_pGlobal Variable is created like this:

extern IPOLGlobal* gl_pGlobal;

/*! \def __InitPOLGlobalSystem()
    \brief Initialisieren das globalen System
*/
#define __InitPOLGlobalSystem()\
    IPOLGlobal* gl_pGlobal=NULL; \
    extern "C" __declspec(dllexport)void InitPOLLibrary(IPOLGlobal* pGlobalEx){ \
        gl_pGlobal=pGlobalEx; \
    } 

The IPOLGlobal is an interface where the CPOLGlobal class derives from. The CPOLGlobal class contains the Function that starts a thread. In the Project with the Main Frame, the gl_pGlobal is used to call the Function that starts a Thread:

gl_pGlobal->ViewBanner();

This is a part of the CPOLGlobas class (second Project), where the function is implemented.

...    
CPOLBannerThread* gl_pBannerThread=NULL;

void CPOLGlobal::ViewBanner()
{
            m_bHaveMoreThreads=TRUE;
            gl_pBannerThread = (CPOLBannerThread*)AfxBeginThread(RUNTIME_CLASS(CPOLBannerThread),THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED,NULL);
            gl_pBannerThread->m_bAutoDelete = TRUE;
            gl_pBannerThread->ResumeThread();
        }

..

The CPOLBannerThread class contains the Functions to start the thread and create the splash window, where m_bannerWnd the Dialog is.

...

BOOL CPOLBannerThread::InitInstance()
    {
        m_bannerWnd.Show();
        m_bannerWnd.m_ctrlEdit.SetWindowText(_T("Try to start ..."));
        return TRUE;
    }

void CPOLBannerDlg::Show(){
        AFX_MANAGE_STATE(AfxGetStaticModuleState());

        CWnd* wnd=CWnd::GetDesktopWindow();
        CDialog::Create(IDD_DIALOG_BANNER, wnd);

        ShowWindow(SW_SHOW);
        UpdateWindow();
    }

...

The CDialog::Create(IDD_DIALOG_BANNER, wnd); call crashes the Thread. This code worked when created with VS 2003, now in VS 2008 it crashed. Can you say what is wrong?

This is the stack Trace:

mfc90ud.dll!CObject::IsKindOf(const CRuntimeClass * pClass=0x78a0dcd4)  Zeile 40 + 0x22 Bytes   C++

mfc90ud.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x01203730, CWnd * pParentWnd=0x01096fdc, HINSTANCE__ * hInst=0x01190000)  Zeile 240 + 0x12 Bytes  C++

mfc90ud.dll!CDialog::CreateIndirect(const DLGTEMPLATE * lpDialogTemplate=0x01203730, CWnd * pParentWnd=0x01096fdc, void * lpDialogInit=0x00000000, HINSTANCE__ * hInst=0x01190000)  Zeile 211   C++

mfc90ud.dll!CDialog::CreateIndirect(void * hDialogTemplate=0x01203730, CWnd * pParentWnd=0x01096fdc, HINSTANCE__ * hInst=0x01190000)  Zeile 188 + 0x16 Bytes    C++

mfc90ud.dll!CDialog::Create(const wchar_t * lpszTemplateName=0x00000068, CWnd * pParentWnd=0x01096fdc)  Zeile 170 + 0x14 Bytes  C++

mfc90ud.dll!CDialog::Create(unsigned int nIDTemplate=104, CWnd * pParentWnd=0x01096fdc)  Zeile 673 + 0x1a Bytes C++

globalAPI.dll!PolGlobal::CPOLBannerDlg::Show()  Zeile 52    C++

globalAPI.dll!PolGlobal::CPOLBannerThread::InitInstance()  Zeile 78 C++

mfc90ud.dll!_AfxThreadEntry(void * pParam=0x0012eaf0)  Zeile 113 + 0xd Bytes    C++

msvcr90d.dll!_callthreadstartex()  Zeile 348 + 0xf Bytes    C

msvcr90d.dll!_threadstartex(void * ptd=0x01092c50)  Zeile 331   C

kernel32.dll!7c80b50b()     

[Unten angegebene Rahmen sind möglicherweise nicht korrekt und/oder fehlen, keine Symbole geladen für kernel32.dll] 
    kernel32.dll!7c8399f3()

The Exception is invalid argument. In the Function ENSURE(this != NULL); crashes because this in NULL.

BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
    ENSURE(this != NULL);
    // it better be in valid memory, at least for CObject size
    ASSERT(AfxIsValidAddress(this, sizeof(CObject)));

    // simple SI case
    CRuntimeClass* pClassThis = GetRuntimeClass();

    ENSURE(pClassThis);
    return pClassThis->IsDerivedFrom(pClass);
}