Use def to export a function from the DLL, or use the _ declspec (dllexport) command to export a class from the DLL, which is familiar to everyone and often used. Here we will introduce
Use the def file to export a class from the DLL. The specific principle or why is it not nonsense? Learn How to export and try again. The procedure is described here.
1. Open vc6.0 and create a "Win32 dynamic-Link Library" project. For example, defclass. On the "DLL kind" Page, select "A simple DLL project"
2.Create a new file named defclass. Def. Enter the following content and add it to the project.
Library defclass
Exports
3.Add a class cmath to the project and add an add method to make it look as follows:
Class cmath
{
Public:
Int add (int A, in B );
Cmath ();
Virtual ~ Cmath ();
};
How do you decide its implementation? When I do the example, add returns return A + B;
4.Open the settings page of the project, select link, and selectGenerate mapfile.
5.Rebuild all project.
6.Open the *. Map File of debug or release in VC (If your project name is defclass, It is delclass. MAP ).
7.Find math. OBJ, for example:
0001: 00000080 ?? 0cmath @ Qae @ xz 10001080 F math. OBJ
0001: 000000c0 ?? _ Ecmath @ uaepaxi @ Z 100010c0 f I math. OBJ
0001: 000000c0 ?? _ Gcmath @ uaepaxi @ Z 100010c0 f I math. OBJ
000:00000130 ?? 1cmath @ UAE @ xz 10001130 F math. OBJ
0001: 00000170? Add @ cmath @ qaehhh @ Z 10001170 F math. OBJ
8.Copy the 2nd columns of lines and 5 to the defclass. Def file to make it look like the following (the serial number is specified by yourself)
Library defclass
Exports
?? 0cmath @ Qae @ xz@ 1
?? 1cmath @ UAE @ xz@ 2
? Add @ cmath @ qaehhh @ Z@ 3
9.Save all the files and run rebuild all.
If everything is normal, the classes in your DLL have been exported by serial number. Then, add the function to cmath. Find the Function Identifier from the map file and add
, Assign a sequence number to it. As long as the previous export sequence number remains unchanged and the DLL generated by the new compilation replaces the previous DLL, the previous client program can still run normally.
How to Use the generated DLL?
You can set "math. H "and" defclass. lib "copy to the project directory of the customer program and put" defclass. DLL "is copied to the output directory of the Client Program (debug/release. Add the defclass. Lib reference to # include "math. H" in the client program settings.
Cmath math;
Int nret = math. Add (2, 3 );