diff --git a/src/_native/helpers.cpp b/src/_native/helpers.cpp index b81bfc9..4d59aa4 100644 --- a/src/_native/helpers.cpp +++ b/src/_native/helpers.cpp @@ -51,6 +51,15 @@ void err_SetFromWindowsErrWithMessage(int error, const char *message, const wcha cause = PyErr_GetRaisedException(); } + if ((error & 0xFFFF0000) == 0x80070000) { + // Error code is an HRESULT containing a regular Windows error + error &= 0xFFFF; + } + if (!hModule && error >= 12000 && error <= 12184) { + // Error codes are from WinHTTP, which means we need a module + hModule = GetModuleHandleW(L"winhttp"); + } + if (!os_message) { DWORD len = FormatMessageW( /* Error API error */ diff --git a/tests/conftest.py b/tests/conftest.py index d475ad5..6d99e0b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,8 @@ if k[:1] not in ("", "_"): setattr(_native, k, getattr(_native_test, k)) +_native.coinitialize() + # Importing in order carefully to ensure the variables we override are handled # correctly by submodules. diff --git a/tests/test_shortcut.py b/tests/test_shortcut.py index a965160..1243ff7 100644 --- a/tests/test_shortcut.py +++ b/tests/test_shortcut.py @@ -7,7 +7,6 @@ def test_simple_shortcut(tmp_path): open(tmp_path / "target.txt", "wb").close() - _native.coinitialize() _native.shortcut_create( tmp_path / "test.lnk", tmp_path / "target.txt", @@ -17,7 +16,6 @@ def test_simple_shortcut(tmp_path): def test_start_path(): - _native.coinitialize() p = Path(_native.shortcut_get_start_programs()) assert p.is_dir() diff --git a/tests/test_urlutils.py b/tests/test_urlutils.py index 14e5986..e78769e 100644 --- a/tests/test_urlutils.py +++ b/tests/test_urlutils.py @@ -227,7 +227,7 @@ def inject_error(): def test_bits_errors(localserver, tmp_path, inject_error): import uuid - ERROR_MR_MID_NOT_FOUND = 0x8007013D + ERROR_MR_MID_NOT_FOUND = 0x13D dest = tmp_path / "read.txt" url = localserver + "/128kb"