滥用 RegisterWindowMessage 会导致资源耗尽吗? [英] Can abusing RegisterWindowMessage lead to resource exhaustion?

查看:25
本文介绍了滥用 RegisterWindowMessage 会导致资源耗尽吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN 建议 RegisterWindowMessage() 函数仅用于注册要在进程之间发送的消息.如果需要在一个进程内发送消息,可以安全地从 WM_APP 到 0xBFFF 范围内选择.

MSDN advises that RegisterWindowMessage() function is only used for registering messages to be sent between the processes. If a message is needed for sending within one process it can be safely selected from the range WM_APP through 0xBFFF.

但是在我们的代码库中,我经常看到 RegisterWindowMessage() 用于仅在一个进程内发送的消息.我认为这样做是因为使用 RegisterWindowMessage() 的感觉很简单,因为它不需要在 WM_APP..0xBFFF 范围内手动分发消息标识符.

However in our codebase I often see that RegisterWindowMessage() is used for messages only sent within one process. I suppose that this was done because of perceived simplicity of using RegisterWindowMessage() since it doesn't require manually distributing the message identifiers in the WM_APP..0xBFFF range.

我是否正确理解,如果许多应用程序在一台机器上运行,并且它们都使用不同的字符串调用 RegisterWindowMessage(),它们可能会耗尽 RegisterWindowMessage() 允许返回的消息标识符范围,而对于其中一些应用程序,它只会返回一个表示失败的值?在 WM_APP..0xBFFF 范围消息就足够的情况下,使用 RegisterWindowMessage() 消息的正当理由是什么?

Do I understand correctly that if many applications are run on one machine and they all call RegisterWindowMessage() with different strings they could exhaust the range of message identifiers allowed to return by RegisterWindowMessage() and for some of them it will just return a value indicating a failure? What could be a valid reason for using RegisterWindowMessage() messages in cases where WM_APP..0xBFFF range messages would suffice?

推荐答案

恕我直言,如果您只是向自己发送消息,则没有正当理由使用 RegisterWindowMessage

IMHO there is no valid reason to use RegisterWindowMessage if you are only sending messages to yourself

没有(已记录的)取消注册消息的方法,因此在您的应用程序退出后,该注册消息将保留在原子表中,直到重新启动/注销(我不记得该原子表的确切存储位置,窗口站或终端服务器会话实例可能)

There is no (documented) way to un-register a message, so after your app quits, that registered message will stay in the atom table until reboot/logoff (I can't remember exactly where this atom table is stored, the window station or terminal server session instance probably)

这篇关于滥用 RegisterWindowMessage 会导致资源耗尽吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆