Created
June 28, 2016 09:32
-
-
Save martinwoodward/f5b195aa53b4ed52cabaf701486baa79 to your computer and use it in GitHub Desktop.
Example of PInvoke from Linux with .NET 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.Runtime.InteropServices; | |
namespace PInvokeSamples { | |
public static class Program { | |
// Import the libc and define the method corresponding to the native function. | |
[DllImport("libc.so.6")] | |
private static extern int getpid(); | |
public static void Main(string[] args){ | |
// Invoke the function and get the process ID. | |
int pid = getpid(); | |
Console.WriteLine(pid); | |
} | |
} | |
} |
@martinwoodward What is the alternative for following code:
This code i m using in Windows. I want alternate code for Linux(RHEL7).
`using System.Runtime.InteropServices;
namespace PInvokeSamples {
public static class Program {
// Import the kernel32.dll and define the method corresponding to the native function.
[DllImport("kernel32.dll")]
private static extern uint GetCurrentThreadId();
public static void Main(string[] args){
// Invoke the function and get the process Thread ID.
uint tid = GetCurrentThreadId();
Console.WriteLine(tid);
}
}
}`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I call a c++ library I created from asp.net core in windows? I get a BadImageFormatException. In RC1 I was able to do it, but am not sure where to place the dll in asp.net core.