在 .NET 的 *.a 库中使用 C 函数

发布于 2024-12-29 13:24:38 字数 420 浏览 4 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(1

望笑 2025-01-05 13:24:38

如果您的 .a 文件包含 Windows 格式的目标文件,那么您可以提取存档(使用 cygwin ar 工具)并将其链接到 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 cygwin ar 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.

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