Created
September 8, 2019 16:04
-
-
Save wolfspider/f575cd085d96693e03f2e8025d0c2e57 to your computer and use it in GitHub Desktop.
Test to see if interop is working on dotnet core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Security; | |
| using System.Runtime.InteropServices; | |
| namespace consoletest | |
| { | |
| class Program | |
| { | |
| [DllImport("libc")] | |
| static extern int uname(IntPtr buf); | |
| [SuppressUnmanagedCodeSecurity] | |
| [DllImport("/usr/lib/libdl.so")] | |
| static extern IntPtr dlopen(string filename, int flags); | |
| [DllImport("/usr/lib/libdl.so")] | |
| static extern IntPtr dlerror(); | |
| [DllImport("/usr/lib/libdl.so")] | |
| static extern IntPtr dlsym(IntPtr handle, String symbol); | |
| static string GetUname() | |
| { | |
| var buffer = Marshal.AllocHGlobal(8192); | |
| try | |
| { | |
| if (uname(buffer) == 0) | |
| { | |
| return Marshal.PtrToStringAnsi(buffer); | |
| } | |
| return string.Empty; | |
| } | |
| catch | |
| { | |
| return string.Empty; | |
| } | |
| finally | |
| { | |
| if (buffer != IntPtr.Zero) | |
| { | |
| Marshal.FreeHGlobal(buffer); | |
| } | |
| } | |
| } | |
| static void Main(string[] args) | |
| { | |
| Console.WriteLine("Hello World! from: " + GetUname()); | |
| var ret = dlopen("/usr/local/lib/libpng.so", 2); | |
| if (ret == IntPtr.Zero) | |
| { | |
| var errorMsg = Marshal.PtrToStringAnsi(dlerror()); | |
| Console.WriteLine(errorMsg); | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FreeBSD 11.3
Runtime Environment:
OS Name: FreeBSD
OS Version: 11
OS Platform: FreeBSD
RID: freebsd.11-x64
Base Path: /usr/local/share/dotnet/sdk/3.0.100-preview-010021/