ahkdll-v2-release icon indicating copy to clipboard operation
ahkdll-v2-release copied to clipboard

Not able to open DLL file

Open pratibhajagnere opened this issue 7 years ago • 11 comments

Hi,

I am trying to use the AutoHotKey.dll from pyahk but when i am opening it using ctypes, I am getting below error

ctypes.cdll.LoadLibrary("C:\\Python27\\Lib\\site-packages\\ahk\\AutoHotKey32w.dll")



Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ctypes.cdll.LoadLibrary("C:\\Python27\\Lib\\site-packages\\ahk\\AutoHotKey32w.dll")
  File "C:\Python27\lib\ctypes\__init__.py", line 440, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application

I tried both 32w and x64w. Below is my environment configuration:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32

Windows 10 - 64 bit

pratibhajagnere avatar Sep 22 '17 08:09 pratibhajagnere

FYI, I copied the DLL file in ahk folder.

Is there anything else needs to be done?

pratibhajagnere avatar Sep 22 '17 12:09 pratibhajagnere

do you have a link to the pyahk you used?

HotKeyIt avatar Sep 22 '17 18:09 HotKeyIt

I installed it via pip

pip install pyahk

pratibhajagnere avatar Sep 23 '17 10:09 pratibhajagnere

There seems to be something wrong with your configuration and afaik you are not even using pyahk: %1 is not a valid Win32 application This means the parameter passed were wrong, it works fine for me in Portable Python 2.7.6.1

HotKeyIt avatar Sep 23 '17 11:09 HotKeyIt

I was facing error in pyahk hence I nailed it down to the point where it was trying to run the given command. If I directly run below command in IDLE CLI, I will still get the error,

>>> import ctypes
>>> ctypes.cdll.LoadLibrary("C:\\Python27\\Lib\\site-packages\\ahk\\AutoHotKey32w.dll")

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    ctypes.cdll.LoadLibrary("C:\\Python27\\Lib\\site-packages\\ahk\\AutoHotKey32w.dll")
  File "C:\Python27\lib\ctypes\__init__.py", line 440, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application

pratibhajagnere avatar Sep 23 '17 13:09 pratibhajagnere

Can you download current dll and try: import ctypes ctypes.cdll.LoadLibrary("C:\\AutoHotKey.dll")

HotKeyIt avatar Sep 24 '17 08:09 HotKeyIt

Hello. I had the same issue. The only difference is that I use python 3 (Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32). Tried with the shown example and it works fine with the x64w version of the dll. But, if I use ahktextdll function, python stops working. Here is the code I'm trying: ` import ctypes ahk = ctypes.cdll.LoadLibrary("C:\windows\system32\AutoHotkey.dll") ahk.ahktextdll(u"") while not ahk.ahkReady(): time.sleep(0.01)

script = u""" Init(){ SendMode Play SetWorkingDir C:/PWX/ if (ErrorLevel <> 0) { return deu ruim } SetTitleMatchMode, 2 return %A_WorkingDir% } """ ahk.addScript(script) r = ctypes.cast(ahk.ahkFunction(u"Init"), ctypes.c_wchar_p).value print(r) ` Is there something different I should use? When using the same script in 32 bit windows it works fine.

andreguilhon avatar Jun 11 '18 20:06 andreguilhon

ahk.ahktextdll(u"#Persistent") Or skip it and while loop and do directly ahk.ahktextdll(script)

HotKeyIt avatar Jun 11 '18 22:06 HotKeyIt

Thank you for your quick response! I did try what you told, but with no luck. Both of them give me the Python Stopped Working window.. (Print bellow) image

Could you provide a full example so I could test and make sure I did not do anything wrong?

andreguilhon avatar Jun 12 '18 11:06 andreguilhon

Just did a quick test. Installed 32 bit version of python, called the same scripts, with both the Win32w and the x64w versions of the DLL. Both worked just fine. Does that give any clue to the problem?

andreguilhon avatar Jun 12 '18 12:06 andreguilhon

I'm running into this same issue using 64-bit Python.

prurph avatar Jul 25 '18 00:07 prurph