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; ...

Get MCAD/MCSD.NET Training Guide (Exam 70-316): Developing and Implementing Windows®-Based Applications with Microsoft® Visual C#™ .NET and Microsoft® Visual Studio® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.