调用 DLL 中嵌入的静态 lib 函数

发布于 2024-12-09 20:58:47 字数 166 浏览 0 评论 0原文

假设有以下架构:

  • 在 DLL 中使用/链接静态库
  • DLL 由可执行文件加载(隐式或显式)

是否可以从可执行代码访问静态库的代码,而无需显式重新链接它或插入包装器DLL 中的函数? 换句话说,我正在寻找一种方法来导出依赖的静态库代码的 dll。

Let's say the following architecture:

  • A static library is used/linked within a DLL
  • The DLL is loaded (either implicitly or explicitly) by an executable

Is it possible from the executable code to access code of the static library without relinking it explicitly nor inserting wrapper functions in the DLL?
In other terms, I am looking for a way to make a dll export of dependant static library code.

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

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

发布评论

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

评论(2

明媚如初 2024-12-16 20:58:47

考虑到你的限制,答案是否定的。

原因是可执行文件对 DLL 的依赖项或“调用者”没有任何可见性。就可执行文件而言,他只知道 DLL 本身:在链接时,可执行文件只知道它从 DLL 中消耗的那些导出。他将对 DLL 调用 LoadLibrary()(如果所述 DLL 的依赖关系不可解析,则会失败),然后调用所述 DLL 的导出。

如果由于某种原因无法静态链接 DLL 使用的库,另一种方法是将调用包装到所述静态库。这可能会很痛苦,因为有很多电话,但其他人已经创建了一些自动化工具来提供帮助。特别是,我之前使用过它来为 DLL 创建一个包装器,当我想拦截特定函数时,它会导出数百个函数:http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs.aspx

Given your constraints, the answer is no.

The reason is that the executable doesn't have any visibility into the dependencies or "call-ees" of the DLL. As far as the executable is concerned, he's just knows about the DLL itself: at link time, the executable knows only about those exports it is consuming from the DLL. He's going to LoadLibrary() against the DLL (which will fail if the dependencies of said DLL aren't resolvable), then call the exports of said DLL.

If you can't statically link with the library used by the DLL for some reason, another approach is to wrap the calls to said static library. This can be a pain of there are lots of calls, but there are automated tools which others have created to help. In particular I've used this before to create a wrapper for a DLL which exported hundreds of functions when I wanted to intercept a particular one: http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs.aspx

破晓 2024-12-16 20:58:47

答案可能很简单:是的。

唯一的要求是:

在静态 LIB 文件中,您必须为所有要导出的内容定义 __declspec(dllexport)。
然后,当您将此 LIB 文件包含到 DLL 项目中时,您声明为 __declspec(dllexport) 的所有函数都将自动 DLL 导出,并且可以从您的 Exe 访问。

The answer may easily be: Yes.

The only requirement is:

In your static LIB file you must define __declspec(dllexport) for all what you want to export.
When you then include this LIB file into your DLL project all the functions that you have declared as __declspec(dllexport) will be automatically DLL Exports and can be accessed from your Exe.

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