将静态Windows库转换为dll
我有一个包含一堆静态 *lib
文件的库,我希望从 JNA
访问它们(一个 Java 库,允许从 JAVA 代码动态调用“dll”) ,那么有没有办法神奇地将静态lib改为dll呢?
代码是使用 Visual Studio 编译的(希望相关),并且我也有适当的头文件。
我无法访问源代码,我也想仅使用免费(如啤酒)工具来完成此操作。
I have a library contains a bunch of static *lib
files, I wish to access them from JNA
(a Java library that allows one to dynamically call `dll's from JAVA Code), so is there a way to magically change static lib to dll?
Code was compiled using Visual studio (hope that is relevant), and I also have appropriate header files.
I do not have access to source code, also I would like to do it using only free (as in beer) tools.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道有任何工具可以自动执行此操作,但该过程是创建一个 DLL 项目并将库添加到该项目中。 对于头文件中的每个函数:
您需要在 DLL 中创建并导出您自己的函数;
这个过程非常机械,您也许可以使用 perl 之类的东西敲出一个脚本来创建 DLL 源文件。
I'm not aware of anyb tools that will do this automatically, but the process is to create a DLL project and add your libraries to the project. For each function in the header file:
you would need to create and export your own function in the DLL;
The process is quite mechanical, and you may be able to knock up a script using something like perl to create the DLL source files.
假设您无权访问源代码,您可以简单地创建一个包装器 DLL,导出您需要的函数并委托给静态库。
Assuming you don't have access to the source, you can simply create a wrapper DLL that exports the functions you need and delegates to the static library.
我按照匿名建议做了,我做了一个自动转换器(有人建议在声明之前放置 _ddlspec(export) 并用这个头编译 dll 就可以了——好吧,它没有——也许我做错了什么——我很简单老Java程序员;)):
它基本上解析头文件并转向:
到:
这是代码(很可能是滥用正则表达式,但它有效),gui部分依赖于MigLayout:
I did as anon suggested, I did an automatic converter (someone suggested just putting _ddlspec(export) before declaration and compiling dll with this header would work -- well it didn't -- maybe i did something wrong -- I'm Plain Old Java Programmer ;)):
it basically parses header files and turns:
to:
Here is the code (most probably its Regexp abuse, but it works), gui part depends on MigLayout: