m_hIcon = AfxGetApp() - > LoadIcon(IDR_MAINFRAME);断言失败:at afxwin1.inl [英] m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); Assertion Failed: at afxwin1.inl
问题描述
我得到一些奇怪的错误,因为 Assert失败
f:\dd\ ... \include\afxwin1.inl
。我在Google中搜索了一些解决方案,一些解决方案是在发布模式下对此行进行注释( m_hIcon = AfxGetApp() - > LoadIcon(IDR_MAINFRAME);
) 。但在评论该行后,我得到一些更多的错误。
I am getting some weird error as Assert Failed
f:\dd\...\include\afxwin1.inl
. I am searched in Google some solutions, some solutions are for commenting this line (m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
) in Release mode to make it work. But after commenting that line I am getting some more errors.
我已经采取了一个基于对话框的MFC应用程序。它是工作绝对正常,当它是一个 application.exe
。我的要求是使它静态库
,我将有另一个控制台应用程序
将成为主 application.exe
,我从 .exe
调用 InitInstance
。一旦它换行,
I have taken a dialog based MFC application. It was working absolutely fine when it was an application.exe
. My requirement is to make it static library
and I will have another console application
which will become main application.exe
, I am calling InitInstance
from that .exe
. Once it fatches the line,
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;
}
我已评论 CDialogApp theApp;
中的行
。 mainapplication .exe中调用它
code> CDialogDlg dlg;
请帮助我如何解决这个错误。
I have commented CDialogApp theApp;
line in Dialog.cpp
as I am calling it in mainapplication .exe
The problem happen when it reaches CDialogDlg dlg;
.
Please help me how to resolve this error.
另一种方式是可以将一个基于对话框的应用程序设置为静态库。如果是,那么为什么我得到这个错误。我试图做的主要应用程序在Windows和控制台基础。
In other way is it possible to set a dialog based application as static library. If yes then why am I getting this error. I have tried making the main application in Windows and console based too. Please find the screenshot for better understing, what am I trying to do.
推荐答案
静态库不包含任何资源,但是您的对话框代码尝试加载图标和对话框模板资源。您将资源移动到控制台应用程序中了吗? (我不知道这是否会工作,但如果你不这样做肯定不会工作。)
A static library does not contain any resources, but your dialog code attempts to load icon and dialog template resources. Did you move the resources into the console app? (I don't know if that would work, but it certainly won't work if you don't.)
常规和支持的解决方案是将对话框代码转换成DLL而不是静态库。 DLL可以包含资源。
The conventional and supported solution is to put the dialog code into a DLL instead of a static lib. A DLL can contain the resources.
这篇关于m_hIcon = AfxGetApp() - > LoadIcon(IDR_MAINFRAME);断言失败:at afxwin1.inl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!