Link to home
Start Free TrialLog in
Avatar of ganantha
ganantha

asked on

Application Crashing - Invalid Page Fault Error

Hi All,
   Iam Receiving "Invalid Page Fault in MFC42.dll" error while launching my Application. Its a Release Mode Application. My investigation has shown that it is crashing in LoadFrame(IDR_MAINFRAME)call in InitInstance.
   Sometime back I had similar problem with debug build and I could resolve it by installing latest VC Service Packs.
   Any inputs in resolving  this will be of great help.
Regards,
Anantha
ASKER CERTIFIED SOLUTION
Avatar of lakshman_ce
lakshman_ce

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lakshman_ce
lakshman_ce

Hi,

1) Here I am providing u an abstract from MSDN regarding this error. Please check out whether any of the cause is there in your application.

SYMPTOMS
When developing applications in Visual C++ with MFC, you may receive an invalid page fault in Mfc42.dll in release builds due to an incorrect function signature for any of the following MFC macros:
ON_MESSAGE()
ON_REGISTERED_MESSAGE()
ON_THREAD_MESSAGE()
ON_REGISTERED_THREAD_MESSAGE()

CAUSE
The message handlers for ON_MESSAGE(), ON_REGISTERED_MESSAGE(), ON_THREAD_MESSAGE(), and ON_REGISTERED_THREAD_MESSAGE() require the programmer to have the correct function signatures. By not having a correct function signature for the handler, an invalid page fault in Mfc42.dll results after the handler executes in release builds. A crash in debug builds does not occur because the stack frame is set up differently for debug builds than it is for release builds.

RESOLUTION
Make sure your message handlers for ON_MESSAGE(), ON_REGISTERED_MESSAGE(), ON_THREAD_MESSAGE(), and ON_REGISTERED_THREAD_MESSAGE() have the correct signatures.
The correct signature for ON_MESSAGE() is:
   afx_msg LRESULT OnMyMsg(WPARAM, LPARAM)
The correct signature for ON_REGISTERED_MESSAGE is:
   afx_msg LRESULT OnMyRegisteredMsg(WPARAM, LPARAM)
The correct signature for ON_THREAD_MESSAGE is:
   afx_msg void OnMyThreadMsg(WPARAM, LPARAM)
The correct signature for ON_REGISTERED_THREAD_MESSAGE is:
   afx_msg void OnMyRegisteredThreadMsg(WPARAM, LPARAM)
For signatures for other versions of Visual C++, please consult help for ON_MESSAGE(), ON_REGISTERED_MESSAGE(), ON_THREAD_MESSAGE() and ON_REGISTERED_THREAD_MESSAGE().

2. Regarding your investigation, Is the code is for LoadFrame is similar like
     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
          return FALSE;
     m_pMainWnd = pMainFrame;
as we get in MDI application's InitInstance() function.??

Regards,
lakshman
Avatar of ganantha

ASKER

Lakshman,
  Thx. for u'r time.
  I have looked at this MSDN abstract. This is reg. the wrong signatures for certain msg. handlers. In my case its happening in InitInstance with is a virtual function.
  Reg.
  . Regarding your investigation, Is the code is for LoadFrame is similar like
    if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
         return FALSE;
    m_pMainWnd = pMainFrame;
as we get in MDI application's InitInstance() function.??
-----yes Iam getting in the same location.
    The call to load frame causes a crash. Its happening in Loadframe code.
Regards,
Anantha
Avatar of DanRollins
Hi lakshman_ce,
The experts in this section have generally agreed to post comments rather than answers.  The lets the question remain in the upper section of the screen where it is more likely to get the attention of other experts.  When you post an 'Answer' it might deprive ganantha of some additional expert input that could help move toward a solution.

So, in the future, please post comments, like everybody else.  Thanks!

-- Dan
hi
could you plz send code.
my id is amit.a@blr.hpsglobal.com.
because that will give me more understanding of the crash

thanx
amit
hi,

Needed some more inputs regarding the function signatures for User Defined Message Handlers. Was trying to resolve a Random Invalid page fault in Release Mode exe, that's causing my Application to crash.

According to Lakshman_ce's comments (from MSDN), the correct signature for ON_MESSAGE() is
afx_msg LRESULT OnMyMsg(WPARAM,LPARAM). However my message handler function is not returning anything, hence am using afx_msg void. Would that matter ?
Also can anyone tell me why exactly my function signature for the message handler has to be outside the AppWizard generated message handler segment.

Have attached a sample code snippet below. Does anyone see anything that could lead to a mfc42.dll page fault, therein.

Thanx,
Deep.

/*MyMacros.h*/
#define WM_USER_UPDATE_STATUS_LOG   (WM_USER + 52)    

/*ChildFrm.h*/
class CChildFrame : public CMDIChildWnd
{
  DECLARE_DYNCREATE(CChildFrame)
  public:
     CChildFrame();

  // Generated message map functions
  protected:
     //{{AFX_MSG(CChildFrame)
     afx_msg int OnCreate(LPCREATESTRUCT  
                                     lpCreateStruct);
     afx_msg void OnDestroy();
     //}}AFX_MSG
     afx_msg void OnSmsStatusLog(WPARAM, LPARAM);

     DECLARE_MESSAGE_MAP()
};

/*ChildFrm.cpp*/

// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
     //{{AFX_MSG_MAP(CChildFrame)
     ON_WM_CREATE()
     ON_WM_DESTROY()
     //}}AFX_MSG_MAP
     ON_MESSAGE (WM_USER_UPDATE_STATUS_LOG,OnSmsStatusLog)
END_MESSAGE_MAP()

///////////////////////////////////////////////////////////
>>  However my message handler function is not returning anything,  hence am using afx_msg void.
>>Would that matter ?


Absolutely, and it is most certainly the cause of the problem.  You must declare the function as it is described in MSDN and you must return a value.  In general, return a value of 0 to indicate that you have handled the message.

This kind of error often shows up only in Release builds becasue the Debug build leaves padding on the stack.  In either type of build there will be errors, but they show up writ large in Release build.

-- Dan
Unless there is objection or further activity,  I will suggest to accept

     "lkshman_ce"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Force accepted

** Mindphaser - Community Support Moderator **