The process of executing native code from within a .NET assembly is called platform invoke, or pinvoke for short. You use platform invoke to call the Win32 API directly, to access existing (legacy) DLLs your company uses, or to access procedures compiled to native code for performance reasons. To use platform invoke, follow these steps:
Import the System.Runtime.InteropServices namespace.
Declare the unmanaged procedure using the DllImport attribute or the Declare statement.
Map the data types of the procedures parameters to the equivalent .NET types.
Call the unmanaged procedure and test its return value for success.
If the procedure did not succeed, retrieve and handle the exception code using the Marshal object’s GetLastWin32Error method.