无限消息循环导致堆栈溢出后,WTL 窗口/窗体崩溃
我有一个遗留项目,需要修复 WTL/VC++ 中的错误。问题之一 - 使用 Ctrl+X 或 Ctrl+Z 键后主窗口(当然,整个应用程序)崩溃。我没有为这些键分配任何自定义加速器。 我发现“致命”组合键会导致无限消息循环,
uMsg == 273 (0x00000111)
最终因堆栈溢出错误而崩溃:
Command Code: 5, ID: 29892, HANDLE: 0xe091aFirst-chance exception at 0x007f88fa
in <myApp>.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x007f88fa in <myApp>.exe: 0xC00000FD: Stack overflow.
我只是在消息处理函数中对其进行了修补 -
BEGIN_MSG_MAP(CMDIChildWindowImpl) )
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
* **
COMMAND_ID_HANDLER(ID_FILE_NEW, OnNewDownload)
COMMAND_ID_HANDLER(ID_UPLOAD_FOLDER_SET, OnUploadFolderSet)
COMMAND_ID_HANDLER(ID_OPEN_RECORD_BY_ID, OnOpenOnline)
*
NOTIFY_CODE_HANDLER(HLN_PORTAL_RECORD_DOWNLOAD, OnPortalPageNotify);
NOTIFY_CODE_HANDLER(HLN_SELCHANGED, OnWebFormNotify);
if(uMsg == 273)
return false;
else
CHAIN_MSG_MAP(baseClass)
END_MSG_MAP()
但我对这个创可贴补丁并不满意,如果能了解发生了什么就太好了 - 我实际上希望这些组合键在我的表单上执行 Windows 默认操作,“剪切”和“撤消”
有关致命消息的更多信息:
Ctrl+X -
uMsg 273 unsigned int
wParam 123171 unsigned int
lParam 0 long
lParam 0 long
Ctrl+Z -
uMsg 273 unsigned int
wParam 123179 unsigned int
lParam 0 long
对不起,如果这没有意义,我的 VC++ 功夫相当生疏;如果有人能给我提示在哪里寻找这些想法,我将不胜感激。
谢谢你!
奥。
I have a legacy project I need to fix bugs in, WTL/VC++. One of the problems - a crash of the main window (well, the entire application, of course) after Ctrl+X or Ctrl+Z keys are used. I don't have any custom accelerators assigned to those keys.
I found that the "fatal" key combinations cause an infinite message loop with
uMsg == 273 (0x00000111)
that eventually crashes with stack overflow error:
Command Code: 5, ID: 29892, HANDLE: 0xe091aFirst-chance exception at 0x007f88fa
in <myApp>.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x007f88fa in <myApp>.exe: 0xC00000FD: Stack overflow.
I simply patched it in the message processing function -
BEGIN_MSG_MAP(CMDIChildWindowImpl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
*
*
COMMAND_ID_HANDLER(ID_FILE_NEW, OnNewDownload)
COMMAND_ID_HANDLER(ID_UPLOAD_FOLDER_SET, OnUploadFolderSet)
COMMAND_ID_HANDLER(ID_OPEN_RECORD_BY_ID, OnOpenOnline)
*
*
NOTIFY_CODE_HANDLER(HLN_PORTAL_RECORD_DOWNLOAD, OnPortalPageNotify);
NOTIFY_CODE_HANDLER(HLN_SELCHANGED, OnWebFormNotify);
if(uMsg == 273)
return false;
else
CHAIN_MSG_MAP(baseClass)
END_MSG_MAP()
But I'm not satisfied with this band-aid patch, it would be nice to understand what's going on - and I actually want those key combinations do the Windows default things on my form, "cut" and "undo"
more info on the fatal messages:
Ctrl+X -
uMsg 273 unsigned int
wParam 123171 unsigned int
lParam 0 long
lParam 0 long
Ctrl+Z -
uMsg 273 unsigned int
wParam 123179 unsigned int
lParam 0 long
Sorry if this doesn't make sense, my VC++ kung fu is rather rusty; If anyone could give me a hint where to look for the ideas, that would be greatly appreciated.
Thank you!
O.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现了这一点,感谢@Roman R。 - 在有问题的窗口中,没有 WM_COMMAND 消息的处理程序,并且在其基类之一中有一个函数通过将消息转发回活动窗口来生成无限循环。所以我添加了这个处理程序 -
这对我来说似乎是一个很好的解决方案。
谢谢!
Found this, thanks to @Roman R. - in the window in question, there was no handler for the WM_COMMAND message, and in one of its base classes there was a function that generated the infinite loop by forwarding the message back to the active window. So I added this handler -
which seems like a good solution for me.
Thanks!