O'Reilly logo

MCAD/MCSD.NET Training Guide (Exam 70-316): Developing and Implementing Windows®-Based Applications with Microsoft® Visual C#™ .NET and Microsoft® Visual Studio® .NET by MCSD Amit Kalani - MCAD

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

Using PInvoke

Instantiate and invoke a Web service or component.

  • Call native functions by using platform invoke.

So far in this chapter, you've seen interoperability between managed code and unmanaged code by way of method calls to classes in COM libraries. There's a second way that the .NET Framework can interoperate with unmanaged code, though: through functional calls to unmanaged libraries. The PInvoke feature of .NET allows .NET code to call functions from unmanaged libraries such as the Windows API.

STEP BY STEP

9.6 Using PInvoke with the Windows API

1.
Add a new form to your Visual C# .NET application.
2.
Place a Label control named lblComputerName on the form.
3.
Switch to the code view. Enter the following using directives:
 using System.Text; ...

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