Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why need to use "WINAPI*" for the Syntax for declaring function pointers for functions in a DLL

I have a C++ console application & a DLL. In the C++ application I see the following snippet ::

typedef DWORD (WINAPI* functABC)(unsigned long*);

functABC functABC111;
HMODULE handleDLL = LOadLibrary("a.DLL");
functABC111 = (functABC)GetProcAddress(handleDLL,"function_1");

At a high level I understand that we are getting the function pointer to the function in a.DLL "function_1()".

But want to understand the 1st 2 lines in the above snippet ::

typedef DWORD (WINAPI* functABC)(unsigned long*);
functABC functABC111;

2 questions :: 1) Is the name "functABC" just a random function pointer name?
2) What are we technically doing in these 2 lines. Declaring function pointer.
3) Why do we need to use WINAPI* in the function pointer declaration in 1st line.

THanks in advance.

like image 408
codeLover Avatar asked May 25 '26 15:05

codeLover


1 Answers

  1. 'functABC' is a typedef to a function returning a DWORD taking an unsigned long pointer as a parameter

  2. First lines defines a typedef and second one creates a function pointer using it

  3. 'WINAPI' is a macro that's usually expanded to '__stdcall' which is the calling convention used by Microsoft to export functions from a .DLL

like image 118
user1233963 Avatar answered May 28 '26 03:05

user1233963