Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
5 out of 10 rated this helpful - Rate this topic

Platform Invoke Examples 

The following examples demonstrate how to define and call the MessageBox function in User32.dll, passing a simple string as an argument. In the examples, the DllImportAttribute.CharSet Field field is set to Auto to let the target platform determine the character width and string marshaling.

The same example appears in Visual Basic, C#, and C++. To show all examples, click the Language Filter button in the upper-left corner of the page. For additional examples, see Marshaling Data with Platform Invoke.

using System.Runtime.InteropServices;

public class Win32 {
     [DllImport("user32.dll", CharSet=CharSet.Auto)]
     public static extern IntPtr MessageBox(int hWnd, String text, 
                     String caption, uint type);
}

public class HelloWorld {
    public static void Main() {
       Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
    }
}      

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.