Simple Application and learning of Dynamic Link Library

Source: Internet
Author: User

Curiosity is completely curiosity. Let me start to look at the story behind the software in DLL (dynamic link library knowledge!

Simple application:

Create a jisuan. h file.Code

 1   Extern   "  C  " _ Declspec (dllexport) Int Add ( Int I, Int J );
2 Extern " C " _ Declspec (dllexport) Int Sub ( Int I, Int J );
3 Extern " C " _ Declspec (dllexport) Int Mull ( Int I, Int J );
4 Extern " C " _ Declspec (dllexport) Float Divv ( Int I, Int J );

They define functions for addition, subtraction, multiplication, division, and division!

Create a jisuan. cpp file and enter the code.

 1 # Include "  Jisuan. h  " 
2 Int Add ( Int I, Int J)
3 {
4 Return I + J;
5 }
6 Int Sub ( Int I, Int J)
7 {
8 Return I-j;
9 }
10 Int Mull ( Int I, Int J)
11 {
12 Return I * J;
13 }
14 Float Divv ( Int I, Int J)
15 {
16 Return I /( Float ) J;
17 }

The four arithmetic operations are defined here

The two files compiled by VC in the debug file areProgramThe fruit of Compilation:

So how can we use them?

The following is a calculator tool:

It is designed in the form of an MFC dialog box and two variables are added to the edit box: M_a, m_ B;

Then add the click events for the buttons respectively: (the sum is listed)

 1   Void Cdllusingdlg: onbtnadd ()
2 {
3 // Todo: add your control notification handler code here
4 Updatedata (true );
5 Cstring STR;
6 Int He = add (M_a, m_ B );
7 Str. Format ( " The sum of % d and % d is % d! " , M_a, m_ B, He );
8 Afxmessagebox (STR );
9
10
11 }

 

The result is ..........

Five errors, so familiar! Yes. When there is no connected library, it is him! Haha, we just used the functions in a whimsical way, but didn't tell the program where to find them?

I have used iostream. h to know that the need to include "iostream. H" is the same!

Next step:

1. Put the DLL file under the project folder, and put the Lib file under debug.

2. In VC, enter the Lib name in project ---> setting ----> connection!

3. # include "youdll. h"

4. Run

No problem! It is as convenient as cout <"SS" <Endl!

Here, I will write down what I learned and share it with you:

Lib is required during compilation and DLL is required during runtime.

Complete the EXE in two steps in VC!

1. Compile: to completeSource codeIs Lib!

2. Connection: If dynamic connection is also enabled, use DLL.
So it can be used!

This method is well-known: dynamic connection!

 

 

"In the case of a dynamic library, there are two files, one being imported into the database (. lib) file. One is a DLL file. The imported file contains the name and location of the function exported by the DLL. The dll contains the actual function and data, the application uses the Lib file to link to the required DLL file. The functions and data in the library are not copied to the executable file. Therefore, in the executable file of the application, stores not the called function code, but the memory address of the function to be called in the DLL, in this way, when one or more applications are running, the program code is linked to the called function code, thus saving memory resources. From the above description, we can see that the DLL and. Lib files must be released along with the application, otherwise the application will produce errors ." ------- Said Daniel!

Import to database is not used in the program. It stores the address symbol table for function execution, just to ensure that the required function can be accurately found during function execution! The real body of the function to be executed is in the DLL!

"The static library itself contains the actual execution code, symbol table, and so on.ForIn the import/export operations, the actual execution code is in the dynamic library, and the import/export operations only contain the address symbol table, so that the program finds some basic address information of the corresponding function.."---------- Said Daniel!

Okay, this is the link library I know!

In fact, DLL is used in many places, such as various API functions (including windows)

I reprinted it.

"

A dynamic link library (DLL) is an executable file used as a shared function library. Dynamic links provide a way for a process to call a function that does not belong to its executable code. The executable code of a function is located in a DLL, which contains one or more functions that have been compiled, linked, and stored separately from the processes that use them. DLL also helps to share data and resources. Multiple applications can simultaneously access the content of a single DLL copy in the memory.
the difference between a dynamic link and a static link is that it allows the executable module (. DLL file or. EXE file) only contains the information required to locate the executable code of the DLL function at runtime. In a static link, the linker obtains all referenced functions from the static Link Library and puts the library together with the code into the executable file.
using dynamic links instead of static links has several advantages. DLL saves memory, reduces swap operations, saves disk space, makes it easier to upgrade, provides after-sales support, and extends the MFC Library Class mechanism to support multi-language programs, and make it easy to create international versions.

An API is an application programming interface. It is a group of functions that can be used to operate components, applications, or operating systems. In typical cases, an API is composed of one or more DLL that provides certain special functions.
DLL is a file, which is contained in Microsoft? Windows? Function that can be called by any application running under. During runtime, the functions in the DLL are dynamically linked to the application that calls it. No matter how many applications call a function in the DLL, only one file on the disk contains the function and the DLL is created only when it is transferred to the memory.
The most frequently-heard API may be a Windows API, which includes various DLL that constitute the Windows operating system. Every windows application interacts directly or indirectly with Windows APIs. Windows API ensures that all applications running in Windows behave in the same way.

"

We recommend two blogs: 1. http://www.cnblogs.com/strinkbug/archive/2007/04/24/725050.html

2. http://www.cnblogs.com/chio/archive/2008/08/05/1261296.html

Calm down and take a look. learning and learning can help you better understand and improve efficiency!

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.