Call AfxGetMainWnd() from derived class of DialogEx returns NULL

995 Views Asked by At

I need to gain access to a member of main frame and can be changed by reference. Here is a free function to get main frame

inline CMainFrame* GetMainFrame()
{
    CMainFrame* mainFrame = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
    ASSERT(mainFrame);
    return mainFrame;
}

I called above function to my Dialog of an MFC application and found the main frame pointer NULL.

How can I gain access of main frame member which can be changed by reference?

Thanks in advance.

0

There are 0 best solutions below