How to create a dynamic library and use VS2013

The specific steps to create a dynamic library are: (take DLL as an example)

1. Create a win32 project

 2. Select the application type: DLL;

        Additional options: export symbols, tick;

 3. Click Finish to generate a dynamic library

4. Since it is an export library, you need to add a module definition file (.def)

This file is to export the corresponding interface for external calls (detailed explanation can be understood by Baidu)

 5. Write this module custom file:

 According to this interface, the function can be realized;

6. Things to pay attention to when calling a dynamic library:

(1) The calling convention:

The calling convention of the dynamic library: refers to a rule negotiated between the calling program and the dynamic library, which is used to determine the way of passing function parameters, the way of passing return values, the way of maintaining the stack, etc.

The commonly used calling conventions are as follows:

1. cdecl: Function parameters are pushed onto the stack from right to left, and the caller clears the stack space.

2. stdcall: Function parameters are pushed onto the stack from right to left, and the called function clears the stack space.

3. fastcall: The first two parameters of the function are passed through registers, and the remaining parameters are passed through the stack.

4. Vectorcall: The first two parameters of the function are passed through registers, the remaining parameters are passed through the stack, and the return value is also returned through registers.

Different operating systems and compilers may use different calling conventions, so you need to choose the correct calling convention according to the actual situation when using a dynamic library.

 (2) Confirm whether the module definition file is filled in the dynamic library

Once someone called the dynamic library and said that the interface name was wrong. Later, I will look at the original project and fill in the module customization file.

If you want to view the interface name of the current dynamic library, you can use the software Depends.exe to view it.

Guess you like

Origin blog.csdn.net/bigger_belief/article/details/131230952
Recommended