10/04/08 15:18
Dax89
Per usare delle funzioni scritte in C, in .NET esiste il 'Platform Invoke, che permette di utilizzare le funzioni esportate da una DLL.
Questo esempio permette di utilizzare l'API MessageBox che sta nella DLL 'user32.dll'
using System;
using System.Runtime.InteropServices;
namespace PInvoke
{
class MainClass
{
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
public static extern int MessageBox(IntPtr hWnd, string text, string caption, int style);
public static void Main()
{
MessageBox(0, "Testo", "Titolo", 0);
}
}
}
Ultima modifica effettuata da Dax89 10/04/08 15:22
aaa
10/04/08 18:14
Dark_Limit
Ciao..potresti alternativamente aggiungere un riferimento al progetto..
aaa
11/04/08 17:15
Dax89
Da errore perchè 'pcap_t' non esiste. in C#, Se è una struttura la devi riscrivere esattamente a come la trovi nel file *.h C++ in cui è presente, ad esempio:
La struttura Point, in C++ è definita così:
struct Point
{
DWORD x;
DWORD y;
};
Ora, supponendo che nel .NET Framework questa struttura non esista, la dovremmo scrivere noi per poterla usare e facciamo:
public struct Point
{
int x;
int y;
}
Permettendoci così di usarla.
La stessa cosa va fatta con la struttura che vuoi usare.
Se invece non è una struttura, dovresti darmi più informazioni a riguardo. ^^
Un altra cosa:
Siccome la funzione restituisce un puntatore, al posto del puntatore si mette IntPtr, che rappresenta un indirizzo.
Ultima modifica effettuata da Dax89 11/04/08 17:21
aaa