Platform Invoke

Platform Invoke is a service provided by .NET that allows you to call functions inside of unmanaged code directly from managed code. Unmanaged code is any code that is not running under the service of the Common Language Runtime (CLR). The entire Win32 API is unmanaged code because it predates .NET. Managed code is code that executes under, and conforms to, the confines of the CLR. As you might imagine, there is a boundary between code that is managed and code that exists outside of the CLR. To cross this boundary you must rely on the services of Platform Invoke.

Platform Invoke provides a number of services to your managed code. First, it locates an unmanaged function on the machine and inside a Windows' DLL. Next, it invokes ...

Get Visual Basic® Programmer's Guide to the .NET Framework Class Library 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.