【发布时间】:2013-10-14 19:09:24
【问题描述】:
Assert Failedf:\dd\...\include\afxwin1.inl 出现了一些奇怪的错误。我在 Google 中搜索了一些解决方案,一些解决方案用于在发布模式下评论此行 (m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);) 以使其工作。但是在评论那行之后,我又遇到了一些错误。
我采用了一个基于对话框的 MFC 应用程序。当它是application.exe 时,它工作得非常好。我的要求是使其成为static library,我将拥有另一个console application,它将成为主要的application.exe,我从.exe 调用InitInstance。一旦它成功了,
CDialogDlg::CDialogDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CDialogDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
它抛出上述错误。
在我的application.cpp
#include "stdafx.h"
#include "DialogDlg.h"
#include "Dialog.h"
#include "afxwin.h"
#include "Resource.h"
#include <afxinet.h>
CDialogApp theApp;
int _tmain(int argc, _TCHAR* argv[])
{
//CInitApp cpp;
theApp.InitInstance();
return 0;
}
Dialog.cpp
#include "stdafx.h"
#include "Dialog.h"
#include "DialogDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CDialogApp
BEGIN_MESSAGE_MAP(CDialogApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CDialogApp construction
CDialogApp::CDialogApp()
{
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
}
//CDialogApp theApp;// I have commented this code as I am declaring it in mainapplication
BOOL CDialogApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
CShellManager *pShellManager = new CShellManager;
//SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CDialogDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
if (pShellManager != NULL)
{
delete pShellManager;
}
return FALSE;
}
我在Dialog.cpp 中评论了CDialogApp theApp; 行,因为我在mainapplication .exe 中调用它时,当它到达CDialogDlg dlg; 时就会出现问题。
请帮我解决这个错误。
另外,可以将基于对话框的应用程序设置为静态库。如果是,那么为什么我会收到此错误。我也尝试过在 Windows 和控制台中制作主要应用程序。请找到截图以便更好地理解,我在做什么。
【问题讨论】:
-
将 MFC 代码移动到库时,您必须管理模块状态,以便正确解析模块私有资源。详情请见TN058: MFC Module State Implementation 和Managing the State Data of MFC Modules。
标签: c++ visual-studio-2010 visual-c++ mfc static-libraries