It seems this was reported just a few hours ago as well :) https://video2.skills-academy.com/en-us/answers/questions/105961/some-dns-api-functions-cause-lnk2019-errors-in-x86.html
WinDNS header/library inconsistency in 32 bit
It seems there's an inconsistency between the compiled DnsAPI.lib library and the windns.h header when compiling in 32 bit.
Specifically the issue is with calling conventions: The compiled library is using the __stdcall
calling convention, while the header declares a __cdecl
function. This makes it impossible to link to the library if running in 32 bit mode.
This can be observed by doing the following:
Using a Visual Studio Develop Shell, navigate to the SDK library files (in my case C:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/um/x86/
).
Then run dumpbin /exports DnsAPI.lib
.
Observe that the exported symbols looks like this _DnsServiceRegister@8
. According to https://video2.skills-academy.com/en-us/cpp/build/reference/decorated-names?view=vs-2019 this means that the symbol is an __stdcall
function.
Now go to the corresponding header (windns.h) and observe that a function declaration looks like this:
DWORD DnsServiceRegister(
_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest,
_Inout_opt_ PDNS_SERVICE_CANCEL pCancel);
When this is compiled it defaults to the __cdecl
calling convention. This means that compilation will succeed but linking will fail.
And indeed, adding WINAPI
to the header allows it to compile and link successfully in 32 bit mode.
I therefore think that this is a bug that should be fixed in the header file, in the windows SDK.
This is not limited to only the DnsServiceRegister
function.