: (this article is about ZZ rivershan ))
There are two types of conventions for the dynamic library output function: The call convention and the name modification convention.
1) Call Convention (calling convention): determines the order in which function parameters are transferred to and from the stack. The caller or t
: The thread is stopped;
LpReserved: a parameter reserved by the system;
2. _ DLLMainCRTStartup
To use the DLL version (multithreading) of the "C" Runtime Library (CRT, C Run time Library), a DLL application must specify _ DLLMainCRTStartup as the entry function, the DLL initialization function must be DLLMain.
_ DLLMainCRTStartup: Data (C Runtime Data) of the "C" Runtime when the process or thread is bound to the DLL) allocate space and initialize and construct a global "C ++" object. When the
. Explains the cause of status management.
There are two kinds of conventions about the dynamic library output function: The call convention and the name modification convention. 1) Call Convention (calling convention): determines the order in which function parameters are transferred to and from the stack. The caller
. If _ stdcall is used, the above problem is solved, and the function solves the clearing work by itself. Therefore, in cross-platform (Development) calls, we use _ stdcall (although sometimes it appears as winapi ). So why do we still need _ cdecl? When the parameters of such a function, such as fprintf (), are variable and variable, the caller cannot know the length of the parameter in advance, and the cleanup operation afterwards cannot proceed normally, therefore, we can only use _ cdecl in
;Dll_thread_attach: The thread is called;Dll_process_detach: the process is stopped;Dll_thread_detach: The thread is stopped;Lpreserved: a parameter reserved by the system.
2. _ dllmaincrtstartup
To use the dll version (multithreading) of the "c" Runtime Library (CRT, C run time Library), a DLL application must specify _ dllmaincrtstartup as the entry function, the DLL initialization function must be dllmain.
_ Dllmaincrtstartup: Data (C Runtime data) of the "c" RunTime when the process or
Left through the stack, the called function cleans up the memory stack of the transfer parameters before returning, but the modified portion of the function name (the cosmetic portion of the function name is described later in detail).
_stdcall is the default calling method of Pascal program, usually used in the Win32 API, the function uses a right to left stack way, its own on the exit empty stack. VC compiles the function with an underscore prefix in front of the function name, plus the "@" a
name modifier generated by the compiler. The following uses vc5 and vb5 as examples to describe how to implement these requirements.
(1) Call conventions there are multiple function call conventions supported by VC ++ 5.0. Here we only discuss the following three types: __stdcall, C, and _ fastcall. the _ stdcall call convention is equivalent to the Pascal call convention that is frequently used in 16-b
is required when the DLL application dynamically links to the mfc dll, but it is statically linked to the DLL application. Explains the cause of status management.Iv. Conventions:There are two types of conventions for the dynamic library output function: The call convention and the name modification convention.1) Call Convention (calling
, the stack top pointer is also modified. You can also remove the top stack from the stack, which is called pop. After the stack pops up, an element at the top of the stack changes to the top of the stack, and the top pointer of the stack changes accordingly.
When a function is called, the caller pushes the parameter to the stack in sequence and then calls the function. After the function is called, the caller obtains data in the stack for calculation. After function compute is completed, the
the invocation and execution of functions, so let's take a look at the following code through an example of a set of function calls:
123456789101112131415161718
intfoo1(intm, int n){intp=m*n;returnp;}intfoo(inta, intb){intc=a+1;intd=b+1;inte=foo1(c,d);returne;}intmain(){intresult=foo(3,4);return0;}
The code itself doesn't really make sense, we just use it to track the stack. The following chapters let us track the build of stacks, the use of stacks, and the destruction
following code through an example of a set of function calls:
123456789101112131415161718
intfoo1(intm, intn){int p=m*n;returnp;}intfoo(inta, intb){intc=a+1;intd=b+1;inte=foo1(c,d);returne;}intmain(){intresult=foo(3,4);return0;}
The code itself doesn't really make sense, we just use it to track the stack. The following chapters let us track the build of stacks, the use of stacks, and the destruction of stacks.the creation of stacksThe first line of code that we execute
;Dll_thread_detach: The thread is stopped;
Lpreserved: a parameter reserved by the system;
2. _ dllmaincrtstartup
To use the dll version (multithreading) of the "c" Runtime Library (CRT, C run time Library), a DLL application must specify _ dllmaincrtstartup as the entry function, the DLL initialization function must be dllmain._ Dllmaincrtstartup: Data (C Runtime data) of the "c" RunTime when the process or thread is bound to the DLL) allocate space and initialize and construct a global "C ++"
process is stopped;Dll_thread_detach: The thread is stopped;
Lpreserved: a parameter reserved by the system;
2. _ dllmaincrtstartup
To use the dll version (multithreading) of the "c" Runtime Library (CRT, C run time Library), a DLL application must specify _ dllmaincrtstartup as the entry function, the DLL initialization function must be dllmain._ Dllmaincrtstartup: Data (C Runtime data) of the "c" RunTime when the process or thread is bound to the DLL) allocate space and initialize and co
Call conventions (Calling convention) RefersProgramA protocol established to implement function calls in the design language. This Protocol specifies the parameter transfer mode in the function of the language, whether the parameter is variable, and who handles the stack. Different Languages define different call conventions.
In C ++, in order to allow Operator Overloading and function overloading, the C ++ compiler often rewrite the symbol names of
;Dll_process_detach: the process is stopped;Dll_thread_detach: The thread is stopped;Lpreserved: a parameter reserved by the system.
2. _ dllmaincrtstartup
To use the dll version (multithreading) of the "c" Runtime Library (CRT, C run time Library), a DLL application must specify _ dllmaincrtstartup as the entry function, the DLL initialization function must be dllmain.
_ Dllmaincrtstartup: Data (C Runtime data) of the "c" RunTime when the process or thread is bound to the DLL) allocate space an
, the above problem is solved, and the function solves the clearing work by itself. Therefore, in cross-platform (Development) calls, we use _ stdcall (although sometimes it appears as WINAPI ). So why do we still need _ cdecl? When the parameters of such a function, such as fprintf (), are variable and variable, the caller cannot know the length of the parameter in advance, and the cleanup operation afterwards cannot proceed normally, therefore, we can only use _ cdecl in this case. Here we hav
__stdcall,__cdecl,__fastcall The difference Tags: dll compiler pascalclassimportinitialization2009-12-09 15:07 10472 people read reviews (1) Favorite report categories:C + + (+)The difference between __stdcall,__cdecl,__fastcallOne or three list of differences
__stdcall
__cdecl
__fastcall
Parameter Passing method
Right-to-left pressure stack
Right-to-left pressure stack
On the left, two parameters that are not greater than 4 bytes (DWORD
code. in fact, they aren't even consistant in their internal code in. NET framework), de facto standards have emerged, and I have captured them here.
The "ux" naming convention for controls is something I have added and found to be helpful. it is not based on any official standards, but instead based upon a multitude of projects by my teams and others, as well as on-line discussions on the topic. while I stronugly recommend that you follow Microsoft
stack, the top of the stack automatically become the new data entry position, the top of the stack pointer also changes. Users can also take the stack from the top of the stack, known as pop-up stack (POP), pop-up stack, the top of the stack under the top of the stack, the top of the stack pointer changes. function calls, the caller sequentially presses the parameter stack, then calls the function, the function is called, obtains the data in the stack, and calculates. After the function is eval
Programmers who use C/C ++ to develop software often encounter this problem: sometimes there is no problem in program compilation, but the function is always reported when the link is used (the classic LNK 2001 error ), sometimes there are no errors in program compilation and linking, but a stack exception occurs when a function in the library is called. These phenomena usually occur when C and C ++ code are used together or when a third-party library is used in C ++ programs (not developed in C
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.