Code: Select all
#Requires AutoHotkey v2.0
test := IncludeLib("D:\script\Run_V1\OSDTIP.ahk") ;(v1 libs path, AutoHotkey.dll path)
test.OSDTIP_Pop("Notification", "Message", "-2000")
ExitApp
class IncludeLib
{
handle_dll := 0
handle_ahk_func := 0
lib_path := ""
dll_path := ""
__New(lib_path, dll_path := "")
{
this.lib_path := lib_path
this.dll_path := dll_path ? (dll_path) : (A_ScriptDir . "\AutoHotkey.dll")
if (!FileExist(this.dll_path))
{
throw Error("Invalid or missing dynamic link library file", -1, dll_path)
}
try
{
this.handle_dll := DllCall("LoadLibrary", "Str", this.dll_path, "Ptr")
}
catch Any
{
throw Error("Could not load dynamic link library", -1, this.dll_path)
}
DllCall(dll_path . "\ahktextdll", "Str", "#Persistent `n#NoTrayIcon `n#include " . this.lib_path, "Str", "", "Str", "")
this.handle_ahk_func := DllCall("GetProcAddress", "Ptr", this.handle_dll, "AStr", "ahkFunction", "PTR")
}
__Delete()
{
DllCall(this.dll_path . "\ahkExec", "Str", "ExitApp", "CDecl")
DllCall("FreeLibrary", "Ptr", this.handle_dll)
}
__Call(func_name, args*)
{
params := []
params.Push("Str", "")
for index, value in args
{
if (value == "") || (!value)
{
params.Push("Str", "")
continue
}
if (this._TypeOf(value) !== "String")
{
type_of := this._TypeOf(value)
throw Error("Expected a string, got a" . (type_of == "Array" ? "n") . " " . type_of, -1, "args[" . index . "]")
}
params.Push("Str", value)
}
params.Push("CDel Str")
ahk_func := DllCall.Bind(this.handle_ahk_func, params*) ; Should look like: DllCall(this.handle_ahk_func, "Str", "", ("Str", params) ... , "CDel Str")
try
{
return ahk_func(func_name)
}
catch Any as err
{
throw err
}
}
_TypeOf(Value)
{
if ((comClass := ComObjType(Value, "Class")) != "")
{
return comClass
}
try ; `Value is Object` is not checked because it can be false for prototypes.
{
if (ObjHasOwnProp(Value, "__Class"))
{
return "Prototype"
}
}
while (Value := ObjGetBase(Value))
{
if (ObjHasOwnProp(Value, "__Class"))
{
return Value.__Class
}
}
return "Object"
}
}