Dll, dynamic link library.
Two concepts are distinguished here,
One is a traditional dynamic link library, which is also well known, such as kerneral under system32. dll, user32.dll. This dll is compiled from a dll written in c or c ++ to a binary file that is already a machine code. It provides encapsulated function interfaces. This dll can be called in almost all languages.
C # introduces a dll, which is a class library that can be created in.
Although such dll is compiled in binary format, it is just the intermediate code format of c #, which is different from the traditional dll. It can only be used by c #. It is only a class library.
C # is not required to call the second dll. It is very simple and can be introduced after being copied to the code.
Here we mainly talk about c # How to call the first traditional dll, such as windows api.
Declare an extern function to host a function in an external dll. If you want to call the msgbox of win32
[Csharp]
/*
* Author: Shu
* E_mail: shushenghong@gmail.com
* Time: 10/24/2012 10:19:48 AM
*/
Using System;
Using System. Runtime. InteropServices;
/// <Summary>
/// Win32 alert
/// </Summary>
Public class Alert
{
[DllImport ("user32.dll", EntryPoint = "MessageBox", CharSet = CharSet. Unicode)]
Private static extern int DllMsgBox (int hwnd, string content, string title, uint type );
/// <Summary>
/// Win32 message box
/// </Summary>
Public static void MsgBox (string content, string title)
{
DllMsgBox (0, content, title, 64 );
}
}