是否可以使用DllImport使用其他操作系统的库? [英] Is it able to use Other OS's Library by DllImport?

查看:98
本文介绍了是否可以使用DllImport使用其他操作系统的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道DllImport()属性会加载Windows DLL文件的功能.

但是,当我查看"Tao Framework"的源代码时,发现以下行:

GLExtensionLoader.cs-Tao框架的一部分.

//linux
[DllImport("libGL.so",EntryPoint ="glXGetProcAddress")]
内部静态外部IntPtr glxGetProcAddress(string s);

对于我们的ARB-y朋友,

//也是Linux
[DllImport("libGL.so",EntryPoint ="glXGetProcAddressARB")]
内部静态外部IntPtr glxGetProcAddressB( >

//Windows
[DllImport("opengl32.dll",EntryPoint ="wglGetProcAddress")]
内部静态外部IntPtr wglGetProcAddress(string s);

//Mac osx变得复杂
[DllImport("libdl.dylib",EntryPoint ="NSIsSymbolNameDefined")] ; libdl.dylib,EntryPoint =" NSLookupAndBindSymbol)]
内部静态外部IntPtr NSLookupAndBindSymbol(string s); >内部静态外部IntPtr NSAddressOfSymbol(IntPtr symbol);

//为此,我们不能依赖Tao.OpenGl.Gl

[DllImport("opengl32.dll")]
内部静态外部IntPtr glGetString(uint名称);


DllImport()属性可以处理其他OS的库吗? (例如"xxxxx.so"或"xxxxx.dylib")

如果是,是否表示我可以在Windows上使用其他操作系统的库功能?
(或Windows的功能) DLL可以通过使用DllImport属性在Mac或Linux上运行吗?)

解决方案

AFAIK DllImport(),对于MS .Net Framework,无法解释非Windows DLL(或任何非PE模块).它主要是用于LoadLibrary()和GetProcAddr()的糖,它们都不适用于非Windows DLL.即使幸运的是,如果lib具有相同的格式,它也可能会引用Windows上不存在(或名称不同)的库.


I've known DllImport() Attribute loads the functions of just Windows DLL Files.

But, When I look the source of "Tao Framework", I found this lines:

GLExtensionLoader.cs -- a part of Tao Framework.

// linux
        [DllImport("libGL.so", EntryPoint = "glXGetProcAddress")]
        internal static extern IntPtr glxGetProcAddress(string s);

        // also linux, for our ARB-y friends
        [DllImport("libGL.so", EntryPoint = "glXGetProcAddressARB")]
        internal static extern IntPtr glxGetProcAddressARB(string s);

        // windows
        [DllImport("opengl32.dll", EntryPoint = "wglGetProcAddress")]
        internal static extern IntPtr wglGetProcAddress(string s);

        // Mac osx gets complicated
        [DllImport("libdl.dylib", EntryPoint = "NSIsSymbolNameDefined")]
        internal static extern bool NSIsSymbolNameDefined(string s);
        [DllImport("libdl.dylib", EntryPoint = "NSLookupAndBindSymbol")]
        internal static extern IntPtr NSLookupAndBindSymbol(string s);
        [DllImport("libdl.dylib", EntryPoint = "NSAddressOfSymbol")]
        internal static extern IntPtr NSAddressOfSymbol(IntPtr symbol);

        // we can't depend on Tao.OpenGl.Gl for this

        [DllImport("opengl32.dll")]
        internal static extern IntPtr glGetString(uint name);


Can DllImport() Attribute deal Other OS's Library? (like "xxxxx.so" or "xxxxx.dylib")

If so, Does it mean that I can use the function of Other OS's library on Windows?
(Or the function of Windows DLL can be runnable on Mac or Linux by using DllImport Attribute?)

解决方案

AFAIK DllImport(), for the MS .Net Framework, can't interpret non-windows DLLs (or any non-PE module).  It's mostly sugar for LoadLibrary() and GetProcAddr() neither of which will work with non-windows DLLs.  Even, if by luck the lib had the same format it would probably reference libraries that don't exist (or have different names) on windows.


这篇关于是否可以使用DllImport使用其他操作系统的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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