(This question uses zlib as an example but isn't specific to it.)
I'm trying to compile zlib on Windows using the MSVC project file it comes with. I'm using VS2012 with the Windows 8 SDK, but my build machine is Windows 7.
Zlib contains the following code:
#ifdef IOWIN32_USING_WINRT_API
if ((filename!=NULL) && (dwDesiredAccess != 0))
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
if ((filename!=NULL) && (dwDesiredAccess != 0))
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif
where IOWIN32_USING_WINRT_API is set up as follows
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define IOWIN32_USING_WINRT_API 1
#endif
#endif
WINAPI_FAMILY_PARTITION and WINAPI_PARTITION_APP are defined in the Windows 8 SDK (winapifamily.h), so the result is that the code that uses CreateFile2 in zlib is available to be compiled.
I can compile zlib, but any application that tries to load it fails because it can't find CreateFile2, and rightly so, since my machine is Windows 7 and that API was introduced in Windows 8.
This is the first time I've ever used a Windows SDK on a lower version of Windows than it supports, hence my question:
Is my only recourse to patch zlib to add a check for _WIN32_WINNT >= _WIN32_WINNT_WIN8 to the very first line, and pass /D_WIN32_WINNT=_WIN32_WINNT_WIN7 to msbuild? That would mean I'd have to build two sets of binaries - one that supports Win7 (by passing the /D) and one that supports Win8 (by not passing the /D).
Is there no way to have a common binary that works on both Windows 7 and 8 and uses the CreateFile2 codepath if running on Windows 8? (I suppose that way is GetProcAddress + function pointers. Anything else?)