O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Platform Invoke Overview

A large investment has been made in ensuring that unmanaged code is a full participant. For most cases, it is simple to seamlessly interoperate with legacy code. Listings 7.1 through 7.4 show how to interoperate with MessageBox in some of the languages that are supported under the .NET Framework.

Listing 7.1 shows how to set up a call to the legacy code in the user32.dll from C#.

Listing 7.1. Message Box Interaction from C#
 using System; using System.Runtime.InteropServices; public class Win32 { [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int MessageBox(int hWnd, String text, String caption, uint type); } public class HelloWorld { public static void Main() { Win32.MessageBox(0, "Hello World", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required