what is the purpose of writing WINAPI word in function
WINAPI is a macro that evaluates to __stdcall , a Microsoft-specific keyword that specifies a calling convention where the callee cleans the stack. The function's caller and callee need to agree on a calling convention to avoid corrupting the stack.