使用Linux在.net核心中进行P调用 [英] P-Invoke in .net core with 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.
这篇关于使用Linux在.net核心中进行P调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!