COM.ahk, best version?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

COM.ahk, best version?

01 Apr 2017, 17:39

Which is the best/most up-to-date version of COM.ahk?

I found 4 versions. Line counts: 555, 572, 625, 633.

==================================================

I tested these with AutoHotkeyU32 v1.1.25.01, and a script which I have posted lower down:

[555 lines (488 sloc) 20.7 KB][works][COM_L.zip (UNICODE)]
COM.AHK/com.ahk at master · ttnnkkrr/COM.AHK · GitHub
https://github.com/ttnnkkrr/COM.AHK/blob/master/com.ahk

[572 lines][runs, but with error message][COM_L.zip (ANSI)]
[worked when I replaced the COM_SysString function]

[625 lines (558 sloc) 26 KB][wouldn't open]
AHKs/COM.ahk at master · camerb/AHKs · GitHub
https://github.com/camerb/AHKs/blob/mas ... ty/COM.ahk

[633 lines (564 sloc) 25.1 KB][runs, but with error message]
[worked when I replaced the COM_SysString function]
Autohotkey-Scripts/com.ahk at master · dufferzafar/Autohotkey-Scripts · GitHub
https://github.com/dufferzafar/Autohotk ... ib/com.ahk

Perhaps there is yet another, better version?

Usual text comparisons in WinMerge, and things like checking for new parameters in the function definitions, proved indecisive in determining which was the best version.

==================================================

My quick-fix function:

Code: Select all

COM_SysString(ByRef wString, sString)
{
	VarSetCapacity(wString,3+2*nLen:=1+StrLen(sString))
	if !A_IsUnicode
		Return	NumPut(DllCall("kernel32\MultiByteToWideChar","Uint",0,"Uint",0,"Uint",&sString,"int",nLen,"Uint",&wString+4,"int",nLen,"Uint")*2-2,wString)
	else
	{
		DllCall("msvcrt\memcpy", "uint", &wString+4, "uint", &sString, "uint", StrLen(sString)*2)
		Return	NumPut(3+2*nLen:=1+StrLen(sString),wString)
	}
}
==================================================

The code I tested it on:
IE_Add() or COM_AtlAxCreateContainer() or AtlAxWin() - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/3213 ... ntry204552

Code: Select all

SetWorkingDir, %A_ScriptDir%
#include %A_ScriptDir%\com.ahk
;~ #include %A_ScriptDir%\ie.ahk

Gui +LastFound +Resize +MinSize600x300
Gui, Show, center h600 w600, Test
COM_AtlAxWinInit()

 pweb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),25, 203, 550, 372, "Shell.Explorer") )

COM_Invoke(pweb, "Silent", True)
COM_Invoke(pweb, "Navigate2", "http://www.google.com/")

Return

GuiSize:
WinMove, % "ahk_id " . COM_AtlAxGetContainer(pweb), , 25, 203, A_GuiWidth - 50, A_GuiHeight - 228
Return
GuiClose:
COM_Release(psink)
COM_Release(pweb)
Gui, Destroy
COM_AtlAxWinTerm()
ExitApp
==================================================

Why I'm interested in COM.ahk.

The script above and COM.ahk give you a way to create a simple GUI with an 'Internet Explorer_Server' control. This is useful for understanding GUIs generally, understanding how AutoHotkey works, creating GUIs in AHK v1 that are not #Persistent (i.e. they do not use the Gui command), and creating GUIs in other programming languages.

I was trying to make a SplashImage replacement that can handle more filetypes like animated gifs and svg files.

Reading through COM.ahk is also a very good way to understand AutoHotkey's native COM. I intend to recommend that for my objects tutorial, however, I need to pick a version first!

jeeswg's objects tutorial (not yet complete) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=29232

==================================================

[EDIT:]
In general, I am in interested in having GUIs that don't use the Gui command, this allows you to have GUIs in script libraries that do not cause a script to become #Persistent (i.e. you would otherwise have to modify the script by changing lines to ExitApp etc, otherwise they would never close, unless closed manually).

[EDIT:]
Some advantages of making GUIs via DllCall only, and not the Gui command, are that they can be simpler to write and maintain, and for example (unless AHK brings in this functionality) allow you to choose a GUI class name, or specify a window with no icon.

==================================================

All roads lead to COM.
COM one, COM all.
TweedleCOM and TweedleRelease.
Will the real COM Query please stand up?
I'm SpartaCOM!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: COM.ahk, best version?

02 Apr 2017, 03:26

jeeswg wrote:Some advantages of making GUIs via DllCall only, and not the Gui command, are that they can be simpler to write and maintain, ...
You know that you have to write your own Window Procedure in this case? Good luck!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: COM.ahk, best version?

03 May 2017, 16:37

@just me. Yep I did, thanks for the encouragement.

==================================================

So overall, this appears to be the best version:

[555 lines (488 sloc) 20.7 KB][works][COM_L.zip (UNICODE)]
COM.AHK/com.ahk at master · ttnnkkrr/COM.AHK · GitHub
https://github.com/ttnnkkrr/COM.AHK/blob/master/com.ahk

I did some of the necessary conversion, to try and make it x64/x32 compatible, if someone who understands the script/issues better wants to finish it off:

DllCall converter/cleaner (e.g. x32 to x64/x32 two-way compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31365

==================================================

Note: Functions in other versions of COM, not in the '555 lines' version:
COM_Invoke_
COM_ActiveXObject
COM_SysStringLen
COM_Ansi4Unicode
COM_Unicode4Ansi
COM_Ansi2Unicode
COM_Unicode2Ansi
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, nacken012 and 232 guests