Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to resolve Mfc42.dll page fault related crash ?

Status
Not open for further replies.

DeepHaze

Programmer
Jul 31, 2002
2
IN
hi,

Needed some 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 comments gathered from similar questions here, 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()

///////////////////////////////////////////////////////////
 
It's the afx_msg void that's doing it. The message handler must return an LRESULT. Since it's not returning anything, it's causing a crash. Here's why:

The return value from a function gets placed on the top of the stack when the function exits. If your function is supposed to return an LRESULT, the caller will expect that LRESULT to be on the top of the stack. It will pop that many bytes off the stack. Since your function didn't return anything, the 4 bytes it pops off the stack are 4 bytes from the next instruction. The machine then tries to execute a corrupted instruction, which causes the crash.

Return an LRESULT and it will work fine.
 
thanx for ur inputs dds82.

However changing the msg handler to return an LRESULT instead of void hasn't helped much. The application still crashed with the following page faults that ocurred in the sequence mentioned below.
The only difference I noticed is that previously the first page fault used to occur in my exe (GSMNWDRIVERDB.EXE) , whereas after the changes it occured in 'unknown module'.

Any clues to this behaviour ??
Deep.

Page Fault 1
*************

GSMNWDRIVERDB caused an invalid page fault in
module <unknown> at 00de:00000003.
Registers:
EAX=0002e71a CS=0137 EIP=00000003 EFLGS=00010202
EBX=00000000 SS=013f ESP=025dfbc8 EBP=00000132
ECX=30bc0378 DS=013f ESI=00466b9c FS=34b7
EDX=006e7980 ES=013f EDI=006da20f GS=0000
Bytes at CS:EIP:
00 8c 41 22 c4 16 00 b4 08 65 04 70 00 65 04 70
Stack dump:
006afa2c 007d4220 025dff60 0000002d 54003000 312c203a 0a0d3335 00003000
006d35a0 006da1e8 006da408 6c441c58 6c441c58 007d6e00 00000000 00466a10



Page Fault 2
*************

GSMNWDRIVERDB caused an invalid page fault in
module MFC42.DLL at 0137:6c371351.
Registers:
EAX=00000000 CS=0137 EIP=6c371351 EFLGS=00010246
EBX=6c440008 SS=013f ESP=00fefaa0 EBP=00fefad4
ECX=00000000 DS=013f ESI=007d26c0 FS=18e7
EDX=00000003 ES=013f EDI=0058022c GS=18de
Bytes at CS:EIP:
8b 71 04 85 f6 57 74 26 8b 7c 24 0c 33 d2 8b c7
Stack dump:
007d26c0 6c375c16 00000800 0058022c 6c440008 00580160 6c3e7754 00000001
00580160 00580160 00fefe28 6c402c76 00000000 00fefaf8 6c3764d0 0058027c

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top