在 .NET 的 *.a 库中使用 C 函数
我有一个 API,它由头文件 (.h) 和库文件 (.a) 组成。
我从未接触过 C,我需要从 C# 访问此 API 并与其函数进行交互。
关于此主题的大多数 问题 都说我需要做类似 [ DllImport("insert_the_dll_name_here")]
用于调用 DLL 方法。但我只有 .h 和 .a 文件。
我应该做什么?
我应该将这些文件编译到DLL中然后使用pInvoke吗?如果是这样,怎么办?
或者我应该写一个包装类?如果是这样怎么办?
任何帮助表示赞赏。
I have an API which is comprised of a header (.h) and the library (.a) files.
I've never touched C and i need to access this API from C# and interact with it's functions.
Most questions regarding this topic say i need to do something like [DllImport("insert_the_dll_name_here")]
this to invoke the DLL methods. But i only have the .h and .a files.
What should i do?
Should i compile these files into the DLL and then use pInvoke? If so, How?
Or should i write a wrapper class? If so how?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
.a
文件包含 Windows 格式的目标文件,那么您可以提取存档(使用 cygwinar
工具)并将其链接到 C++/CLI 项目中。 C++/CLI 可以使用您的头文件,直接调用 C 函数,并创建 C# 可以像任何 Microsoft 提供的库类一样轻松使用的 .NET 类。如果您的
.a
文件包含 Linux 格式的目标文件,您需要联系提供这些文件的人并要求为 Windows 重新编译代码。If your
.a
files contain Windows-format object files, then you can extract the archive (use the cygwinar
tool for that) and link those into a C++/CLI project. C++/CLI can use your header files, call C functions directly, and create .NET classes which C# can use just as easily as any Microsoft-provided library class.If your
.a
files contain Linux-format object files, you'll need to go back to whoever provided them and ask the code to be recompiled for Windows.