简体   繁体   English

如何检查在调用CallwindowProc时window proc是否未损坏?

[英]How to check if window proc is not corrupted in call to CallwindowProc?

I need to call API 我需要调用API

CallWindowProc((WNDPROC)lpfnOldProc, hWnd, Message, wParam, lParam);

Now how can I make sure that lpfnOldProc still valid ? 现在如何确定lpfnOldProc仍然有效?

Basically, lpfnOldProc is procedure in another dll and if that dll is unloaded then lpfnOldProc will still be pointing to something but not valid memory? 基本上, lpfnOldProc是另一个dll中的过程,如果该dll被卸载,则lpfnOldProc仍将指向某个东西,但不是有效的内存?

Are there some memory API's through which I can verify validity of lpfnOldProc ? 是否有一些内存API可用来验证lpfnOldProc有效性?

Don't worry. 不用担心 You're in a hook proc obviously. 显然,您处于挂接过程中。 Now, even in your absence the program would crash if the original window proc was unloaded and called. 现在,即使在您不在的情况下,如果原始窗口proc被卸载并调用,程序也会崩溃。 It doesn't matter that you're now the caller instead of Windows. 您现在是Windows的呼叫者,这并不重要。

A Window Proc should remain in memory as long as there are existing windows using it. 只要有现有的窗口正在使用Window Proc,它就应该保留在内存中。 The responsibility for this check lies fully with the code considering the unload, not the callers of the Window Proc (ie you). 该检查的责任完全在于考虑卸载的代码,而不是Window Proc的调用者(即您)。 This responsibility can be summarized in one line: "Don't unload anything still in use." 这一责任可以概括为以下一行:“不要卸载仍在使用的任何东西。”

You can't check. 您无法检查。 You can set up structured exception handling to catch the fault that will result of the DLL in question has gone away or been replaced by a copy of the Encyclopedia Brittanica mapped into memory. 您可以设置结构化异常处理来捕获将导致问题DLL消失或被映射到内存中的Brittanica百科全书副本取代的错误。

Happened something similar in the pass, name two or more dll trying to override a window proc. 在传递过程中发生了类似的情况,将两个或多个dll命名为试图覆盖窗口proc。 Normally as part of the process shutdown, or a plugin unload, they try to restore the "oldWndProc", but since they are not aware of each other they may end up overriding a good pointer with an invalid pointer and then crash happens. 通常,在关闭进程或卸载插件的过程中,他们会尝试还原“ oldWndProc”,但是由于彼此之间不了解,因此它们最终可能会被无效的指针覆盖,从而导致崩溃。

If you have access to the source code the best you can do is to have only one dll responsible for hooking a window proc, and then the rest can implement a kind of delegate, so when unloding it can be set to null, and the hooking dll can check and if it is null skip the call. 如果您可以访问源代码,则最好的办法是只有一个dll负责挂接窗口proc,然后其余的可以实现一种委托,因此在取消挂载时可以将其设置为null,然后进行挂接dll可以检查,如果它为null,则跳过该调用。

If you don't have access to the source code, perhaps because you are trying to make your dll work with an already very popular (and buggy) plugin, you may try to find a repeteable procedure so you can detect this case of corruption before it happens (check some of messages before your crash), and workaround it with a custom message notifying your wndproc. 如果您无权访问源代码,也许是因为您试图使dll与已经非常流行(且有错误的)插件一起工作,则可以尝试找到可重复的过程,以便在之前检测到这种损坏情况它会发生(崩溃前检查一些消息),并通过通知您的wndproc的自定义消息来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM