WinDNS header/library inconsistency in 32 bit

Frederik Juul 1 Reputation point
2020-09-24T08:49:25.033+00:00

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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,498 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Frederik Juul 1 Reputation point
    2020-09-24T08:56:19.507+00:00
    0 comments No comments