2010-11-16 44 views
1

我想從C DLL中調用一個函數。這個DLL是通過在ubuntu/mingw上編譯創建的。我想在C#中使用這個dll函數。我怎樣才能做到這一點?從C中的mingw的C DLL#

回答

1

您需要使用[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); 
    } 
}