WINAPI identifiers in function declaration C++ in DLL entrypoint function [duplicate]

WINAPI identifiers in function declaration C++ in DLL entrypoint function [duplicate]



This question already has an answer here:



I'm just learning how to create a dll with C++.



There appears this :


BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)



And I can not understand what is "WINAPI" in DllMain()?


"WINAPI"


DllMain()



I know that a function is :


typeReturn functionName (params) function body



typeReturn : is the value that function returns,
functionName : is the name of the function,
params : are the parameters for the function,

function body : is the code inside in the function.

...


typeReturn


functionName


params



Then, following the explanation, what does WINAPI mean in C++ that or __stdcall?


WINAPI


__stdcall



I'm not asking what means WINAPI itself.


WINAPI



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





For me, searching "WINAPI" in Google gives the answer in the first link: stackoverflow.com/questions/2348442/…
– Ivan Aksamentov - Drop
Aug 19 at 4:14





yes, but what does IN C++ mean? can i write functions with extra identifier that crowns functions?
– Andres Camilo Sierra Hormiga
Aug 19 at 4:20




2 Answers
2



WINAPI is defined as __stdcall.


WINAPI


__stdcall



Actually __stdcall is a calling convention And different calling conventions push parameters in different ways, Bellow are some of c/c++ Calling Conventions :


__stdcall


c/c++



In x86 :



C calling convention (__cdecl). The main characteristics of __cdecl calling convention are :


C


__cdecl


__cdecl



Standard calling convention (__stdcall). The main characteristics of __stdcall calling convention are :


__stdcall


__stdcall



Fast calling convention (__fastcall). he main characteristics of __fastcall calling convention are :


__fastcall


__fastcall


'@'


'@'



Consider to Read This Link



In x64 :
In x64, only __fastcall exists. All other attributes are ignored.


x64


__fastcall



The x64 Application Binary Interface (ABI) uses a four register fast-call calling convention by default.


x64



Notice :
When you call a function, what happens at the assembly level is all the passed-in parameters are pushed to the stack or placed in registers or placed in static storage, then the program jumps to a different area of code. The new area of code looks at the stack and expects the parameters to be placed there.



Different calling conventions push parameters in different ways. Some might push the first parameter first, or some might push the first param last. Or some might keep a parameter in a register and not push it at all.



By specifying a calling convention, you are telling the compiler how the parameters are to be pushed.





so, PARAMETERS can be passed to stack, why? or why do i need push parameters to another site? sorry, i'm very new in c++.
– Andres Camilo Sierra Hormiga
Aug 19 at 4:32





The __cdecl convention is "safer" because it is the caller that needs to deallocate the stack. What may happen in a __stdcall library is that the developer might have forgotten to deallocate the stack properly, or an attacker might inject some code by corrupting the DLL's stack (e.g. by API hooking) which is then not checked by the caller. See this Link
– Mohammadreza Panahi
Aug 19 at 4:37


__cdecl


__stdcall





then, "calling conventions" in C++ are a safer way to call functions, avoiding some attackers inject code to corrupt my function. searching in google...
– Andres Camilo Sierra Hormiga
Aug 19 at 4:45






@AndresCamiloSierraHormiga Calling conventions in general aren't a "safer" way to call functions. Every function has a calling convention. It's the contract between the caller and the callee that both agree to adhere to so that the callee knows where to find its parameters and where to put its return value so the caller can find it.
– Miles Budnek
Aug 19 at 5:23





Worth noting, those calling conventions are relevant in 32-bit code only. The 64-bit ABI of the Windows API defines only a single calling convention, and you can get away with not specifying one in your code, because the choice is unambiguous.
– IInspectable
2 days ago



Dynamic-Link Library, used in Windows operating system, so the entry point of DLL function should be crowned by "WINAPI" if it is running on Windows.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ