OSError: [WinError 193] %1 is not a valid Win32 application when using ctypes


i am trying to use kernal32 dll and use functions from it. when trying to do that, i got the error.

Traceback (most recent call last):
  File "C:\Users\Tawfiq\Desktop\2D render\win32.py", line 2, in <module>
    mydll = cdll.LoadLibrary(r"C:\Windows\SysWOW64\kernel32.dll")
  File "C:\Program Files\Python39\lib\ctypes\__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "C:\Program Files\Python39\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

this is the code i am executing:

from ctypes import*
mydll = cdll.LoadLibrary(r"C:\Windows\SysWOW64\kernel32.dll")


c:\windows\syswow64 contains 32-bit DLLs. Your Python path is c:\Program Files which is the 64-bit Python installation location. You can’t mix.

Don’t hard-code the path. Just use mydll = WinDLL('kernel32') and Windows will search the correct standard location for the Python running (32- or 64-bit).

Answered By – Mark Tolonen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published