Home > Article > Backend Development > What are the function calling conventions in C++?
Calling conventions in C define how function arguments are passed and values are returned, including cdecl, fastcall, thiscall, and stdcall. In practice, the stdcall calling convention can be used to load and call functions in a DLL.
C Function Calling Convention
In C, the calling convention defines how arguments to a function are passed and returned. Different calling conventions have different trade-offs in terms of performance, memory usage, and code portability.
Common calling conventions
Practical case
The following C code demonstrates the use of stdcall to call a function:
#include <windows.h> // 只适用于 Windows typedef void (WINAPI *pfnPrintString)(const char*); int main() { // 加载 DLL 并获取函数指针 HMODULE hDll = LoadLibrary("mydll.dll"); pfnPrintString PrintString = (pfnPrintString)GetProcAddress(hDll, "PrintString"); // 调用函数,传递参数 PrintString("Hello, world!"); // 卸载 DLL FreeLibrary(hDll); return 0; }
In this example, stdcall is used to call The convention is to load and call the PrintString function from the DLL.
The above is the detailed content of What are the function calling conventions in C++?. For more information, please follow other related articles on the PHP Chinese website!