Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

m_pMainWnd changed to NULL in MFC [closed]

Tags:

c++

mfc

I've got this code in the InitInstance function of a class that extends WinApp:

m_pMainWnd = &m_Frame;  // Clearly setting m_pMainWnd to !NULL
m_Frame.LoadFrame(BMP_ICON, 0, NULL, NULL);

m_pMainWnd->GetMenu()->Detach();
m_pMainWnd->SetMenu(NULL);

m_Frame.ShowWindow(SW_SHOW);
m_Frame.UpdateWindow();

Yet when running, the app opens, displays the m_Frame for like a millisecond and then closes again. I get this output:

Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
Warning: m_pMainWnd is NULL in CWinApp::Run - quitting application.
The thread 'Win32 Thread' (0x914) has exited with code 0 (0x0).
The program '[6628] VentSizerPro.exe: Native' has exited with code 0 (0x0).

So somewhere along the line m_pMainWnd has been changed to NULL, but where and why and how and what? :(

EDIT:

m_Frame is an instance of a class that exends CFrameWnd to modify the window frame.

like image 894
user965369 Avatar asked Feb 20 '23 23:02

user965369


1 Answers

Don't be an idiot.. you assigned the pointer value to the value of a local variable.

like image 59
user965369 Avatar answered Feb 26 '23 21:02

user965369