A problem of using calling V1's libs in V2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

A problem of using calling V1's libs in V2

Post by songdg » 15 May 2024, 22:39

A problem of using calling V1's libs in V2viewtopic.php?f=83&t=95656, use viv's code without any problem, but I try Delta Pythagorean's modified code encounter this problem D:\script\Run_V1\call_OSDTIP.ahk (60) : ==> A "?" is missing its ":"

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"
	}
}

User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: A problem of using calling V1's libs in V2

Post by boiler » 16 May 2024, 02:20

To address that error, replace (type_of == "Array" ? "n") with (type_of == "Array" ? "n" : "") on line 60.

songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: A problem of using calling V1's libs in V2

Post by songdg » 16 May 2024, 02:42

Thanks, there's another problem, Error: Failed to load DLL., and I have already replace DllCall(dll_path . "\ahktextdll", "Str", "#Persistent `n#NoTrayIcon `n#include " . this.lib_path, "Str", "", "Str", "") with DllCall(dll_path "\ahktextdll", "Str", "#Persistent `n#NoTrayIcon `n#include " . lib_path, "Str", "", "Str", "")

User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: A problem of using calling V1's libs in V2

Post by boiler » 16 May 2024, 03:06

What is the reason for removing this.?

songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: A problem of using calling V1's libs in V2

Post by songdg » 16 May 2024, 04:04

boiler wrote:
16 May 2024, 03:06
What is the reason for removing this.?
I see this reply by HotKeyIt.
Attachments
postreply.png
postreply.png (25.74 KiB) Viewed 587 times

User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: A problem of using calling V1's libs in V2

Post by boiler » 16 May 2024, 05:01

Do you have a copy of the AutoHotkey.dll file in your script directory?

songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: A problem of using calling V1's libs in V2

Post by songdg » 16 May 2024, 10:22

boiler wrote:
16 May 2024, 05:01
Do you have a copy of the AutoHotkey.dll file in your script directory?
Yes, I use viv's original code without any problem.

User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: A problem of using calling V1's libs in V2

Post by boiler » 16 May 2024, 10:51

In my view, if the reason for using DP's code instead of viv's is because DP said it's a better approach, but DP's code doesn't work anymore, it's not better. I would just continue to use viv's code.

songdg
Posts: 699
Joined: 04 Oct 2017, 20:04

Re: A problem of using calling V1's libs in V2

Post by songdg » 17 May 2024, 01:49

Thanks, you are right, I should stick to the original one.

Post Reply

Return to “Ask for Help (v2)”