13.1. Call a Function in an Unmanaged DLL
You need to call a function in a DLL. This function might be part of the Win32 API or your own legacy code.
Declare a method in your VB .NET code that you will use to access the unmanaged function. Declare this method as Shared, and apply the attribute System.Runtime.InteropServices.DllImportAttribute to specify the DLL file and the name of the unmanaged function.
How It Works
To use a function from an external library (such as one written in C or C++), all you need to do is declare it appropriately. The CLR automatically handles the rest, including loading the DLL into memory when the function is called and marshaling the parameters from .NET data types to C data types (or the data ...