Dynamic library display and implicit calling and static library calling in Windows

Source: Internet
Author: User

Create a dynamic library:

1. Create a Win32 project in VC. For example, the project name is mytestdll. Select DLL and empty project. Then, confirm that an empty DLL project is created;

2. Add header files, source files, and Def files. The reason for using def files is that for functions in C ++, the compiler will generate different names of the original functions, using the def file can directly avoid this problem, and you do not need to define the modifiers _ declspec (dllexport) and _ declspec (dllimport.

 

Define the functions to be included in the DLL, for example:

Int add (int A, int B)

{

Return A + B;

}

In the def file, add the name of the function to be exported in the following format:

Then compile the project and generate the mytestdll. dll and mytestdll. Lib files.

 

For dynamic library display calling, you can directly use a DLL file during compilation and then loadlibrary in the program.

For implicit calls, header files, DLL files, and Lib files must be included at the same time during compilation, and preprocessing commands must be used like calling static libraries.

# Pragma comment (Lib, "libname ")

 

Static Library Creation is very simple. In the call project, during compilation, only the header file and Lib file are required, and the preceding pre-processing commands are also required. Note, "libname" can be included or not ". lib.

 

For a dynamic library, a DLL file is required during runtime, regardless of whether the project is implicitly or explicitly used during compilation. For a static library, the static library file does not need to be referenced during runtime.

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.