Tuesday, February 7, 2017

Errors in Windows header files

From time to time I find errors in the WinAPI header files.
Usually, they are small errors, which can be very annoying in certain cases.

Example #1:
Some function definitions lack the DECLSPEC_IMPORT (which is a macro for DLL import/export tag)
Usually, it is not a problem. The compiler identify it as external, and the linker finds it in the WinAPI. But it means that the function pointer does not point directly to the DLL, but indirectly using stubs. On normal usage you won't notice that, but it causes problems with MSDetour library.

Example #2:
EnumPageFiles accept a callback of type PENUM_PAGE_CALLBACK.
But in the definition of that in Psapi.h, they forgot to add the CALLBACK modifier, that should make it to stdcall.
So, if you are using the function, at best you get a weird compilation error, or simply a crash.