From aae62fa136adeef5fda47859376ac48c4502aecd Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 19 Mar 2026 23:58:20 +0000 Subject: [PATCH] the platform check is mostly redundant since `import winreg` will already have failed on most python installations. Instead wrap `import winreg` and raise NVDAVMError switch to ct.WinDLL which is more appropriate for C APIs using the stdcall convention --- src/nvda_voicemeeter/cdll.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/nvda_voicemeeter/cdll.py b/src/nvda_voicemeeter/cdll.py index 8dc4e31..bb823bc 100644 --- a/src/nvda_voicemeeter/cdll.py +++ b/src/nvda_voicemeeter/cdll.py @@ -1,15 +1,21 @@ import ctypes as ct import platform -import winreg from pathlib import Path from .errors import NVDAVMError -BITS = 64 if ct.sizeof(ct.c_void_p) == 8 else 32 +try: + import winreg +except ImportError as e: + ERR_MSG = 'winreg module not found, only Windows OS supported' + raise NVDAVMError(ERR_MSG) from e +# Defense against edge cases where winreg imports but we're not on Windows if platform.system() != 'Windows': raise NVDAVMError('Only Windows OS supported') +BITS = 64 if ct.sizeof(ct.c_void_p) == 8 else 32 + REG_KEY = '\\'.join( filter( None, @@ -43,4 +49,4 @@ if not controller_path.exists(): DLL_PATH = controller_path / f'x{64 if BITS == 64 else 86}' / 'nvdaControllerClient.dll' -libc = ct.CDLL(str(DLL_PATH)) +libc = ct.WinDLL(str(DLL_PATH))