DLL里边创建一对话框失败
我选择的是Regular DLL using shared MFC DLL,DLL中的内容片段:
static CPopWndThread* pMsgThread = NULL;//线程
HRESULTInitMsgInstance(HWND hwndCallBack)//此函数被导出
{
if(!pMsgThread)
{
pMsgThread=(CPopWndThread*)::AfxBeginThread(RUNTIME_CLASS(CPopWndThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
if(!pMsgThread)
return E_FAIL;
pMsgThread-> m_wndCallBack=hwndCallBack;
pMsgThread-> ResumeThread();
}
return S_OK;
}
BOOL CPopWndThread::InitInstance()
{
m_pMainWnd=CPopDlg::CreateObject();
CPopDlg *dlg = (CPopDlg *) m_pMainWnd ;
return TRUE;
}
CPopDlg* CPopDlg::CreateObject()//对话框中静态的函数
{
CPopDlg *dlg = NULL;
dlg = new CPopDlg;
AfxMessageBox( "No ");
//dlg-> Create(IDD_DIALOG_POPDLG,AfxGetMainWnd());
dlg-> Create(IDD_DIALOG_POPDLG,AfxGetApp()-> m_pMainWnd);//有问题
return dlg;
}
会主程序中使用该DLL,会运行错误,是dlgcore.cpp的173行引起的:
#ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
{
ASSERT(FALSE); // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
[解决办法]
AFX_MANAGE_STATE(AfxGetStaticModuleState());//需要这句。
dlg-> Create(IDD_DIALOG_POPDLG);
dlg-> ShowWindow(SW_SHOW);
[解决办法]
CPopDlg *dlg=new CPopDlg;
[解决办法]
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CPopDlg *dlg = NULL;
dlg = new CPopDlg;
if(!dlg-> Create(IDD_DIALOG_POPDLG, CWnd::FromHandle(hMainWnd)) )