.net core 中的 P-Invoke 与 Linux [英] P-Invoke in .net core with Linux

查看:11
本文介绍了.net core 中的 P-Invoke 与 Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Linux 上的 .NET Core 中实现 P/Invoke (dllimport)?

Is there way to implement P/Invoke (dllimport) in .NET Core on Linux ?

示例:

我使用 .net 框架编译了 C++ MyLib.dll.

I have C++ MyLib.dll compiled with .net framework.

是否可以这样使用,或者不支持使用 .net-core 在 linux 上调用本机 win api?

If it is possible to use like this or it's not support to call native win api with linux using .net-core ?

[DllImport("MyLib.dll", CallingConvention = CallingConvention.StdCall)]
internal static extern long NativeMethod();

推荐答案

PInvoke 肯定受支持(这就是与操作系统交互的所有代码的工作方式),但不适用于您列出的特定情况.你不能在 Linux 上 PInvoke 到一个 win32 二进制文件,除非你自己以某种方式为 Linux 构建了一个功能兼容的版本.更现实的是,您需要从其他一些系统二进制文件中找到一个公开类似功能的 Linux 函数,然后改用它.

PInvoke is certainly supported (that is how all of the code that interfaces with the OS works), but not in the specific case you listed. You cannot PInvoke to a win32 binary on Linux, unless you have somehow built a function-compatible version of it for Linux yourself. More realistically, you need to find a Linux function from some other system binary which exposes similar functionality, and then use that instead.

这篇关于.net core 中的 P-Invoke 与 Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆