From 423b58150fa618f13a298036b5581a9d0467b784 Mon Sep 17 00:00:00 2001 From: mol123 <60134413+mol123@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:30:11 +0200 Subject: [PATCH] Fix build when targeting Windows 7 as platform. This change makes more of the code introduced in https://github.com/yhirose/cpp-httplib/pull/1775 conditional on feature macros. `CreateFile2`, `CreateFileMappingFromApp` and `MapViewOfFileFromApp` are available only starting from Windows 8. * https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 * https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingfromapp * https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffilefromapp --- httplib.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index 616b914..25b984a 100644 --- a/httplib.h +++ b/httplib.h @@ -2823,8 +2823,13 @@ inline bool mmap::open(const char *path) { wpath += path[i]; } +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8) hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL); +#else + hFile_ = ::CreateFileW(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +#endif if (hFile_ == INVALID_HANDLE_VALUE) { return false; } @@ -2832,7 +2837,7 @@ inline bool mmap::open(const char *path) { if (!::GetFileSizeEx(hFile_, &size)) { return false; } size_ = static_cast(size.QuadPart); -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8) hMapping_ = ::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL); #else @@ -2846,7 +2851,7 @@ inline bool mmap::open(const char *path) { return false; } -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8) addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0); #else addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);