In this article I will explain, how one can call windows API, from managed world. let’s define the signatures of windows API for managed world.
Calling a Win32 MessageBox function from Managed Word
//****************************
// MyProgram.cs
namespace MyManagedProgram { //1
class Program { // 2
static void Main(string[] args) { //3
Win32DllWrapper.MsgBox(0, "This Text has been sent from Managed World", "Win32 Messsage Box", 0);
} //3
} //2
///defining the helper class
///define a helper class which will contain a functions for
public class Win32DllWrapper { //4
// Standard Functions from Windows API.
[DllImport("User32.dll", EntryPoint = "MessageBox", CharSet = CharSet.Auto)]
public static extern int MsgBox(int hWnd, String text, String caption, uint type);
} //4
} // 1
compile and execute