burque505 / go-ahk

Future home of go-ahk. Uses go-ole to wrap AutoHotkey.dll
MIT License
0 stars 1 forks source link

Question about the package #1

Open tommynanny opened 3 weeks ago

tommynanny commented 3 weeks ago

this is an awesome library, but when working with it, I saw the following line. I was trying to understand where do you get this string from "AutoHotkey.Script". I guess AutoHotkey is the DLL name, but how about ".String"

    unknown, err := oleutil.CreateObject("AutoHotkey.Script")
burque505 commented 3 weeks ago
I guess AutoHotkey is the DLL name, but how about ".String"

I'm not 100% sure I understand the question, but I'll try to answer as best I can.

Maybe this will help, not sure (I am working almost exclusively with AutoHotkey V2 now, and haven't touched this repo in some time, not doing much of anything with Go anymore either, apologies).

"AutoHotkey.Script" is the human-readable name of the COM object being created.

If you run this plain-vanilla AutoHotkey v1 script (using autohotkey.exe, not the dll) maybe it will provide some useful information. If you experiment with using the human-readable name vs. the CLSID, by commenting and uncommenting as needed, you should get the same info for both.

ahk := ComObjCreate("AutoHotkey.Script")
;ahk := ComObjCreate("{C00BCC8C-5A04-4392-870F-20AAE1B926B2}")
Cls := ComObjType(ahk, "Class")
Id := ComObjType(ahk, "CLSID") 
MsgBox %Id%
MsgBox %Cls%
ahk := ""

;CLSID
; {C00BCC8C-5A04-4392-870F-20AAE1B926B2}
tommynanny commented 3 weeks ago

@burque505 , thanks again for your response!

ahk := ComObjCreate("AutoHotkey.Script")
;ahk := ComObjCreate("{C00BCC8C-5A04-4392-870F-20AAE1B926B2}")
Cls := ComObjType(ahk, "Class")
Id := ComObjType(ahk, "CLSID") 
MsgBox id->"%Id%"  cls->"%Cls%"
ahk := ""

image image

I ran the script you provided, and the class (Cls) returned was "CoCOMServer", which matches what I saw when viewing AutoHotkey.dll directly in Visual Studio's Object Browser. However, none of the results show "AutoHotkey.Script" as the correct string to create the COM object. (unless it is a preserved string/syntax and a predefined keyword used when interacting with COM, not just AutoHotkey, but any COM in general)

I was originally asking about the .Script part in AutoHotkey.Script (apologies for the typo in my original post where I mentioned ".String"). I’m trying to replicate this in AutoHotkey v2 (using AutoHotkey_H), but I can’t figure out how to locate the right ProgID for the COM object.

It seems critical to use the exact string because if I change it in any way

e.g.,

unknown, err := oleutil.CreateObject("AutoHotkey.Other")

I get the error

2024/09/27 10:20:44 CreateObject: Invalid class string
exit status 1

Could you explain a bit more about how you found "AutoHotkey.Script" in the first place? This would really help me in figuring out the correct ProgID for my scenario.

I did some research on the provided CLSID online and found this reference: AutoHotkey COM Interface. It shows that the interface AutoHotkey.Script corresponds to the CLSID {C00BCC8C-5A04-4392-870F-20AAE1B926B2}, but how can one tell the correct interface ("AutoHotkey.Script") and CLSID in the first place if they only have the DLL without having this information?

Apologies if my questions seem a bit basic; I’m still learning and trying to understand how this works. Thanks for your patience!

Thanks again for your help! πŸ™‡πŸ™‡πŸ™‡ πŸ™