C # basic knowledge 4: dll-related

Source: Internet
Author: User

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 );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.