When I write a program at night, I don't know what STDAPI is. Share it with me!

Source: Internet
Author: User

For a beginner, the following function definitions are certainly confusing.
STDAPI DllGetClassObject (){}
You may ask what STDAPI is in the function definition. If you are confused about this, I will tell you the STDAPI macro definition in WINNT. H is as follows:

# Define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
In MSDN, The STDAPICALLTYPE macro is defined as follows:
# Ifdef _ WIN32 // Win32 doesn' t support _ export
# Define STDAPICALLTYPE _ stdcall
# Else
# Define STDAPICALLTYPE _ export _ stdcall
# Endif

# Ifdef _ cplusplus
# Define EXTERN_C extern "C"
# Else
# Define EXTERN_C extern
# Endif

It can be seen that STDAPI is just a macro definition. The macro definition consists of two macro definitions (EXTERN_C and STDAPICALLTYPE) and HRESULT. After pre-compilation, the following results are displayed:
Extern "c" HRESULT _ stdcall
Here, I assume that it is precompiled in Win32, so there is no _ export. At the same time, _ cplusplus is defined, that is, the C ++ syntax is used.
Extern "C" is not needed. You can refer to any c/c ++ grammar book. HRESULT is the return value type of the function. _ Stdcall is a call type ). This is what I want to talk about.
During programming, you may see two macros, CALLBACK and WINAPI, In the function declaration or definition. They are also synonymous with _ stdcall. Check the content in windef. h:

# Define CALLBACK _ stdcall
# Define WINAPI _ stdcall
Are there other call types besides _ stdcall? What is the call type? In my understanding, the call type is a rule for how to use function parameters. There are three call types: __fastcall, _ cdecl, and _ stdcall.
1. _ cdecl call type:
This is the calling rule of C. This is the default call rule for all functions that are not C ++ member functions or functions that are not labeled _ stdcall or _ fastcall.
2. _ fastcall call type:
It can be seen from the literal meaning that this is a fast call. Because the CPU registers are used to store the first few parameters in the function parameter list. The remaining parameters will be pushed down the stack from right to left. The called function obtains function parameters from registers and stacks. In x86, ECX and EDX are generally used to store the initial parameters. In. NET, ecx and edx are used to implement _ fastcall for fast performance.
3. _ stdcall call type:
This call only uses the stack to push and pop parameters. When pushing parameters, the order is from right to left.

Now, you should understand. Finally, let me add a sentence. The three call types correspond to the/Gd,/Gr, And/Gz compilation options in the VC compiler.

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.