[Dllimport ("dynamic database name")]
Public static extern Return Value Type Function Name (parameter );
In this way, you can call
All APIs are implemented in the following three DLL files.
Kernel
User
GDI
1. Kernel
Its database name is kernel32.dll, which is an API set managed by the operating system
Process loading. Load the process
Context switching.
File I/O. File Operations
Memory Management. Memory Management
For example, the globalmemorystatus function obtains the usage information of the Physical Virtual Memory of the system.
2. User
In Win32, its database name is user32.dll
This allows managing the entire user interfaces such
It manages all user interfaces, such:
Windows
Menus menu
Dialog Boxes dialog box
Icons Etc., icons, etc.
For example, drawicon draws an icon on a specified device.
3. GDI (graphical device interface)
This dll is gdi32.dll, which is responsible for the output of images. It uses GDI to draw windows, menus, and dialog boxes.
It can create graphical output. output image
For example, the createbitmap function creates a bitmap with the specified width, height, and color format.
Add a namespace for using external libraries:
Using system. runtime. interopservices;
The following API Declaration
[Dllimport ("user32.dll")]
The dllimport attribute is used to specify the location of the dynamic connection library containing external methods. "User32.dll" indicates the Database Name and static indicates that it is not a specific object. Extern indicates an external method. Methods With the dllimport attribute must have the modifier extern.
MessageBox is a Chinese number and contains four parameters to return an int value.
Many APIs use structures to pass and return parameters, which can reduce complexity. It also allows fixed parameters like the MessageBox function.
Add the following to the button clicking event:Code:
Protected void button#click (Object sender, system. eventargs E)
{
MessageBox (0, "API message box", "API Demo", 0 );
}