我收到一些奇怪的错误,如 Assert Failed
f:\dd\...\include\afxwin1.inl
。我在 Google 中搜索了一些解决方案,一些解决方案用于在 Release模式下注释此行 (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 和控制台中制作主要应用程序。请找到屏幕截图以便更好地理解我要做什么。
最佳答案
静态库不包含任何资源,但您的对话框代码会尝试加载图标和对话框模板资源。您是否将资源移至控制台应用程序? (我不知道这是否行得通,但如果你不这样做肯定行不通。)
常规且受支持的解决方案是将对话框代码放入 DLL 而不是静态库。 DLL 可以包含资源。
关于c++ - m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);断言失败 : at afxwin1. inl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19367464/