alex reboot
alex reboot

Reputation: 1

How can i run this code in Python 3.9 (64-bit)?

When I run the code I get this error:

[WinError 193]% 1 is not a valid Win32 application

    from ctypes import *
    mydll = windll.LoadLibrary(r"C:\Windows\SysWOW64\kernel32.dll")
    mydll.Beep(2000,500)

Upvotes: 0

Views: 604

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177735

TL;DR Use dll = WinDLL('kernel32'). That path is in the default DLL search path.

You have to use 32-bit DLLs with 32-bit Python and 64-bit DLLs with 64-bit Python.

Non-intuitively, C:\Windows\SysWOW64 on 64-bit Windows contains DLLs compatible with 32-bit applications and C:\Windows\System32 contains 64-bit DLLs.

However, whether you are using 32-bit Python or 64-bit Python, always use C:\Windows\System32 if hard-coding the path because for backward compatibility, 32-bit applications originally written for 32-bit Windows will try to open C:\Windows\System32 but if run on 64-bit Windows will automatically redirect the access to C:\Windows\SysWOW64.

Upvotes: 1

Related Questions