Skip to content

Commit

Permalink
Remove old Windows version macros and set _WIN32_WINNT+WINVER from se…
Browse files Browse the repository at this point in the history
…tup.py
  • Loading branch information
Avasam committed Oct 27, 2024
1 parent 14df895 commit 81d2fd5
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 184 deletions.
6 changes: 0 additions & 6 deletions Pythonwin/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

#define WIN32_LEAN_AND_MEAN

#ifndef WINVER
// we don't need this, but vs2009 makes noise without it set to something -
// and this is what we currently use...
#define WINVER 0x0600
#endif

#define _USING_V110_SDK71_
// MFC support for mbcs is going away, but no need for us to constantly be told...
#define NO_WARN_MBCS_MFC_DEPRECATION
Expand Down
1 change: 0 additions & 1 deletion com/TestSources/PyCOMTest/preconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// or project specific include files that are used frequently,
// but are changed infrequently

#define _WIN32_WINNT 0x0403
#define _WIN32_DCOM

#include <atlbase.h>
Expand Down
1 change: 0 additions & 1 deletion com/win32com/src/include/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// so we don't lose all the constants etc that come with DCOM
//
#define _WIN32_DCOM
#define _WIN32_WINNT 0x0501 // we use some of these features.

// objidl.h checks for this to define IContext and IEnumContextProps
#define USE_COM_CONTEXT_DEF
Expand Down
20 changes: 4 additions & 16 deletions com/win32comext/shell/src/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2532,15 +2532,15 @@ static PyObject *PyShellExecuteEx(PyObject *self, PyObject *args, PyObject *kw)

static char *kw_items[] = {
"fMask", "hwnd", "lpVerb", "lpFile", "lpParameters", "lpDirectory", "nShow",
"lpIDList", "lpClass", "hkeyClass", "dwHotKey", "hIcon", "hMonitor", NULL,
"lpIDList", "lpClass", "hkeyClass", "dwHotKey", "hMonitor", NULL,
};
PyObject *obhwnd = Py_None, *obVerb = NULL, *obFile = NULL, *obParams = NULL;
PyObject *obDirectory = NULL, *obIDList = NULL, *obClass = NULL;
PyObject *obhkeyClass = NULL, *obHotKey = NULL, *obhIcon = NULL;
PyObject *obhMonitor = NULL;
PyObject *obhkeyClass = NULL, *obHotKey = NULL, PyObject *obhMonitor = NULL;
// @pyparm int|fMask|0|The default mask for the structure. Other
// masks may be added based on what paramaters are supplied.
if (!PyArg_ParseTupleAndKeywords(args, kw, "|lOOOOOlOOOOOO", kw_items, &info.fMask,
if (!PyArg_ParseTupleAndKeywords(args, kw, "|lOOOOOlOOOOO", kw_items,
&info.fMask, // @pyparm int|fMask|0|
&obhwnd, // @pyparm <o PyHANDLE>|hwnd|0|
&obVerb, // @pyparm string|lpVerb||
&obFile, // @pyparm string|lpFile||
Expand All @@ -2551,7 +2551,6 @@ static PyObject *PyShellExecuteEx(PyObject *self, PyObject *args, PyObject *kw)
&obClass, // @pyparm string|obClass||
&obhkeyClass, // @pyparm int|hkeyClass||
&obHotKey, // @pyparm int|dwHotKey||
&obhIcon, // @pyparm <o PyHANDLE>|hIcon||
&obhMonitor)) // @pyparm <o PyHANDLE>|hMonitor||
goto done;
if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&info.hwnd))
Expand Down Expand Up @@ -2585,17 +2584,6 @@ static PyObject *PyShellExecuteEx(PyObject *self, PyObject *args, PyObject *kw)
if (PyErr_Occurred())
goto done;
}
if (obhIcon) {
// SEE_MASK_ICON is defined around 'if (NTDDI_VERSION < NTDDI_LONGHORN)' and commented as 'not used'
#ifndef SEE_MASK_ICON
PyErr_SetString(PyExc_NotImplementedError, "SEE_MASK_ICON not declared on this platform");
goto done;
#else
info.fMask |= SEE_MASK_ICON;
if (!PyWinObject_AsHANDLE(obhIcon, &info.hIcon))
goto done;
#endif
}
if (obhMonitor) {
info.fMask |= SEE_MASK_HMONITOR;
if (!PyWinObject_AsHANDLE(obhMonitor, &info.hMonitor))
Expand Down
21 changes: 15 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,26 @@ def __init__(
if export_symbol_file:
extra_link_args.append("/DEF:" + export_symbol_file)

self.windows_h_version = windows_h_version or 0x600 # Vista

# Some of our swigged files behave differently in distutils vs
# MSVC based builds. Always define DISTUTILS_BUILD so they can tell.
define_macros = define_macros or []
define_macros.append(("DISTUTILS_BUILD", None))
define_macros.append(("_CRT_SECURE_NO_WARNINGS", None))
# CRYPT_DECRYPT_MESSAGE_PARA.dwflags is in an ifdef for some unknown reason
# See github PR #1444 for more details...
define_macros.append(("CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS", None))
define_macros.extend(
(
("DISTUTILS_BUILD", None),
("_CRT_SECURE_NO_WARNINGS", None),
# CRYPT_DECRYPT_MESSAGE_PARA.dwflags is in an ifdef for some unknown reason
# See github PR #1444 for more details...
("CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS", None),
# Minimum Windows version supported
# https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
("_WIN32_WINNT", windows_h_version),
("WINVER ", windows_h_version),
)
)
self.pch_header = pch_header
self.extra_swig_commands = extra_swig_commands or []
self.windows_h_version = windows_h_version
self.optional_headers = optional_headers
self.is_regular_dll = is_regular_dll
self.base_address = base_address
Expand Down
6 changes: 0 additions & 6 deletions win32/Lib/win32con.py
Original file line number Diff line number Diff line change
Expand Up @@ -4247,10 +4247,8 @@ def GetBValue(rgb):
# winuser.h line 4249
KEYEVENTF_EXTENDEDKEY = 1
KEYEVENTF_KEYUP = 2
# if(_WIN32_WINNT >= 0x0500)
KEYEVENTF_UNICODE = 4
KEYEVENTF_SCANCODE = 8
# endif /* _WIN32_WINNT >= 0x0500 */
MOUSEEVENTF_MOVE = 1
MOUSEEVENTF_LEFTDOWN = 2
MOUSEEVENTF_LEFTUP = 4
Expand All @@ -4261,12 +4259,8 @@ def GetBValue(rgb):
MOUSEEVENTF_XDOWN = 128
MOUSEEVENTF_XUP = 256
MOUSEEVENTF_WHEEL = 2048
# if (_WIN32_WINNT >= 0x0600)
MOUSEEVENTF_HWHEEL = 4096
# endif
# if(WINVER >= 0x0600)
MOUSEEVENTF_MOVE_NOCOALESCE = 8192
# endif /* WINVER >= 0x0600 */
MOUSEEVENTF_VIRTUALDESK = 16384
MOUSEEVENTF_ABSOLUTE = 32768
INPUT_MOUSE = 0
Expand Down
13 changes: 1 addition & 12 deletions win32/src/PyACL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,13 @@ BOOL PyWinObject_AsTRUSTEE(PyObject *obtrustee, TRUSTEE_W *ptrustee)
}
break;
}
#if WINVER >= 0x0501
case TRUSTEE_IS_OBJECTS_AND_SID:
case TRUSTEE_IS_OBJECTS_AND_NAME: {
// still need to add TRUSTEE_IS_OBJECTS_AND_SID and TRUSTEE_IS_OBJECTS_AND_NAME
PyErr_SetString(PyExc_NotImplementedError, "TrusteeForm not yet supported");
bsuccess = FALSE;
break;
}
#else
#pragma message( \
"NOTE: You are building with an early Platform SDK - not all" \
"TRUSTEE operations on SIDs will be supported")
#endif // WINVER
default: {
PyErr_SetString(PyExc_ValueError, "Invalid value for TrusteeForm");
bsuccess = FALSE;
Expand All @@ -298,13 +292,11 @@ PyObject *PyWinObject_FromTRUSTEE(TRUSTEE_W *ptrustee)
obIdentifier = PyWinObject_FromWCHAR(ptrustee->ptstrName);
break;
}
#if WINVER >= 0x0501
case TRUSTEE_IS_OBJECTS_AND_SID:
case TRUSTEE_IS_OBJECTS_AND_NAME: {
PyErr_SetString(PyExc_NotImplementedError, "TrusteeForm not yet supported");
return FALSE;
}
#endif
default: {
PyErr_SetString(PyExc_ValueError, "Invalid value for TrusteeForm");
return FALSE;
Expand Down Expand Up @@ -964,10 +956,7 @@ PyObject *PyACL::GetAce(PyObject *self, PyObject *args)
case ACCESS_ALLOWED_ACE_TYPE:
case ACCESS_DENIED_ACE_TYPE:
case SYSTEM_AUDIT_ACE_TYPE:
#ifdef _WIN32_WINNT_LONGHORN
case SYSTEM_MANDATORY_LABEL_ACE_TYPE:
#endif
{
case SYSTEM_MANDATORY_LABEL_ACE_TYPE: {
ACCESS_ALLOWED_ACE *pAce = (ACCESS_ALLOWED_ACE *)p;
return Py_BuildValue("(ll)lN", pAceHeader->AceType, pAceHeader->AceFlags, pAce->Mask,
PyWinObject_FromSID((PSID)(&pAce->SidStart)));
Expand Down
5 changes: 0 additions & 5 deletions win32/src/PythonService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ static void CheckRegisterEventSourceFile();
// increased to MAX_SERVICES
DWORD g_maxServices = 1;

#if (WINVER < 0x0500)
// SDK probably doesn't define LPHANDLER_FUNCTION_EX, so do it ourselves.
typedef DWORD(WINAPI *LPHANDLER_FUNCTION_EX)(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext);
#endif

typedef SERVICE_STATUS_HANDLE(WINAPI *REGSVC_EX_FN)(LPCTSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc,
LPVOID lpContext);

Expand Down
4 changes: 0 additions & 4 deletions win32/src/_winxptheme.i
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
%include "pywintypes.i"

%{
#define _WIN32_WINNT 0x0501

#undef PyHANDLE
#include "pywinobjects.h"
#include "windows.h"
#include "Uxtheme.h"
#include "commctrl.h"


%}

// @object PyHTHEME|A <o PyHANDLE> object wrapping a HTHEME.
Expand Down
6 changes: 0 additions & 6 deletions win32/src/win32apimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ generates Windows .hlp files.
#define PyW32_END_ALLOW_THREADS PyEval_RestoreThread(_save);
#define PyW32_BLOCK_THREADS Py_BLOCK_THREADS

#if (_WIN32_WINNT < 0x0500)
// We don't get COMPUTER_NAME_FORMAT unless we bump this.
// As we use it dynamically, we don't *need* to bump it.
typedef int COMPUTER_NAME_FORMAT;
#endif

// from kernel32.dll
typedef BOOL(WINAPI *GetComputerNameExfunc)(COMPUTER_NAME_FORMAT, LPWSTR, PULONG);
static GetComputerNameExfunc pfnGetComputerNameEx = NULL;
Expand Down
6 changes: 0 additions & 6 deletions win32/src/win32consolemodule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @doc
#define _WIN32_WINNT 0x501
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "structmember.h"
Expand Down Expand Up @@ -941,11 +940,6 @@ PyObject *PyConsoleScreenBuffer::PySetConsoleMode(PyObject *self, PyObject *args
return Py_None;
}

#ifndef _WIN32_WINNT_LONGHORN
// 'reserved' ReadConsole param is defined as a PCONSOLE_READCONSOLE_CONTROL
// in Vista's SDK. If no such def exists, assume it's still 'void *'
#define PCONSOLE_READCONSOLE_CONTROL void *
#endif
// @pymethod <o PyUNICODE>|PyConsoleScreenBuffer|ReadConsole|Reads characters from the console input buffer
PyObject *PyConsoleScreenBuffer::PyReadConsole(PyObject *self, PyObject *args, PyObject *kwargs)
{
Expand Down
1 change: 0 additions & 1 deletion win32/src/win32credmodule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @doc
#define _WIN32_WINNT 0x501 // Credentials functions only available on WinXP
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "WinCred.h"
Expand Down
1 change: 0 additions & 1 deletion win32/src/win32crypt/win32cryptmodule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @doc
#define _WIN32_WINNT 0x502
#include "win32crypt.h"

// @pymethod bytes|win32crypt|CryptProtectData|Encrypts data using a session key derived from current user's logon
Expand Down
5 changes: 0 additions & 5 deletions win32/src/win32file.i
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
// <nl>RemoveDirectory / RemoveDirectoryTransacted

%{
//#define FAR
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif

// We use the deprecated API
#define _WINSOCK_DEPRECATED_NO_WARNINGS

Expand Down
4 changes: 0 additions & 4 deletions win32/src/win32gui.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

%module win32gui // A module which provides an interface to the native win32 GUI API.

%{
#define _WIN32_WINNT 0x0501

%}
%include "typemaps.i"
%include "pywintypes.i"

Expand Down
4 changes: 0 additions & 4 deletions win32/src/win32job.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
// available in Windows 2000 and later.

%{
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x500
#endif

#include "PyWinTypes.h"

#define CHECK_PFN(fname)if (pfn##fname==NULL) return PyErr_Format(PyExc_NotImplementedError,"%s is not available on this platform", #fname);
Expand Down
3 changes: 0 additions & 3 deletions win32/src/win32net/win32net.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ PyObject *PyDoDel(PyObject *self, PyObject *args, PFNDEL pfn, char *fnname);

PyObject *PyDoGroupDelMembers(PyObject *self, PyObject *args);

#if WINVER >= 0x0500
typedef NET_API_STATUS(NET_API_FUNCTION *NetValidateNamefunc)(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, NETSETUP_NAME_TYPE);
extern "C" NetValidateNamefunc pfnNetValidateName;

Expand All @@ -73,5 +72,3 @@ extern "C" NetValidatePasswordPolicyfunc pfnNetValidatePasswordPolicy;

typedef NET_API_STATUS(NET_API_FUNCTION *NetValidatePasswordPolicyFreefunc)(LPVOID *);
extern "C" NetValidatePasswordPolicyFreefunc pfnNetValidatePasswordPolicyFree;

#endif // WINVER
4 changes: 0 additions & 4 deletions win32/src/win32net/win32netmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,6 @@ PyObject *PyNetServerComputerNameDel(PyObject *self, PyObject *args)
return ret;
}

#if WINVER >= 0x0500

extern "C" NetValidateNamefunc pfnNetValidateName = NULL;
// @pymethod |win32net|NetValidateName|Checks that domain/machine/workgroup name is valid for given context
// @rdesc Returns none if valid, exception if not
Expand Down Expand Up @@ -1652,5 +1650,3 @@ PyObject *PyNetValidatePasswordPolicy(PyObject *self, PyObject *args)
(*pfnNetValidatePasswordPolicyFree)((void **)&out_arg);
return ret;
}

#endif // WINVER
11 changes: 0 additions & 11 deletions win32/src/win32net/win32netmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ conversion is required.

#include "assert.h"

#if WINVER >= 0x0500
NetGetJoinInformationfunc pfnNetGetJoinInformation = NULL;
#endif

/*****************************************************************************/
/* error helpers */
Expand Down Expand Up @@ -946,8 +944,6 @@ PyObject *PyNetGetAnyDCName(PyObject *self, PyObject *args)
return ret;
}

#if WINVER >= 0x0500

// @pymethod <o PyUnicode>, int|win32net|NetGetJoinInformation|Retrieves join status information for the specified
// computer.
static PyObject *PyNetGetJoinInformation(PyObject *self, PyObject *args)
Expand Down Expand Up @@ -979,7 +975,6 @@ static PyObject *PyNetGetJoinInformation(PyObject *self, PyObject *args)
NetApiBufferFree(result);
return ret;
}
#endif // WINVER

/*************************************************************************************************************
**
Expand Down Expand Up @@ -1059,10 +1054,8 @@ extern PyObject *PyNetServerComputerNameDel(PyObject *self, PyObject *args);
/* List of functions exported by this module */
// @module win32net|A module encapsulating the Windows Network API.
static struct PyMethodDef win32net_functions[] = {
#if WINVER >= 0x0500
{"NetGetJoinInformation", PyNetGetJoinInformation,
1}, // @pymeth NetGetJoinInformation|Retrieves join status information for the specified computer.
#endif
{"NetGroupGetInfo", PyNetGroupGetInfo,
1}, // @pymeth NetGroupGetInfo|Retrieves information about a particular group on a server.
{"NetGroupGetUsers", PyNetGroupGetUsers, 1}, // @pymeth NetGroupGetUsers|Enumerates the users in a group.
Expand Down Expand Up @@ -1180,13 +1173,11 @@ static struct PyMethodDef win32net_functions[] = {
{"NetServerComputerNameDel", PyNetServerComputerNameDel,
1}, // @pymeth NetServerComputerNameDel|Deletes an emulated computer name created by <om
// win32net.PyNetServerComputerNameAdd>
#if WINVER >= 0x0500
{"NetValidateName", PyNetValidateName,
1}, // @pymeth NetValidateName|Verify that computer/domain name is valid for given context
{"NetValidatePasswordPolicy", PyNetValidatePasswordPolicy,
1}, // @pymeth NetValidatePasswordPolicy|Allows an application to check password compliance against an
// application-provided account database.
#endif
{NULL, NULL}};

static void AddConstant(PyObject *dict, char *name, long val)
Expand All @@ -1212,7 +1203,6 @@ PYWIN_MODULE_INIT_FUNC(win32net)
AddConstant(dict, "USE_LOTS_OF_FORCE", USE_LOTS_OF_FORCE);

HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("netapi32.dll");
#if WINVER >= 0x0500
if (hmodule != NULL) {
pfnNetValidateName = (NetValidateNamefunc)GetProcAddress(hmodule, "NetValidateName");
pfnNetGetJoinInformation = (NetGetJoinInformationfunc)GetProcAddress(hmodule, "NetGetJoinInformation");
Expand All @@ -1221,6 +1211,5 @@ PYWIN_MODULE_INIT_FUNC(win32net)
pfnNetValidatePasswordPolicyFree =
(NetValidatePasswordPolicyFreefunc)GetProcAddress(hmodule, "NetValidatePasswordPolicyFree");
}
#endif
PYWIN_MODULE_INIT_RETURN_SUCCESS;
}
Loading

0 comments on commit 81d2fd5

Please sign in to comment.