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
This commit is contained in:
onyx-and-iris 2026-03-19 23:58:20 +00:00
parent 5b4a76c484
commit aae62fa136

View File

@ -1,15 +1,21 @@
import ctypes as ct import ctypes as ct
import platform import platform
import winreg
from pathlib import Path from pathlib import Path
from .errors import NVDAVMError 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': if platform.system() != 'Windows':
raise NVDAVMError('Only Windows OS supported') raise NVDAVMError('Only Windows OS supported')
BITS = 64 if ct.sizeof(ct.c_void_p) == 8 else 32
REG_KEY = '\\'.join( REG_KEY = '\\'.join(
filter( filter(
None, None,
@ -43,4 +49,4 @@ if not controller_path.exists():
DLL_PATH = controller_path / f'x{64 if BITS == 64 else 86}' / 'nvdaControllerClient.dll' 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))