typedef 解决 dll 包装器问题

发布于 2024-09-09 04:27:58 字数 192 浏览 2 评论 0原文

我想为 DLL 文件编写一个包装,在本例中是为 python 编写的。问题是参数类型不是 C 标准类型。它们已被类型定义为其他东西。

我有 DLL 文件的头文件...所以我可以手动跟踪参数类型被类型定义的原始标准 C 类型。但想要一种更系统的方法来做到这一点。我想知道是否有一个实用程序可以评估头文件,或者您是否可以在 dll 中的某个位置获取类型定义。

I want to write a wrap for a DLL file, in this case for python. The problem is that the argument types are not the C standard ones. They have been typedef'end to something else.

I have the header files for the DLL files... so I can manually track the original standard C type the argument type was typedef'ined to. But wanted a more systematic way to do this. I was wondering whether there is a utility that would evaluate the header files, or if you can get somewhere in the dll the types definition.

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

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

发布评论

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

评论(1

枫以 2024-09-16 04:27:58

我认为您正在寻找的工具是 SWIG

SWIG 是一种软件开发工具,它将用 C 和 C++ 编写的程序与各种高级编程语言连接起来。 SWIG 可与不同类型的语言一起使用,包括 Perl、PHP、Python、Tcl 和 Ruby 等常见脚本语言。支持的语言列表还包括非脚本语言,例如 C#、Common Lisp(CLISP、Allegro CL、CFFI、UFFI)、Java、Lua、Modula-3、OCAML、Octave 和 R。还有一些解释和编译的方案实现(支持 Guile、MzScheme、Chicken)。 SWIG 最常用于创建高级解释或编译编程环境、用户界面,以及作为 C/C++ 软件测试和原型设计的工具。 SWIG 还可以以 XML 和 Lisp s 表达式的形式导出其解析树。 SWIG 可以自由使用、分发和修改以用于商业和非商业用途。

这确实假设您愿意使用 DLL 的标头。如果您想单独使用 DLL,那么您还有更多工作要做。它可能提供一个可用于分析类型的反射接口。如果做不到这一点,您就会陷入痛苦的世界——或者对 DLL 中的任何调试信息进行逆向工程。

I think the tool you are looking for is SWIG:

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. The list of supported languages also includes non-scripting languages such as C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Lua, Modula-3, OCAML, Octave and R. Also several interpreted and compiled Scheme implementations (Guile, MzScheme, Chicken) are supported. SWIG is most commonly used to create high-level interpreted or compiled programming environments, user interfaces, and as a tool for testing and prototyping C/C++ software. SWIG can also export its parse tree in the form of XML and Lisp s-expressions. SWIG may be freely used, distributed, and modified for commercial and non-commercial use.

This does assume that you are willing to use the headers for the DLL. If you want to work solely with the DLL, then you have more work to do. It might provide a reflection interface that you can use to analyze the types. Failing that, you are into a world of pain - or reverse engineering any debugging information in the DLL.

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