调用 DLL 中嵌入的静态 lib 函数
假设有以下架构:
- 在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑到你的限制,答案是否定的。
原因是可执行文件对 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
答案可能很简单:是的。
唯一的要求是:
在静态 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.