Review writing DLLs in C++

The project template uses the dll project created by the Win32 project

1. Original code

Use depends to view exported functions

Second, the difference between different compilation methods

Compile in C mode (extern "C"):

  1. __stdcall calling convention: the output name is preceded by an underscore, followed by an "@" and the total number of bytes of its parameters (_original name@parameter total number of bytes), such as the name int Func_C_stdcall(int a,int b) The output is _Func_C_stdcall@8;
  2. __cdecl calling convention: the same as the original name, such as the name int Func_C_cdecl(int a, int b), the output is still Func_C_cdecl;

Compile in C++ mode (extern "C++"):

__stdcall calling convention:

  1. The output name starts with "?" followed by the original name;
  2. The original name is followed by "@@YG", followed by the code of the return value and the code of the parameter table. The codes are as follows:
    X--void ,
    D--char,
    E--unsigned char,
    F--short,
    H-- int,
    I--unsigned int,
    J--long,
    K--unsigned long,
    M--float,
    N--double,
    _N--bool,
    ...
    PA--represents a pointer, and the following code indicates the pointer type, If pointers of the same type appear consecutively, replace them with "0", and a "0" represents a repetition;
  3. The parameter list ends with "@Z" to identify the entire name, or "Z" if the function has no parameters. For example, the compiled output name of the name int Func_CPP_stdcall(int a,int b) is ?Func_CPP_stdcall@@YGHHH@Z.

__cdecl calling convention: It is basically the same as the _stdcall calling convention, except that the start identifier of the parameter table is changed from "@@YG" above to "@@YA". For example, the name int Func_CPP_cdecl(int a,int b) is compiled and the output name is ?Func_CPP_cdecl@@YAHHH@Z.
To compile C files and CPP files, there is no need to add extern "C" and extern "C++", because of course, extern "C" is the default for compiling C files, and extern "C++" is the default for compiling CPP files.

The second part is transferred from: https://blog.csdn.net/beanjoy/article/details/9136127

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325052791&siteId=291194637