I'm a beginner in AHK and I'm trying to call an AHK script from C++ code using the AHK DLL.
I have this AHK script file "MyScript.ahk" :
Code: Select all
#NoEnv
SetBatchLines -1
ListLines Off
#NoTrayIcon
MyVar:="test3"
Code: Select all
typedef int(*AhkDll)(wchar_t *, wchar_t *, wchar_t *);
typedef int(*AhkReady)();
typedef int(*AhkAssign)(wchar_t *, wchar_t *);
typedef wchar_t*(*AhkGetVar)(wchar_t *, UINT);
//...
wchar_t* l_sRes = NULL;
// Load AHK DLL file
HINSTANCE l_hAutoHotKeyLibrary = LoadLibrary(_T("AutoHotkey.dll"));
if (l_hAutoHotKeyLibrary != NULL)
{
// Get function pointer
AhkDll l_hAutoHotKeyDLL = (AhkDll)GetProcAddress(l_hAutoHotKeyLibrary, "ahkdll");
AhkReady l_hAutoHotKeyReady = (AhkReady)GetProcAddress(l_hAutoHotKeyLibrary, "ahkReady");
AhkAssign l_hAutoHotKeyAssign = (AhkAssign)GetProcAddress(l_hAutoHotKeyLibrary, "ahkassign");
AhkGetVar l_hAutoHotKeyGetVar = (AhkGetVar)GetProcAddress(l_hAutoHotKeyLibrary, "ahkgetvar");
if ((l_hAutoHotKeyDLL != NULL) && (l_hAutoHotKeyReady != NULL) && (l_hAutoHotKeyAssign != NULL) && (l_hAutoHotKeyGetVar != NULL))
{
l_hAutoHotKeyAssign(_T("MyVar"), _T("test1"));
l_sRes = l_hAutoHotKeyGetVar(_T("MyVar"), 0); // l_sRes = NULL
l_hAutoHotKeyDLL(_T("MyScript.ahk"), _T(""), _T(""));
l_sRes = l_hAutoHotKeyGetVar(_T("MyVar"), 0); // l_sRes = ""
l_hAutoHotKeyAssign(_T("MyVar"), _T("test2"));
l_sRes = l_hAutoHotKeyGetVar(_T("MyVar"), 0); // l_sRes = "test2"
while (l_hAutoHotKeyReady())
Sleep(50);
l_sRes = l_hAutoHotKeyGetVar(_T("MyVar"), 0); // l_sRes = NULL
}
}
These results are very strange, Does someone can explain me how it exactly works?
The thing I want to do is to get the value from the script (here, "test3") to use it into my C++ code.
Thanks,
Alex.