What are the steps to follow to use Platform Invoke?

Q

Managed Code and Unmanaged Code related ASP.NET - What are the steps to follow to use Platform Invoke?

✍: Guest

A

To use platform invoke, follow the following steps:
1. Import the System.Runtime.InteropServices namespace.
2. Declare the unmanaged procedure using the DllImport attribute or the Declare statement.
3. Map the data types of the procedures parameters to the equivalent .NET types.
4. Call the unmanaged procedure and test its return value for success.
5. If the procedure did not succeed, retrieve and handle the exception code using the Marshal object’s GetLastWin32Error method.

2009-03-31, 4511👍, 0💬