1
我想从C DLL中调用一个函数。这个DLL是通过在ubuntu/mingw上编译创建的。我想在C#中使用这个dll函数。我怎样才能做到这一点?从C中的mingw的C DLL#
我想从C DLL中调用一个函数。这个DLL是通过在ubuntu/mingw上编译创建的。我想在C#中使用这个dll函数。我怎样才能做到这一点?从C中的mingw的C DLL#
您需要使用[DllImport]
属性,然后将P/Invoke定义到非托管库中来定义托管签名。从MSDN来自实例user32.dll
调用MessageBox功能:
using System;
using System.Runtime.InteropServices;
class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}