Windows Message handling in Debug and Release build of Dialog Based MFC Application
-
I am working on Dialog based application using MFC in VC++. In that i have handled Row change message of Grid (GRID_WMUSER_ROWCHANGE) its user defined message and I have written handler : for example **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, fun) void Cdlg::fun(int n) { MessageBox(..... } **Cdlg.h** void fun(int n=0) now in the Debug build of the Program this works fine. But when i run the application in the Release build the Program crashes as soon as row change of event of Grid occurs. Now if I correct the above code as **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, OnRowChangeGrdLoad) void Cdlg::fun(int n) { MessageBox(..... } LRESULT CDlg2701::OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ) { fun(); } **Cdlg.h file** afx_msg LRESULT OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ); After doing this my application works fine in both Debug and Release build. I want to know what is the reason behind this?? why such difference in Debug and Release build ??
-
I am working on Dialog based application using MFC in VC++. In that i have handled Row change message of Grid (GRID_WMUSER_ROWCHANGE) its user defined message and I have written handler : for example **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, fun) void Cdlg::fun(int n) { MessageBox(..... } **Cdlg.h** void fun(int n=0) now in the Debug build of the Program this works fine. But when i run the application in the Release build the Program crashes as soon as row change of event of Grid occurs. Now if I correct the above code as **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, OnRowChangeGrdLoad) void Cdlg::fun(int n) { MessageBox(..... } LRESULT CDlg2701::OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ) { fun(); } **Cdlg.h file** afx_msg LRESULT OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ); After doing this my application works fine in both Debug and Release build. I want to know what is the reason behind this?? why such difference in Debug and Release build ??
read the Forum Guidelines[^] before posting code :suss:
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
I am working on Dialog based application using MFC in VC++. In that i have handled Row change message of Grid (GRID_WMUSER_ROWCHANGE) its user defined message and I have written handler : for example **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, fun) void Cdlg::fun(int n) { MessageBox(..... } **Cdlg.h** void fun(int n=0) now in the Debug build of the Program this works fine. But when i run the application in the Release build the Program crashes as soon as row change of event of Grid occurs. Now if I correct the above code as **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, OnRowChangeGrdLoad) void Cdlg::fun(int n) { MessageBox(..... } LRESULT CDlg2701::OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ) { fun(); } **Cdlg.h file** afx_msg LRESULT OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ); After doing this my application works fine in both Debug and Release build. I want to know what is the reason behind this?? why such difference in Debug and Release build ??
If you are too lazy to even write your own name into account, then I ( and I am sure many others ) will not even bother to read your posts. PLEASE FIX IT!!!
-
read the Forum Guidelines[^] before posting code :suss:
Don't know where to start ?
Refer the Forums Guidelines and ask a friendFWIW, I love the "Ask a friend" link... The easter egg section also has some interesting content. Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
I am working on Dialog based application using MFC in VC++. In that i have handled Row change message of Grid (GRID_WMUSER_ROWCHANGE) its user defined message and I have written handler : for example **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, fun) void Cdlg::fun(int n) { MessageBox(..... } **Cdlg.h** void fun(int n=0) now in the Debug build of the Program this works fine. But when i run the application in the Release build the Program crashes as soon as row change of event of Grid occurs. Now if I correct the above code as **CDlg.cpp** ON_MESSAGE( GRID_WMUSER_ROWCHANGE, OnRowChangeGrdLoad) void Cdlg::fun(int n) { MessageBox(..... } LRESULT CDlg2701::OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ) { fun(); } **Cdlg.h file** afx_msg LRESULT OnRowChangeGrdLoad( WPARAM wParam, LPARAM lParam ); After doing this my application works fine in both Debug and Release build. I want to know what is the reason behind this?? why such difference in Debug and Release build ??
wrote:
I want to know what is the reason behind this?? why such difference in Debug and Release build ??
Stack corruption causes the crash. The correct signature of a message handler, the function takes a WPARAM and an LPARAM (which are pushed onto the stack when the function is called) and returns an LRESULT (which is popped from the stack when the function returns). In the incorrect version of your code, the
fun()
function is being called as if it had this signature, even though thefun()
function does not, and as a result there is stack corruption. The fact that it works in debug mode is a coincidence, possibly due to padding added by the compiler in debug compilations. Incidentally, are you still using VC 6.0? The error in signatures for message handlers is flagged as a compiler error in newer versions of Visual Studio. Mike