Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between pointer to function and pointer to WINAPI function?

I came accross a code snippet which detects whether app is running in x32 emulated environment on x64 PC here

Generally I understand that code but there is one thing I don't get:

1) typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

Why does WINAPI have to be there? Why is it so important to know that pointer doesn't point to my-defined function but to WINAPI one? Would these 2 pointers be different? (in way of size, place they are created etc.)

Thanks,

Kra

like image 615
Kra Avatar asked Mar 22 '26 11:03

Kra


2 Answers

WINAPI expands to __stdcall (in most cases -- you shouldn't rely on that calling convention specifically), which is a different calling convention than the default, __cdecl. The difference is that in __stdcall, the function called cleans the stack, while in __cdecl, the caller cleans the stack. __stdcall does not support varadic (Variable argument length) functions like __cdecl does, but __stdcall can be faster and reduce code size in some cases.

like image 54
Billy ONeal Avatar answered Mar 24 '26 23:03

Billy ONeal


WINAPI is a macro that normally contains implementation-specific declaration details related to WinAPI functions. Like a calling convention. The above pointer can point to any function as long as it follows the same calling convention as WinAPI functions do.

The fact that this macro is spelled as WINAPI has no significance whatsoever. It could have been spelled A, HELLO_WORLD or anything else. The whole and only point of that WINAPI macro is to provide a single place where all these WinAPI-specific conventions are described, so that in case something changes you'd only have to modify it in one place.

It could easily be a macro that resolves to nothing.

like image 21
AnT Avatar answered Mar 25 '26 01:03

AnT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!