This is an automated email from the ASF dual-hosted git repository.

leginee pushed a commit to branch aoo50x-win7-floor
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 5f2d56ca18422a9fcf3a851a4c07edf0d4f52f0b
Author: Peter <[email protected]>
AuthorDate: Thu Dec 3 06:34:14 2026 +0100

    Windows 7 SP1 floor
    
    - solenv: Windows API floor WINVER/_WIN32_WINNT=0x0601 in wntmsci11.mk,
      wntmscx.mk and gbuild windows.mk; _WIN32_IE is no longer pinned (the
      SDK derives it per translation unit, which uwinapi's NT4 files need)
    - sal/uwinapi: psapi thunks built with PSAPI_VERSION=1, otherwise psapi.h
      renames GetModuleFileNameEx* to K32* at 0x0601 and the .dxp export breaks
    - python: Python 3.11 patched to build for and load on Windows 7 SP1
    - setup.exe: require Windows 7 SP1 instead of Windows 10
    - MSI: LaunchCondition refuses Windows 7 RTM and older
    
    The pieces taken earlier (Win64 pointer fixes, installer fixes) are already
    on this branch; this completes the floor so that compile defines, setup.exe,
    the MSI and the bundled Python all name the same minimum.
    
    (cherry picked from commit c34c9f813125780dafc52d725b4057487d838338)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 main/desktop/win32/source/setup/setup.cpp          |  51 +--
 main/desktop/win32/source/setup/setup.ulf          |   2 +-
 .../windows/msi_languages/LaunchCo.ulf             |   2 +
 .../windows/msi_templates/LaunchCo.idt             |   3 +-
 main/python/makefile.mk                            |  11 +
 main/python/python-3.11.15-win7.patch              | 414 +++++++++++++++++++++
 main/sal/systools/win32/uwinapi/makefile.mk        |   7 +
 main/solenv/gbuild/platform/windows.mk             |   6 +-
 main/solenv/inc/wntmsci11.mk                       |  13 +-
 main/solenv/inc/wntmscx.mk                         |  13 +-
 10 files changed, 493 insertions(+), 29 deletions(-)

diff --git a/main/desktop/win32/source/setup/setup.cpp 
b/main/desktop/win32/source/setup/setup.cpp
index 6e62b818d5..bd589b391d 100644
--- a/main/desktop/win32/source/setup/setup.cpp
+++ b/main/desktop/win32/source/setup/setup.cpp
@@ -67,10 +67,13 @@
 #define ERROR_OS_TO_OLD       -5
 #define ERROR_RUNTIME_FAILED  -6
 
-// Lowest Windows this office can run on.  Not an arbitrary policy: the VC v14
-// redistributable that supplies the runtime the binaries need installs only on
-// Windows 10/11 and Server 2016 and later, so the floor comes with the 
toolset.
-#define REQUIRED_WINDOWS_MAJOR  10
+// Lowest Windows this office can run on: Windows 7 SP1 (6.1 SP1), matching the
+// WINVER/_WIN32_WINNT 0x0601 the office is compiled for and the MSI launch
+// condition.  The bundled VC v14 redistributable must still install there --
+// current releases do not; see external/vcredist/README.
+#define REQUIRED_WINDOWS_MAJOR  6
+#define REQUIRED_WINDOWS_MINOR  1
+#define REQUIRED_WINDOWS_SP     1
 
 #define PARAM_SETUP_USED    TEXT( " SETUP_USED=1 " )
 #define PARAM_PACKAGE       TEXT( "/I " )
@@ -1861,9 +1864,9 @@ boolean SetupApp::IsPatchInstalled( TCHAR* pBaseDir, 
TCHAR* pFileName )
 // as an MSI LaunchCondition, and lives here instead.
 //
 // RtlGetVersion is not subject to that shim.
-static bool GetRealWindowsVersion( DWORD *pMajor, DWORD *pBuild )
+static bool GetRealWindowsVersion( OSVERSIONINFOEXW *pInfo )
 {
-    typedef LONG ( WINAPI *pfnRtlGetVersion_t )( OSVERSIONINFOW * );
+    typedef LONG ( WINAPI *pfnRtlGetVersion_t )( OSVERSIONINFOEXW * );
 
     HMODULE hNtdll = ::GetModuleHandle( TEXT( "ntdll.dll" ) );
     if ( hNtdll == NULL )
@@ -1874,25 +1877,18 @@ static bool GetRealWindowsVersion( DWORD *pMajor, DWORD 
*pBuild )
     if ( pRtlGetVersion == NULL )
         return false;
 
-    OSVERSIONINFOW aInfo;
-    ZeroMemory( &aInfo, sizeof( aInfo ) );
-    aInfo.dwOSVersionInfoSize = sizeof( aInfo );
+    ZeroMemory( pInfo, sizeof( *pInfo ) );
+    pInfo->dwOSVersionInfoSize = sizeof( *pInfo );
 
-    if ( pRtlGetVersion( &aInfo ) != 0 )
-        return false;
-
-    *pMajor = aInfo.dwMajorVersion;
-    *pBuild = aInfo.dwBuildNumber;
-    return true;
+    return pRtlGetVersion( pInfo ) == 0;
 }
 
 //--------------------------------------------------------------------------
 boolean SetupApp::CheckOSVersion()
 {
-    DWORD nMajor = 0;
-    DWORD nBuild = 0;
+    OSVERSIONINFOEXW aInfo;
 
-    if ( !GetRealWindowsVersion( &nMajor, &nBuild ) )
+    if ( !GetRealWindowsVersion( &aInfo ) )
     {
         // Could not determine the version.  Let the install proceed rather 
than
         // refuse on a machine we simply failed to identify -- if the OS 
really is too
@@ -1903,15 +1899,24 @@ boolean SetupApp::CheckOSVersion()
 
     TCHAR sBuf[ 128 ];
 
-    StringCchPrintf( sBuf, 128, TEXT( " Windows major version %u, build 
%u\r\n" ),
-                     nMajor, nBuild );
+    StringCchPrintf( sBuf, 128, TEXT( " Windows version %u.%u build %u, 
service pack %u\r\n" ),
+                     aInfo.dwMajorVersion, aInfo.dwMinorVersion, 
aInfo.dwBuildNumber,
+                     (DWORD)aInfo.wServicePackMajor );
     Log( sBuf );
 
-    if ( nMajor < REQUIRED_WINDOWS_MAJOR )
+    const DWORD nHave = ( aInfo.dwMajorVersion << 16 ) | ( 
aInfo.dwMinorVersion << 8 )
+                        | aInfo.wServicePackMajor;
+    const DWORD nNeed = ( REQUIRED_WINDOWS_MAJOR << 16 ) | ( 
REQUIRED_WINDOWS_MINOR << 8 )
+                        | REQUIRED_WINDOWS_SP;
+
+    if ( nHave < nNeed )
     {
         StringCchPrintf( sBuf, 128,
-                         TEXT( "ERROR: Windows %u is older than the required 
Windows %u.\r\n" ),
-                         nMajor, (DWORD)REQUIRED_WINDOWS_MAJOR );
+                         TEXT( "ERROR: Windows %u.%u SP%u is older than the 
required Windows %u.%u SP%u.\r\n" ),
+                         aInfo.dwMajorVersion, aInfo.dwMinorVersion,
+                         (DWORD)aInfo.wServicePackMajor,
+                         (DWORD)REQUIRED_WINDOWS_MAJOR, 
(DWORD)REQUIRED_WINDOWS_MINOR,
+                         (DWORD)REQUIRED_WINDOWS_SP );
         Log( sBuf );
         SetError( ERROR_OS_TO_OLD );
         return false;
diff --git a/main/desktop/win32/source/setup/setup.ulf 
b/main/desktop/win32/source/setup/setup.ulf
index 1950668380..b0f326d96c 100644
--- a/main/desktop/win32/source/setup/setup.ulf
+++ b/main/desktop/win32/source/setup/setup.ulf
@@ -50,7 +50,7 @@ en-US = "This package requires at least the version '%s' of 
the Windows Installe
 en-US = "This package requires the Windows Installer. \nYou need at least 
Windows Installer '%s' on your system!"
 
 [%OS_TO_OLD%]
-en-US = "This version of %PRODUCTNAME% requires Windows 10 or later. \nIt 
cannot be installed on this version of Windows."
+en-US = "This version of %PRODUCTNAME% requires Windows 7 Service Pack 1 or 
later. \nIt cannot be installed on this version of Windows."
 
 [%RUNTIME_FAILED%]
 en-US = "The Microsoft Visual C++ runtime could not be installed. 
\n%PRODUCTNAME% cannot run without it, so the installation has been stopped."
diff --git 
a/main/instsetoo_native/inc_openoffice/windows/msi_languages/LaunchCo.ulf 
b/main/instsetoo_native/inc_openoffice/windows/msi_languages/LaunchCo.ulf
index 7f443b1949..9ac0306ab3 100644
--- a/main/instsetoo_native/inc_openoffice/windows/msi_languages/LaunchCo.ulf
+++ b/main/instsetoo_native/inc_openoffice/windows/msi_languages/LaunchCo.ulf
@@ -23,3 +23,5 @@
 en-US = "The Installation Wizard cannot be run properly because you are logged 
in as a user without sufficient administrator rights for this system."
 [OOO_LAUNCH_2]
 en-US = "Please use the file setup.exe to start the installation."
+[OOO_LAUNCH_3]
+en-US = "[ProductName] requires Windows 7 Service Pack 1 or later."
diff --git 
a/main/instsetoo_native/inc_openoffice/windows/msi_templates/LaunchCo.idt 
b/main/instsetoo_native/inc_openoffice/windows/msi_templates/LaunchCo.idt
index 3fe0c20621..0ab3f179aa 100644
--- a/main/instsetoo_native/inc_openoffice/windows/msi_templates/LaunchCo.idt
+++ b/main/instsetoo_native/inc_openoffice/windows/msi_templates/LaunchCo.idt
@@ -2,4 +2,5 @@ Condition       Description
 s255   l255
 WINDOWSENCODINGTEMPLATE        LaunchCondition Condition
 Privileged     OOO_LAUNCH_1
-(VersionNT < 600) or (SETUP_USED=1) or Installed       OOO_LAUNCH_2 
\ No newline at end of file
+(VersionNT < 600) or (SETUP_USED=1) or Installed       OOO_LAUNCH_2 
+(VersionNT > 601) or (VersionNT = 601 and ServicePackLevel >= 1) or Installed  
OOO_LAUNCH_3
\ No newline at end of file
diff --git a/main/python/makefile.mk b/main/python/makefile.mk
index 14c307e125..587785203c 100644
--- a/main/python/makefile.mk
+++ b/main/python/makefile.mk
@@ -58,6 +58,17 @@ PATCH_FILES+=python-$(PYVERSION)-selfcontained.patch
 #   through the compiler include/lib search paths instead of the old hard-coded
 #   source edit; see python_CFLAGS/python_LDFLAGS in the UNX branch below.
 
+# Windows 7 SP1, the office's floor, where upstream Python 3.9+ wants
+# Windows 8: PC/pyconfig.h's Py_WINVER/Py_NTDDI lowered to Windows 7, and
+# pythoncore no longer imports pathcch.lib (its API set does not exist on
+# Windows 7, so python311.dll would not even load there) -- PC/pathcch_win7.c
+# calls the real PathCch* functions where KernelBase exports them and falls
+# back to their documented behaviour on Windows 7.  _freeze_module keeps
+# pathcch.lib: it only runs on the build machine.
+.IF "$(GUI)"=="WNT"
+PATCH_FILES += python-$(PYVERSION)-win7.patch
+.ENDIF
+
 # Windows build deferred — Python 3 requires modern MSVC (VS2008/msvs9 not 
supported).
 # The msvs9 patch files below are retained for reference but are NOT applied 
until
 # the Windows toolchain is modernised. See python3 migration notes.
diff --git a/main/python/python-3.11.15-win7.patch 
b/main/python/python-3.11.15-win7.patch
new file mode 100644
index 0000000000..2296e1792b
--- /dev/null
+++ b/main/python/python-3.11.15-win7.patch
@@ -0,0 +1,414 @@
+diff -ruN misc/Python-3.11.15/PC/aoo_win7_compat.h 
misc/build/Python-3.11.15/PC/aoo_win7_compat.h
+--- misc/Python-3.11.15/PC/aoo_win7_compat.h   1970-01-01 00:00:00.000000000 
+0000
++++ misc/build/Python-3.11.15/PC/aoo_win7_compat.h     2025-01-01 
00:00:00.000000000 +0000
+@@ -0,0 +1,48 @@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++
++/*
++ * Force-included into every CPython translation unit 
(PCbuild/pyproject.props,
++ * ForcedIncludeFiles).
++ *
++ * CPython 3.11 is compiled here at the Windows 7 API level (Py_WINVER 0x0601
++ * in PC/pyconfig.h) instead of upstream's Windows 8 one, so the SDK hides 
what it
++ * gates on Windows 8.  Most of that would be a real dependency and must stay 
a
++ * compile error.  What is defined here is only what CPython uses WITHOUT
++ * depending on Windows 8 -- plain constants, never functions -- each with the
++ * use that makes it safe.  The values are the SDK's.
++ *
++ * Found by matching every name the 10.0.19041.0 SDK declares under a Windows 
8
++ * or later guard against the sources this module compiles.
++ */
++
++#ifndef AOO_PYTHON_WIN7_COMPAT_H
++#define AOO_PYTHON_WIN7_COMPAT_H
++
++/* WinNls.h, WINVER >= _WIN32_WINNT_WIN8.  Modules/_winapi.c
++   (_winapi.LCMapStringEx) only uses them to reject these flags with
++   ValueError before calling LCMapStringEx, which itself exists from Vista. */
++#ifndef LCMAP_SORTHANDLE
++#define LCMAP_SORTHANDLE 0x20000000
++#endif
++#ifndef LCMAP_HASH
++#define LCMAP_HASH       0x00040000
++#endif
++
++#endif /* AOO_PYTHON_WIN7_COMPAT_H */
+diff -ruN misc/Python-3.11.15/PC/pathcch.h 
misc/build/Python-3.11.15/PC/pathcch.h
+--- misc/Python-3.11.15/PC/pathcch.h   1970-01-01 00:00:00.000000000 +0000
++++ misc/build/Python-3.11.15/PC/pathcch.h     2025-01-01 00:00:00.000000000 
+0000
+@@ -0,0 +1,63 @@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++
++/*
++ * Stand-in for the Windows SDK's <pathcch.h>, for a Python that must load on
++ * Windows 7 SP1.
++ *
++ * The SDK header declares the PathCch* functions as imports from
++ * api-ms-win-core-path-l1-1-0.dll, an API set that exists from Windows 8 on.
++ * A python311.dll importing it statically cannot be loaded on Windows 7 at
++ * all.  This file lives in PC/, which is on the include path ahead of the 
SDK,
++ * so `#include <pathcch.h>` in getpath.c, posixmodule.c, fileutils.c and
++ * pathconfig.c resolves here instead and the SDK header is never seen.
++ *
++ * Only what those four files use is declared.  The definitions in
++ * PC/pathcch_win7.c call the real functions from KernelBase.dll when it
++ * exports them (Windows 8 and later), so behaviour there is the system's own;
++ * the fallbacks only ever run on Windows 7.
++ */
++
++#ifndef AOO_PYTHON_PATHCCH_H
++#define AOO_PYTHON_PATHCCH_H
++
++#include <windows.h>
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++#define PATHCCH_NONE             0x00000000
++#define PATHCCH_ALLOW_LONG_PATHS 0x00000001
++
++/* Largest buffer, in characters, the PathCch functions accept. */
++#define PATHCCH_MAX_CCH          0x8000
++
++HRESULT WINAPI PathCchSkipRoot(PCWSTR pszPath, PCWSTR *ppszRootEnd);
++HRESULT WINAPI PathCchFindExtension(PCWSTR pszPath, size_t cchPath,
++                                    PCWSTR *ppszExt);
++HRESULT WINAPI PathCchCombineEx(PWSTR pszPathOut, size_t cchPathOut,
++                                PCWSTR pszPathIn, PCWSTR pszMore,
++                                ULONG dwFlags);
++
++#ifdef __cplusplus
++}
++#endif
++
++#endif /* AOO_PYTHON_PATHCCH_H */
+diff -ruN misc/Python-3.11.15/PC/pathcch_win7.c 
misc/build/Python-3.11.15/PC/pathcch_win7.c
+--- misc/Python-3.11.15/PC/pathcch_win7.c      1970-01-01 00:00:00.000000000 
+0000
++++ misc/build/Python-3.11.15/PC/pathcch_win7.c        2025-01-01 
00:00:00.000000000 +0000
+@@ -0,0 +1,241 @@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++
++/*
++ * PathCch* for a python311.dll that must load on Windows 7 SP1.  See
++ * PC/pathcch.h for why this exists.
++ *
++ * Each function first asks KernelBase.dll for the real implementation.
++ * KernelBase is mapped into every process from Windows 7 on, so this loads
++ * nothing and searches no directory; from Windows 8 on it exports the PathCch
++ * family and the system's own code runs.  Only when the export is missing --
++ * i.e. on Windows 7 -- does the fallback below run.
++ *
++ * The fallbacks are written from the documented contract of each function,
++ * and cover what Python 3.11 asks of them:
++ *   PathCchSkipRoot      os._path_splitroot (posixmodule.c), _Py_isabs
++ *                        (fileutils.c)
++ *   PathCchFindExtension the ".exe" test in getpath.c's isxfile
++ *   PathCchCombineEx     _Py_join_relfile (fileutils.c), used by getpath
++ * PathCchCombineEx falls back to shlwapi's PathCombineW and so is limited to
++ * MAX_PATH there -- which is the limit Windows 7 itself imposes on the Win32
++ * file API without a \\?\ prefix.
++ */
++
++#include "pathcch.h"
++
++#include <shlwapi.h>
++#include <string.h>
++#include <wchar.h>
++
++typedef HRESULT (WINAPI *skip_root_fn)(PCWSTR, PCWSTR *);
++typedef HRESULT (WINAPI *find_extension_fn)(PCWSTR, size_t, PCWSTR *);
++typedef HRESULT (WINAPI *combine_ex_fn)(PWSTR, size_t, PCWSTR, PCWSTR, ULONG);
++
++/* Looks NAME up in KernelBase.dll once and remembers the answer in *SLOT:
++   0 = not looked up yet, -1 = not exported, otherwise the address.  Two
++   threads racing here store the same value, and a pointer-sized aligned store
++   is atomic on every Windows target, so no lock is needed. */
++static FARPROC
++kernelbase_export(volatile LONG_PTR *slot, const char *name)
++{
++    LONG_PTR value = *slot;
++    if (value == 0) {
++        HMODULE kernelbase = GetModuleHandleW(L"kernelbase.dll");
++        FARPROC proc = kernelbase ? GetProcAddress(kernelbase, name) : NULL;
++        value = proc ? (LONG_PTR)proc : (LONG_PTR)-1;
++        *slot = value;
++    }
++    return value == (LONG_PTR)-1 ? NULL : (FARPROC)value;
++}
++
++/* Advances past one path segment and the backslash ending it, if any. */
++static PCWSTR
++skip_segment(PCWSTR p)
++{
++    while (*p != L'\0' && *p != L'\\') {
++        ++p;
++    }
++    if (*p == L'\\') {
++        ++p;
++    }
++    return p;
++}
++
++static int
++is_drive_letter(WCHAR c)
++{
++    return (c >= L'A' && c <= L'Z') || (c >= L'a' && c <= L'z');
++}
++
++/* "X:" or "X:\" -> the character after it. */
++static PCWSTR
++skip_drive(PCWSTR p)
++{
++    p += 2;
++    if (*p == L'\\') {
++        ++p;
++    }
++    return p;
++}
++
++/* Root forms, as documented for PathCchSkipRoot:
++     C:\path        drive-absolute       root "C:\"
++     C:path         drive-relative       root "C:"
++     \path          rooted               root "\"
++     \\server\share\path                 root "\\server\share\"
++     \\?\C:\path                         root "\\?\C:\"
++     \\?\UNC\server\share\path           root "\\?\UNC\server\share\"
++     \\?\Volume{guid}\path               root "\\?\Volume{guid}\"
++   Anything else -- a relative path -- has no root and is E_INVALIDARG. */
++static HRESULT
++skip_root_fallback(PCWSTR path, PCWSTR *root_end)
++{
++    PCWSTR p;
++
++    if (path == NULL || root_end == NULL || path[0] == L'\0') {
++        return E_INVALIDARG;
++    }
++    *root_end = NULL;
++
++    if (path[0] == L'\\' && path[1] == L'\\') {
++        if (path[2] == L'?') {
++            if (path[3] != L'\\') {
++                return E_INVALIDARG;
++            }
++            p = path + 4;
++            if (_wcsnicmp(p, L"UNC\\", 4) == 0) {
++                p = skip_segment(p + 4);        /* server */
++                p = skip_segment(p);            /* share */
++            }
++            else if (is_drive_letter(p[0]) && p[1] == L':') {
++                p = skip_drive(p);
++            }
++            else if (_wcsnicmp(p, L"Volume{", 7) == 0) {
++                p = skip_segment(p);
++            }
++            else {
++                return E_INVALIDARG;
++            }
++        }
++        else {
++            p = skip_segment(path + 2);         /* server */
++            p = skip_segment(p);                /* share */
++        }
++    }
++    else if (is_drive_letter(path[0]) && path[1] == L':') {
++        p = skip_drive(path);
++    }
++    else if (path[0] == L'\\') {
++        p = path + 1;
++    }
++    else {
++        return E_INVALIDARG;
++    }
++
++    *root_end = p;
++    return S_OK;
++}
++
++/* The extension is the last '.' in the final path segment; with none,
++   *ext is the terminating NUL.  The string must end within cch characters. */
++static HRESULT
++find_extension_fallback(PCWSTR path, size_t cch, PCWSTR *ext)
++{
++    PCWSTR p;
++    PCWSTR dot = NULL;
++
++    if (ext == NULL) {
++        return E_INVALIDARG;
++    }
++    *ext = NULL;
++    if (path == NULL || cch == 0 || cch > PATHCCH_MAX_CCH) {
++        return E_INVALIDARG;
++    }
++    for (p = path; p < path + cch && *p != L'\0'; ++p) {
++        if (*p == L'.') {
++            dot = p;
++        }
++        else if (*p == L'\\') {
++            dot = NULL;
++        }
++    }
++    if (p == path + cch) {
++        return E_INVALIDARG;                    /* not terminated */
++    }
++    *ext = dot != NULL ? dot : p;
++    return S_OK;
++}
++
++static HRESULT
++combine_ex_fallback(PWSTR out, size_t cch, PCWSTR in, PCWSTR more,
++                    ULONG flags)
++{
++    WCHAR combined[MAX_PATH];
++    size_t len;
++
++    (void)flags;        /* long paths do not exist on Windows 7 */
++    if (out == NULL || cch == 0 || cch > PATHCCH_MAX_CCH) {
++        return E_INVALIDARG;
++    }
++    out[0] = L'\0';
++    if (PathCombineW(combined, in, more) == NULL) {
++        return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
++    }
++    len = wcslen(combined);
++    if (len >= cch) {
++        return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
++    }
++    memcpy(out, combined, (len + 1) * sizeof(WCHAR));
++    return S_OK;
++}
++
++static volatile LONG_PTR skip_root_slot;
++static volatile LONG_PTR find_extension_slot;
++static volatile LONG_PTR combine_ex_slot;
++
++HRESULT WINAPI
++PathCchSkipRoot(PCWSTR pszPath, PCWSTR *ppszRootEnd)
++{
++    skip_root_fn real = (skip_root_fn)kernelbase_export(
++        &skip_root_slot, "PathCchSkipRoot");
++    return real != NULL ? real(pszPath, ppszRootEnd)
++                        : skip_root_fallback(pszPath, ppszRootEnd);
++}
++
++HRESULT WINAPI
++PathCchFindExtension(PCWSTR pszPath, size_t cchPath, PCWSTR *ppszExt)
++{
++    find_extension_fn real = (find_extension_fn)kernelbase_export(
++        &find_extension_slot, "PathCchFindExtension");
++    return real != NULL ? real(pszPath, cchPath, ppszExt)
++                        : find_extension_fallback(pszPath, cchPath, ppszExt);
++}
++
++HRESULT WINAPI
++PathCchCombineEx(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn,
++                 PCWSTR pszMore, ULONG dwFlags)
++{
++    combine_ex_fn real = (combine_ex_fn)kernelbase_export(
++        &combine_ex_slot, "PathCchCombineEx");
++    return real != NULL
++        ? real(pszPathOut, cchPathOut, pszPathIn, pszMore, dwFlags)
++        : combine_ex_fallback(pszPathOut, cchPathOut, pszPathIn, pszMore,
++                              dwFlags);
++}
+diff -ruN misc/Python-3.11.15/PC/pyconfig.h 
misc/build/Python-3.11.15/PC/pyconfig.h
+--- misc/Python-3.11.15/PC/pyconfig.h  2025-01-01 00:00:00.000000000 +0000
++++ misc/build/Python-3.11.15/PC/pyconfig.h    2025-01-01 00:00:00.000000000 
+0000
+@@ -141,9 +141,12 @@
+ #endif /* MS_WIN64 */
+ 
+ /* set the version macros for the windows headers */
+-/* Python 3.9+ requires Windows 8 or greater */
+-#define Py_WINVER 0x0602 /* _WIN32_WINNT_WIN8 */
+-#define Py_NTDDI NTDDI_WIN8
++/* Upstream Python 3.9+ requires Windows 8 or greater.  Apache OpenOffice
++   builds it for Windows 7 SP1, its own floor: PC/pathcch_win7.c stands in for
++   the PathCch* functions Windows 7 lacks, and PC/aoo_win7_compat.h supplies
++   the few Windows 8 constants used without depending on Windows 8. */
++#define Py_WINVER 0x0601 /* _WIN32_WINNT_WIN7 */
++#define Py_NTDDI NTDDI_WIN7
+ 
+ /* We only set these values when building Python - we don't want to force
+    these values on extensions, as that will affect the prototypes and
+diff -ruN misc/Python-3.11.15/PCbuild/pyproject.props 
misc/build/Python-3.11.15/PCbuild/pyproject.props
+--- misc/Python-3.11.15/PCbuild/pyproject.props        2025-01-01 
00:00:00.000000000 +0000
++++ misc/build/Python-3.11.15/PCbuild/pyproject.props  2025-01-01 
00:00:00.000000000 +0000
+@@ -39,6 +39,7 @@
+     <ClCompile>
+       
<AdditionalIncludeDirectories>$(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)PC;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+       
<PreprocessorDefinitions>WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions)</PreprocessorDefinitions>
++      
<ForcedIncludeFiles>aoo_win7_compat.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ 
+       <Optimization>MaxSpeed</Optimization>
+       <IntrinsicFunctions>true</IntrinsicFunctions>
+diff -ruN misc/Python-3.11.15/PCbuild/pythoncore.vcxproj 
misc/build/Python-3.11.15/PCbuild/pythoncore.vcxproj
+--- misc/Python-3.11.15/PCbuild/pythoncore.vcxproj     2025-01-01 
00:00:00.000000000 +0000
++++ misc/build/Python-3.11.15/PCbuild/pythoncore.vcxproj       2025-01-01 
00:00:00.000000000 +0000
+@@ -106,7 +106,7 @@
+       <PreprocessorDefinitions 
Condition="$(IncludeExternals)">_Py_HAVE_ZLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+     </ClCompile>
+     <Link>
+-      
<AdditionalDependencies>version.lib;ws2_32.lib;pathcch.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
++      
<AdditionalDependencies>version.lib;ws2_32.lib;shlwapi.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
+     </Link>
+   </ItemDefinitionGroup>
+   <ItemGroup>
+@@ -473,6 +473,7 @@
+     <ClCompile Include="..\PC\invalid_parameter_handler.c" />
+     <ClCompile Include="..\PC\winreg.c" />
+     <ClCompile Include="..\PC\config.c" />
++    <ClCompile Include="..\PC\pathcch_win7.c" />
+     <ClCompile Include="..\PC\msvcrtmodule.c" />
+     <ClCompile Include="..\Python\pyhash.c" />
+     <ClCompile Include="..\Python\_warnings.c" />
diff --git a/main/sal/systools/win32/uwinapi/makefile.mk 
b/main/sal/systools/win32/uwinapi/makefile.mk
index d81a02fa02..50419c4c8d 100644
--- a/main/sal/systools/win32/uwinapi/makefile.mk
+++ b/main/sal/systools/win32/uwinapi/makefile.mk
@@ -43,6 +43,13 @@ CXXFLAGS+= $(LFS_CFLAGS)
 CFLAGSCXX+=-Wno-unused-parameter -Wno-return-type
 .ENDIF
 
+# The thunks define the psapi entry points under their classic names, which
+# uwinapi.dxp exports.  From _WIN32_WINNT 0x0601 on psapi.h defaults to
+# PSAPI_VERSION 2 and maps GetModuleFileNameExA/W to K32GetModuleFileNameExA/W,
+# so the definitions would land under the K32 names and the export would not
+# resolve (LNK2001).  Callers elsewhere keep the default and bind to kernel32.
+CDEFS+=-DPSAPI_VERSION=1
+
 .IF "$(COMEX)"=="9"
 .IF "$(PSDK_HOME)"!=""
 # Since the 02/2003 PSDK the "new" linker is needed here.
diff --git a/main/solenv/gbuild/platform/windows.mk 
b/main/solenv/gbuild/platform/windows.mk
index 49390ea8f6..3f280ceaef 100644
--- a/main/solenv/gbuild/platform/windows.mk
+++ b/main/solenv/gbuild/platform/windows.mk
@@ -54,9 +54,11 @@ ifneq ($(origin CXX),default)
 gb_CXX := $(CXX)
 endif
 
+# The Windows API floor, Windows 7 SP1 -- the same values as
+# solenv/inc/wntmsci11.mk and wntmscx.mk, see there.
 gb_OSDEFS := \
-       -DWINVER=0x0500 \
-       -D_WIN32_IE=0x0500 \
+       -DWINVER=0x0601 \
+       -D_WIN32_WINNT=0x0601 \
        -DNT351 \
        -DWIN32 \
        -DWNT \
diff --git a/main/solenv/inc/wntmsci11.mk b/main/solenv/inc/wntmsci11.mk
index e926859535..1011d87f57 100644
--- a/main/solenv/inc/wntmsci11.mk
+++ b/main/solenv/inc/wntmsci11.mk
@@ -218,7 +218,18 @@ CFLAGSWERRCC=-WX
 # settings.mk):
 MODULES_WITH_WARNINGS :=
 
-CDEFS+=-D_MT -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0500
+# The Windows API floor: Windows 7 SP1.  Trunk builds only with a VS2015-or-
+# newer toolset (Python 3.11 needs one, and its runtime does not install on
+# anything older than Windows 7 SP1), so the old Windows 2000 values (0x0500)
+# described a platform the result cannot run on.  _WIN32_IE is deliberately not
+# set: the SDK derives it per translation unit from the _WIN32_WINNT that unit
+# ends up with (0x0800 at 0x0601), and a fixed value breaks the files that
+# lower _WIN32_WINNT to NT4 themselves (sal uwinapi, C1189 in sdkddkver.h).
+# A few modules state their own _WIN32_WINNT: fpicker and
+# sal/systools/win32/kill replace it with -U/-D, shell adds a second -D,
+# openssl builds with its own flags.  Python builds with its own project files
+# and gets the same floor from python-3.11.15-win7.patch.
+CDEFS+=-D_MT -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
 .IF "$(COMEX)" == "11"
 _VC_MANIFEST_BASENAME=__VC80
 .ELSE
diff --git a/main/solenv/inc/wntmscx.mk b/main/solenv/inc/wntmscx.mk
index b61b99e574..1d96bccb10 100644
--- a/main/solenv/inc/wntmscx.mk
+++ b/main/solenv/inc/wntmscx.mk
@@ -225,7 +225,18 @@ CFLAGSWERRCC=-WX
 # settings.mk):
 MODULES_WITH_WARNINGS :=
 
-CDEFS+=-D_MT -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0500
+# The Windows API floor: Windows 7 SP1.  Trunk builds only with a VS2015-or-
+# newer toolset (Python 3.11 needs one, and its runtime does not install on
+# anything older than Windows 7 SP1), so the old Windows 2000 values (0x0500)
+# described a platform the result cannot run on.  _WIN32_IE is deliberately not
+# set: the SDK derives it per translation unit from the _WIN32_WINNT that unit
+# ends up with (0x0800 at 0x0601), and a fixed value breaks the files that
+# lower _WIN32_WINNT to NT4 themselves (sal uwinapi, C1189 in sdkddkver.h).
+# A few modules state their own _WIN32_WINNT: fpicker and
+# sal/systools/win32/kill replace it with -U/-D, shell adds a second -D,
+# openssl builds with its own flags.  Python builds with its own project files
+# and gets the same floor from python-3.11.15-win7.patch.
+CDEFS+=-D_MT -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
 .IF "$(COMEX)" == "11"
 _VC_MANIFEST_BASENAME=__VC80
 .ELSE

Reply via email to