Personal advice: You can use static libraries do not use the dynamic library, you can use the implicit call do not use the display call.
Attention:
(1) the. lib file in the dynamic library is called the import library, for the import library, its actual execution code is in the dynamic library, the import library contains only the address symbol table, etc., to ensure that the program finds some basic address information of the corresponding function.
The. Lib in the static library is called the Static Library, which itself contains the actual execution code, symbol table, etc.
(2) The display call must be compiled with extern "C" into C standard, to eliminate the overload of C + +
Static Library: The generated target file will be assembled during the link phase. o The link to the reference library is packaged into an executable file, which is simply considered (a collection of. O or. obj files). (1) The link to the function library is placed in the compile time completed (2) program at runtime and function library is not involved, portability (3) wasted space and resources
Create a static library: Create a Win32 Project-"lib-" Add C + + class-"Add function"
Static double Add (double a,double b);
Call: (1) If the third-party library-"VC + + Directory-" contains the directory, library directory
Linker-"Input-" Additional dependencies
(2) If in the same project-"General properties-" framework and reference-"add a new reference
Dynamic libraries:
(1) Postpone the link loading of library functions to the time of program operation
(2) enables resource sharing between processes (hence also known as shared libraries)
(3) Easy to upgrade some programs
(4) Can really do the link loading is completely controlled by the programmer in the program code (display call)
Dynamic Library creation: (1) Same as static library, then properties-"Configuration Properties-" General-"configuration type
(2) Win32 Project-"DLL
The executable file format under Windows is the PE format, and the dynamic library requires a DllMain function to initialize the portal, usually with the __declspecl (dllexport) keyword
Static __declspec (dllexport) double Add (double a,double b);
Call:
(1) If the third-party library-"VC + + Directory-" contains the directory, library directory
Linker-"Input-" additional dependencies Lib
DLL into the current working directory
(2) If in the same project-"General properties-" framework and reference-"add a new reference
(3) shows that the call is not a function in the class-"VC + + Directory-" contains the directory. h
Add header file typedef double (*add) (double,double) function declaration in. cpp
HINSTANCE stance = LoadLibraryA (".. /.. /dll/staticclassdll.dll ") Load Dll dynamically
Add add = (add) GetProcAddress (stance, "adddllglobal") get function
Double c = Add (10,10) Use function
FreeLibrary (stance) Release handle
(4) Show call if the class function involves overloading, you need to smash the name through the DLL parser and the same call in (3)
AddM AddM = (AddM) GetProcAddress (stance, "[email protected]@@[email protected]");
Example
Dynamic:
#ifdef Xianshidll_exports
#define XIANSHIDLL_API __declspec (dllexport)//for easy writing
#else
#define XIANSHIDLL_API __declspec (dllimport)
#endif
This class is derived from XIANSHIDll.dll.
extern "C" class Xianshidll_api Cxianshidll {//extern "C" in order to display the function in the calling class
Public
Cxianshidll (void);
Double Addxian (double a,double b); The functions in a class involve overloading, which requires a function smash, which can be obtained by using a DLL parser.
};
extern Xianshidll_api int nxianshidll; Interface for exporting variables
Xianshidll_api int fnxianshidll (void); Out-of-class functions can be displayed directly by calling
Windows static Library and dynamic library differences