HotKeyIt / ahkdll-v2-release

AutoHotkey_H v2 release

Home Page:http://hotkeyit.github.io/v2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to open DLL file

pratibhajagnere opened this issue · 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

FYI, I copied the DLL file in ahk folder.

Is there anything else needs to be done?

do you have a link to the pyahk you used?

I installed it via pip

pip install pyahk

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

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

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

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.

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

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?

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?

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