Hi there,
i had a Projekt that worked with VS 2003. Then i ported it with the help of the Studio to 2008. Now the following class crashes when i start the Application in Debug mode. The crash occurs in the Function calling CDialog::Create(IDD_DIALOG_BANNER, wnd);
void CPOLBannerDlg::Show(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* wnd=CWnd::GetDesktopWindow();
CDialog::Create(IDD_DIALOG_BANNER, wnd);
ShowWindow(SW_SHOW);
UpdateWindow();
}
Here is the class, that is in another DLL of the Solution. The class will be called as a thread from the MFC Project of the Solution.
#include "stdafx.h"
#include "../../include/utility/POLBanner.h"
#include "../../resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
namespace PolGlobal{
//Dialog
IMPLEMENT_DYNAMIC(CPOLBannerDlg, CDialog)
/*! \fn CPOLBannerDlg::CPOLBannerDlg(CWnd* pParent)
\brief Default Konstruktor
\param pParent Parent Fenster
*/
CPOLBannerDlg::CPOLBannerDlg(CWnd* pParent /*=NULL*/){}
/*! \fn CPOLBannerDlg::~CPOLBannerDlg()
\brief Destruktor
*/
CPOLBannerDlg::~CPOLBannerDlg(){}
/*! \fn void CPOLBannerDlg::DoDataExchange(CDataExchange* pDX)
\brief Daten austausch mit Child- Controls
\param pDX Pointer auf CDataExchange
\return void
*/
void CPOLBannerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_BANER, m_ctrlEdit);
}
BEGIN_MESSAGE_MAP(CPOLBannerDlg, CDialog)
END_MESSAGE_MAP()
/*! \fn void CPOLBannerDlg::Show()
\brief Ruft CDialog::Create und zeigt Dialog
\return void
*/
void CPOLBannerDlg::Show(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* wnd=CWnd::GetDesktopWindow();
CDialog::Create(IDD_DIALOG_BANNER, wnd);
ShowWindow(SW_SHOW);
UpdateWindow();
}
//Thread
IMPLEMENT_DYNCREATE(CPOLBannerThread, CWinThread)
/*! \fn CPOLBannerThread::CPOLBannerThread()
\brief Default Konstruktor
*/
CPOLBannerThread::CPOLBannerThread(){}
/*! \fn CPOLBannerThread::~CPOLBannerThread()
\brief Destruktor
*/
CPOLBannerThread::~CPOLBannerThread(){}
/*! \fn BOOL CPOLBannerThread::InitInstance()
\brief Thread Starten
\return TRUE
Zeigth m_bannerWnd und setzt in dem Dialog Try to start ... String
*/
BOOL CPOLBannerThread::InitInstance()
{
m_bannerWnd.Show();
m_bannerWnd.m_ctrlEdit.SetWindowText(_T("Try to start ..."));
return TRUE;
}
/*! \fn int CPOLBannerThread::ExitInstance()
\brief Beendet Thread und zersört Dialog
\return exit code aus dem Thread
*/
int CPOLBannerThread::ExitInstance()
{
m_bannerWnd.ShowWindow(SW_HIDE);
m_bannerWnd.DestroyWindow();
return CWinThread::ExitInstance();
}
/*! \fn void CPOLBannerThread::SetMessage(LPCTSTR mes)
\brief Setzt String in dem m_bannerWnd
\param mes String zum Anzeigen
\return void
*/
void CPOLBannerThread::SetMessage(LPCTSTR mes){
if(m_bannerWnd.m_ctrlEdit)
m_bannerWnd.m_ctrlEdit.SetWindowText(mes);
}
BEGIN_MESSAGE_MAP(CPOLBannerThread, CWinThread)
END_MESSAGE_MAP()
}
The class is called like this:
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 Stack says:
> mfc90ud.dll!CObject::IsKindOf(const CRuntimeClass * pClass=0x78a0dcd4) Zeile 40 C++
mfc90ud.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x01203398, CWnd * pParentWnd=0x01098d44, HINSTANCE__ * hInst=0x01190000) Zeile 240 + 0x12 Bytes C++
mfc90ud.dll!CDialog::CreateIndirect(const DLGTEMPLATE * lpDialogTemplate=0x01203398, CWnd * pParentWnd=0x01098d44, void * lpDialogInit=0x00000000, HINSTANCE__ * hInst=0x01190000) Zeile 211 C++
mfc90ud.dll!CDialog::CreateIndirect(void * hDialogTemplate=0x01203398, CWnd * pParentWnd=0x01098d44, HINSTANCE__ * hInst=0x01190000) Zeile 188 + 0x16 Bytes C++
mfc90ud.dll!CDialog::Create(const wchar_t * lpszTemplateName=0x00000068, CWnd * pParentWnd=0x01098d44) Zeile 170 + 0x14 Bytes C++
mfc90ud.dll!CDialog::Create(unsigned int nIDTemplate=104, CWnd * pParentWnd=0x01098d44) 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=0x01092ef8) 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()
In the ENSURE(this != NULL); Line of IsKindOf the 'this' Variable is 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);
}
What happend here?