Windows Messaging - 捕获来自另一个API的呼叫 [英] Windows Messaging - trapping calls originating from another API

查看:156
本文介绍了Windows Messaging - 捕获来自另一个API的呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景



我们正忙着将第三方的C ++ SDK作为一个DLL,使其更容易为其他开发人员组织将此功能集成到自己的应用程序(无论是,.net,delphi等)中。



底层系统发送Windows消息以发出系统中发生的事件。这些事件需要处理,因为它们可能会显示系统的状态,接下来可以做些什么。



问题: / p>

在我们正在采取的方法(即包装第三方SDK的DLL)的上下文中,最好的方法是处理这些消息?一些想法想到:


  1. 让使用DLL的应用程序捕获消息,然后通过函数将其传回给DLL呼叫处理 - 呼叫应用程序是否可能陷阱这些消息?

  2. 从DLL内部生成一个线程,该线程实现了从基础系统处理这些消息的消息泵,引发我们自己的自定义消息?

为SDK提供的所​​有示例代码都使用一个实现消息泵的Win32应用程序,并处理



自从我使用本机Win32完成Windows开发以来,它已经过去了,并且会欣赏一些建议。


div class =h2_lin>解决方案

最简单的方法是制作代理DLL。基本的想法是用你自己的API代替API,替换你想要的功能,并将其余的转发给原来的API DLL。您重命名原始的DLL并放入您的API DLL的原始名称。为此,您需要导出功能。微软已经使用Visual Studio来做到这一点。



以下是导出功能的方法: http://msdn.microsoft.com/en-us/library/z4zxe9k8%28v=VS.100%29.aspx



如果您不知道他们正在使用的API的函数调用,则有一个名为PE Explorer的实用程序可以告诉您所有的功能。对于单一营业执照,它的成本为229美元,但它看起来像是值得的: http: //pe-explorer.com/peexplorer-tour-function-view.htm



有些方法可以替换内存中的API调用,但复杂,要求API已经处于活动状态(除非您密切监视系统),并可能会启动防病毒程序。


Scenario:

We're busy wrapping up a 3rd party's C++ SDK as a DLL to make it simpler for other developers in our organisation to integrate this functionality into their own apps (be it, .net, delphi, etc)

The underlying system sends Windows messages to signal events that occur in the system. These events need to be dealt with, as they could potentially signal the state of the system and what can be done next.

Question:

What would the best way be to handle these messages within the context of the approach we are taking (i.e a DLL that wraps up the 3rd party SDK)? Some ideas that come to mind:

  1. Let the application using the DLL trap the message, and then pass it back to the DLL via a function call for processing -- is it even possible for the calling application to trap these messages?
  2. Spawn a thread from within the DLL that implements a message pump that handles these messages from the underlying system and bubbles up our own custom messages?

All sample code given for the SDK uses a single Win32 app that implements a message pump and handles the messages within the context of the application.

Its been ages since I have done Windows development using native Win32 and would appreciate some advice.

解决方案

The easiest way is to make a proxy DLL. The basic idea is to replace the API DLL with your own, replace the functions you want to and forward the rest to the original API DLL. You rename the original DLL and put in your with the original name of the API DLL. To do this you need to export the functions. Microsoft has made this fairly simple using Visual Studio.

Here's how to export the functions: http://msdn.microsoft.com/en-us/library/z4zxe9k8%28v=VS.100%29.aspx

If you dont know the function calls of the API they are using, there is a utility called PE Explorer that can tell you all about the functions. It costs $229 for a single business license but it looks like it's worth it's money: http://pe-explorer.com/peexplorer-tour-function-view.htm

There are ways to replace the API calls in memory but it's complex, requires the API to already be active (unless you are closely monitoring the system) and may set off an antivirus programs.

这篇关于Windows Messaging - 捕获来自另一个API的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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