- ahkassign is not returning a -1 or 0 status code to indicate success/failure.
- I can't tell if ahkgetvar is reading from an initialized variable or hitting an error if the variable I'm trying to read does not exist.
Code: Select all
public interface AutoHotkeyDllLibrary extends Library {
public Pointer ahktextdll(WString script, WString parameters, WString title);
public Pointer ahkassign(WString varname, WString value);
public Pointer ahkgetvar(WString varname, WString getpointer);
public Pointer ahkFunction(WString f, WString p1, WString p2, WString p3, WString p4, WString p5, WString p6, WString p7, WString p8, WString p9, WString p10);
public Pointer ahkExec(WString s);
}
public static void main(final String[] args) {
// ### Init ###
final AutoHotkeyDllLibrary ahkLib = Native.load("AutoHotkey.dll", AutoHotkeyDllLibrary.class);
final Pointer newAhkThread = ahkLib.ahktextdll(null, null, null);
Objects.requireNonNull(newAhkThread);
// ### Try to initialize and get a variable using the dll's methods ###
final Pointer assignResult = ahkLib.ahkassign(new WString("varX"), new WString("123")); // also tried "\"123\"" and got the same results
// commented out because the returned pointer is null.
// but the documentation of ahkassign says it should return -1 on failure and 0 on success.
// Objects.requireNonNull(assignResult);
final Pointer getResult1 = ahkLib.ahkgetvar(new WString("varX"), new WString("1"));
// this returns some random number. there is no warning or error
System.out.println(getResult1.getWideString(0));
final Pointer getResult0 = ahkLib.ahkgetvar(new WString("varX"), new WString("0"));
// this returns some random number. there is no warning or error
System.out.println(getResult0.getWideString(0));
// ### Try to initialize and get a variable using ahkExec ###
// commented out because this stops the succeeding ahkFunction call from running
// ahkLib.ahkExec(new WString("varX := \"123\""));
// ### Hit an error when trying to use an output variable in a function call ###
// the function call emits an AutoHotkey warning: "Parameter#1 of WinGetClientPos must be a variable."
ahkLib.ahkFunction(
new WString("WinGetClientPos"),
new WString("varX"), new WString("varY"), new WString("varW"), new WString("varH"), new WString("ahk_exe notepad.exe"),
null, null, null, null, null
);
}