P/Invoke is an implementation specification created by Microsoft of the Common Language Infrastructure (CLI) for invocation of native code libraries from managed code.
P/Invoke stands for Platform Invocation Services. It is a specification created by Microsoft in order to provide interoperability with unmanaged code from managed applications. Data passed to/from P/Invoke should usually be converted to/from CLI types before it can be used. This process is called marshalling.
The wiki website for P/Invoke method declarations is pinvoke.net.
The base namespace in .NET Framework is System.Runtime.InteropServices.
Sample code in C# of a class using P/Invoke (from pinvoke.net):
class Beeper
{
public enum beepType
{
SimpleBeep = -1,
OK = 0x00,
Question = 0x20,
Exclamation = 0x30,
Asterisk = 0x40,
}
[DllImport("User32.dll", ExactSpelling=true)]
private static extern bool MessageBeep(uint type);
static void Main(string[] args)
{
Class1.beep(beepType.Asterisk);
Thread.Sleep(1000);
Class1.beep(beepType.Exclamation);
Thread.Sleep(1000);
Class1.beep(beepType.OK);
Thread.Sleep(1000);
Class1.beep(beepType.Question);
Thread.Sleep(1000);
Class1.beep(beepType.SimpleBeep);
}
public static void beep(beepType type)
{
MessageBeep((uint)type);
}
}