MFC blues
A release build of a MFC application crashes, while the Debug build works fine.
The crash analysis shows that the stack has been overwritten and thus destroyed.
Further analysis reveals that the crash occurs inside a ::SetWindowText
call in a CEdit
sub-classed object. This shouldn’t be my code, right? Wrong.
What was happening is that somewhere inside the call the framework called my OnUpdate
handler (setup with ON_CONTROL_REFLECT_EX
). The problem was that the handler was defined having a wrong prototype: BOOL OnUpdate(NMHDR* pNotifyStruct, LRESULT* result)
instead of BOOL OnUpdate()
. The framework doesn’t perform type checking – the function pointer is just being casted and the call is being made. So, no parameters are being pushed, but two parameters are popped – and the stuck is trashed.