Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of PInvoke from Linux with .NET Core
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);
}
}
}
@wiwichu

This comment has been minimized.

Show comment
Hide comment
@wiwichu

wiwichu Jul 25, 2016

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.

wiwichu commented Jul 25, 2016

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.

@ms0713

This comment has been minimized.

Show comment
Hide comment
@ms0713

ms0713 Jan 4, 2018

@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);
    }
}

}`

ms0713 commented Jan 4, 2018

@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