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 (#2422)
  • Loading branch information
Avasam authored Dec 23, 2024
1 parent f4bf147 commit e8743ad
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 167 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
18 changes: 13 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ def __init__(
# 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 (Vista)
# https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
("_WIN32_WINNT", hex(0x0600)),
("WINVER", hex(0x0600)),
)
)
self.pch_header = pch_header
self.extra_swig_commands = extra_swig_commands or []
self.optional_headers = optional_headers
Expand Down
6 changes: 0 additions & 6 deletions win32/Lib/win32con.py
Original file line number Diff line number Diff line change
Expand Up @@ -4248,10 +4248,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 @@ -4262,12 +4260,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;
}
8 changes: 0 additions & 8 deletions win32/src/win32rasmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ generates Windows .hlp files.

******************************************************************/

#ifndef WINVER
#define WINVER 0x500
#endif

#include "pywintypes.h"
#include "ras.h"
#include "raserror.h"
Expand Down Expand Up @@ -285,7 +281,6 @@ PyObject *PyRASDIALEXTENSIONS::getattro(PyObject *self, PyObject *obname)
// @prop integer|reserved|
if (strcmp(name, "reserved") == 0)
return PyWinObject_FromULONG_PTR(py->m_ext.reserved);
#if (WINVER >= 0x500)
// @prop integer|reserved1|
if (strcmp(name, "reserved1") == 0)
return PyWinObject_FromULONG_PTR(py->m_ext.reserved1);
Expand All @@ -294,7 +289,6 @@ PyObject *PyRASDIALEXTENSIONS::getattro(PyObject *self, PyObject *obname)
Py_INCREF(py->m_pyeap);
return py->m_pyeap;
}
#endif
return PyObject_GenericGetAttr(self, obname);
}

Expand Down Expand Up @@ -329,7 +323,6 @@ int PyRASDIALEXTENSIONS::setattro(PyObject *self, PyObject *obname, PyObject *va
py->m_ext.reserved = v;
return 0;
}
#if (WINVER >= 0x500)
if (strcmp(name, "reserved1") == 0) {
long v = PyLong_AsLong(val);
if (v == -1 && PyErr_Occurred())
Expand All @@ -348,7 +341,6 @@ int PyRASDIALEXTENSIONS::setattro(PyObject *self, PyObject *obname, PyObject *va
Py_INCREF(val);
return 0;
}
#endif
return PyObject_GenericSetAttr(self, obname, val);
}

Expand Down
Loading

0 comments on commit e8743ad

Please sign in to comment.