Windows Messaging - 捕获来自另一个 API 的调用

发布于 2024-10-09 09:12:17 字数 550 浏览 0 评论 0原文

场景

我们正忙于将第 3 方的 C++ SDK 包装为 DLL,以便我们组织中的其他开发人员更容易将此功能集成到他们自己的应用程序中(无论是 .net、delphi、等)

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

问题

在我们正在采用的方法的上下文中处理这些消息的最佳方法是什么(即包装第 3 方 SDK 的 DLL)?我想到了一些想法:

  1. 让使用 DLL 的应用程序捕获消息,然后通过函数调用将其传回 DLL 进行处理——调用应用程序是否有可能捕获这些消息?
  2. 从 DLL 中生成一个线程,该线程实现一个消息泵,处理来自底层系统的这些消息并冒泡我们自己的自定义消息?

为 SDK 提供的所有示例代码都使用单个 Win32 应用程序,该应用程序实现消息泵并在应用程序上下文中处理消息。

我已经很久没有使用本机 Win32 进行 Windows 开发了,希望得到一些建议。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末蓝 2024-10-16 09:12:17

最简单的方法是制作一个代理DLL。基本思想是用你自己的 API DLL 替换,替换你想要的函数,并将其余的转发到原始 API DLL。您重命名原始 DLL,并将 API DLL 的原始名称放入其中。为此,您需要导出函数。 Microsoft 使用 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 已经处于活动状态(除非您正在密切监视系统) )并可能启动防病毒程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文