Platform Invoke - C#
A platform invoke call to an unmanaged DLL function
- Locates the DLL containing the function.
- Loads the DLL into memory.
- Locates the address of the function in memory and pushes its arguments onto the stack, marshaling data as required.
Note Locating and loading the DLL, and locating the address of the function in memory occur only on the first call to the function.
- Transfers control to the unmanaged function.
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text,
String caption, uint type);
}
public class HelloWorld {
public static void Main() {
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
}
}
No comments:
Post a Comment