Rasmi Ranjan Nayak
Rasmi Ranjan Nayak

Reputation: 11968

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); Assertion Failed: at afxwin1.inl

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.

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);

}

It throws above error.

In my 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;
}

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.

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.enter image description here

Upvotes: 0

Views: 3949

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10425

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.)

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.

Upvotes: 1

Related Questions