Using Platform Invoke
Access unmanaged code from a Windows service, a serviced component, a .NET Remoting object, and an XML Web service.
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: by calling methods from unmanaged libraries. The Platform Invoke (often abbreviated as PInvoke) feature of .NET allows .NET code to call methods from unmanaged libraries such as the Windows API.
To call unmanaged methods from your .NET code, you need to provide the declarations of the method in your .NET code. Because the methods are implemented externally in unmanaged libraries, ...
Get MCAD/MCSD Training Guide (70-320): Developing XML Web Services and Server Components with Visual C#™ .NET and the Microsoft .NET Framework 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.