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

会有一股神秘感。 提交于 2019-12-06 11:37:43
  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

3) Almost all Windows functions (from shell32.dll, user32.dll, and all other) are declared as __stdcall, or as WINAPI (same thing). It is not necessary to declare functions in DLL as WINAPI, but people just follow Microsoft's lead. The code will be a few bytes smaller, and execution a few nanoseconds shorter.

2) What are we technically doing in these 2 lines. Declaring function pointer.

First a type is defined that can be used to point to any function that follows the prototype DWORD WINAPI funcName(unsigned long*);. Then a variable of that type is created.

3) Why do we need to use WINAPI* in the function pointer declaration in 1st line.

Because function_1 is using the WINAPI calling convention (usually defined as __stdcall). Or at least this code assumes that it does.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!