HotKeyIt / ahkdll

AutoHotkey_H
Mozilla Public License 2.0
266 stars 62 forks source link

ahk.ahkgetvar always returns a pointer? #2

Closed kitsu closed 3 years ago

kitsu commented 12 years ago

From Python I try:

>>> import ctypes
>>> ahk = ctypes.cdll.AutoHotKey
>>> ahk.ahktextdll("","","")
816
>>> ahk.ahkassign("test","5")
0
>>> ahk.ahkgetvar("test",0) # As value
39321392
>>> ahk.ahkgetvar("test",1) # As pointer
39321392 # Same value either way
>>> ctypes.cast(int(ahk.ahkgetvar("test", 0)), ctypes.POINTER(ctypes.c_char))
<ctypes.LP_c_char object at 0x01EC7B20>
>>> ans = _ # Result of last operation is stored in a variable named "_"
>>> ans[0]
'5'

I expect ahkgetvar to return the value not a pointer, am I wrong? Using Version 1.1.8.1 AutoHotkey_H ANSI 32-bit (on winXP64, Python2.7 32bit).

Thanks a ton for building this though, it's very helpful!

HotKeyIt commented 12 years ago

ahkgetvar returns always a pointer to a string similar to ahkFunction. ahk.ahkgetvar("test", 1) is only required for LowLevel functions like Alias().

from ctypes import * ahk = cdll.AutoHotKey ahk.ahktextdll("","","") ahk.ahkassign("test","5") print str(cast(ahk.ahkgetvar("test", 0), c_char_p).value)

basiltt commented 4 years ago

Hello HotKeyIt, Seems like print str(cast(ahk.ahkgetvar("test", 0), c_char_p).value) throwing an error. Can you share me the working code for new version. Python version 3.7 AutoHotkey.dll version 1.1.09.01

HotKeyIt commented 4 years ago

Are you using ANSI? Otherwise you will need c_wchar_p. Also what error do you get?