Praveen Katiyar' Blog

Learning along the way . . . .

Interoperability with Winodws API (1 of N)

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


July 26, 2013 - Posted by | .NET, CodeProject, Interoperability, Marshaling, Win32 | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: