Solution: Crash in Release build with self-defined message
We often meet such case: I have an application with a modeless dialog. The dialog comes up perfectly in DEBUG build, But in RELEASE build, it crashed.
Such problem often occures because of incorrect signature of message handle functions, that included into MFC message map for your CWnd based class.
We should very carefully check signatures such functions in comparision with expected one by MFC library. For example, if you put follow handler into message map
and define OnMyMessage as:
{
//do something
}
this code will be compiled without errors. DEBUG build can work without any problems, but RELEASE will crash besause ON_MESSAGE macro expect follow
signature:
DEBUG build works because stack processing has differences for debug and release builds.
so, the solution is simple:
Solution 1: modify the message handle functions with the following style and it will be ok.
Solution 2: don’t modify the message handle functios, and change the ON_MESSAGE macro to ON_MESSAGE_VOID.
This macro is in AfxPriv.h, but is largely undocumented.