Skip to content

Commit 491b2ae

Browse files
committed
gh-152433: Windows: _ctypes module: improve UWP compatibility
1 parent b52bc56 commit 491b2ae

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``_ctypes`` module: improve UWP compatibility.

Modules/_ctypes/callproc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,7 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...)
10821082
}
10831083

10841084

1085-
#ifdef MS_WIN32
1086-
1085+
#ifdef MS_WINDOWS_DESKTOP
10871086
static PyObject *
10881087
GetComError(ctypes_state *st, HRESULT errcode, GUID *riid, IUnknown *pIunk)
10891088
{
@@ -1337,9 +1336,11 @@ PyObject *_ctypes_callproc(ctypes_state *st,
13371336

13381337
#ifdef MS_WIN32
13391338
if (iid && pIunk) {
1339+
#ifdef MS_WINDOWS_DESKTOP
13401340
if (*(int *)resbuf & 0x80000000)
13411341
retval = GetComError(st, *(HRESULT *)resbuf, iid, pIunk);
13421342
else
1343+
#endif
13431344
retval = PyLong_FromLong(*(int *)resbuf);
13441345
} else if (flags & FUNCFLAG_HRESULT) {
13451346
if (*(int *)resbuf & 0x80000000)
@@ -1417,10 +1418,14 @@ static PyObject *load_library(PyObject *self, PyObject *args)
14171418
return NULL;
14181419

14191420
Py_BEGIN_ALLOW_THREADS
1421+
#ifndef MS_WINDOWS_DESKTOP
1422+
hMod = LoadPackagedLibrary(name, 0);
1423+
#else
14201424
/* bpo-36085: Limit DLL search directories to avoid pre-loading
14211425
* attacks and enable use of the AddDllDirectory function.
14221426
*/
14231427
hMod = LoadLibraryExW(name, NULL, (DWORD)load_flags);
1428+
#endif
14241429
err = hMod ? 0 : GetLastError();
14251430
Py_END_ALLOW_THREADS
14261431

0 commit comments

Comments
 (0)