2010-11-16 4 views
1

Je veux appeler une fonction d'un dll C. Cette DLL a été créée en compilant sur ubuntu/mingw. Je veux utiliser cette fonction dll en C#. Comment puis-je faire ceci?C dll de mingw en C#

Répondre

1

Vous devez définir une signature gérée à l'aide de l'attribut [DllImport], puis P/Invoke dans la bibliothèque non gérée. Exemple de MSDN appelant la fonction MessageBox de user32.dll:

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); 
    } 
} 
Questions connexes