w4j3d w4j3d - 2 months ago 4x
C Question

BOOL (WINAPI * FunctionName) ( var1, var2, etc...) = NULL // … What does this code mean? What does it do?

BOOL (WINAPI * FunctionName) (var1, var2, etc...) = NULL;

What does this code mean? What does it do?


This line defines a function pointer FunctionName pointing to a function that takes arguments var1, var2... returns BOOL, is called with the WINAPI calling convention (this is really for the compiler to generate the proper code) and initialized to NULL (the null pointer).

On the Intel architecture, there are different ways to call functions at the machine code level (aka ABI), Windows supports multiple ones and WINAPI is a to tell the compiler to generate code for the standard kernel ABI.

The function pointer has a type, namely the number and types of the parameters and the return type (aka prototype). You can store the address of a function whose prototype matches the type of the pointer. This makes it easier to avoid type mismatches on parameters.