Search code examples
c++windowsheaderconditional-compilationwinapi

Include header that may or may not exist on Windows


So, I am trying to deal with small differences in the various versions of the Windows SDK but am having trouble determining during compilation precisely what version of the Windows SDK I am building against in C++.

As of version 6.1 of the Windows SDK, there is a WinSDKVer.h file that contains some version information that I could use to determine what version of the SDK is being used even though it does not contain a direct version number for the SDK. However, 6.0A does not include this header file, so simply inserting #include and then using something like #ifdef will not work since there is no WinSDKVer.h in the environment.

A colleague of mine had a vague recollection of a way to include a header on Windows if and only if it exists, but could not remember any details and I have so far failed to find any information on doing so either on stackoverflow or the internet.

I've already done what I can to our make process to try to force the use of a 6.1 or greater SDK if installed on the developer's machine, but I'm also interested if others have run into this general kind of issue before and if/how they solved it.

Any ideas?


Solution

  • (ugly) create your own empty version of the header file and place it on a folder. Then add this folder last in your include directories. if the file exists in the SDK it will be included; otherwise your file will be used.