Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

COM Standard Library


  • Please log in to reply
669 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
Show your code. I'd like to see how you separated it first before I comment. BTW, I bet your errors were not consistent, I mean you did not always get the errors at the same item(s) when you run the code as the needed time for a procedure to complete is dependent on the current status of the system. So, you didn't get an error just once means little in this case.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
The errors appeared to happen randomly, this is mainly why I tried the sleep command.

items := Array()
itemnames := Array()
Loop % doc.Folder.Items.Count
{
	items.append(doc.Folder.Items.Item(A_Index - 1))
	itemnames.append(items[A_Index].Name)
	Sleep 10
}
Loop % Select.len()
{
	filter := Select[A_Index]
	If filter <>
	{
		If(InStr(filter, "*"))
		{
			filter := "\Q" StringReplace(filter, "*", "\E.*\Q", 1) "\E"
			filter := strTrim(filter,"\Q\E")
			Loop % items.len()
			{
				if(RegexMatch(itemnames[A_Index],"i)" filter))
				{
					COM_Invoke(doc,"SelectItem",items[A_Index],index=1 ? value1 : value) ;http://msdn.microsoft.com/en-us/library/bb774047(VS.85).aspx					
					index++
					;Sleep 10
				}
			}
		}
		else
			COM_Invoke(doc,"SelectItem",doc.Folder.ParseName(filter),(A_Index=1 ? value1 : value)) ;http://msdn.microsoft.com/en-us/library/bb774047(VS.85).aspx					
	}
}

I also just tried this kind of loop so that Count is only requested once:
count := doc.Folder.Items.Count
Loop % count

It does not seem to do much to the frequency of errors, with both methods I get 0-2 errors on a folder with 44 elements, of which 42 should get selected.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
So, back to the my first reply. I already suggested two other solutions than using sleep which may be the simplest but inaccurate. My preferred solution is using the event SelectionChanged, but it's really up to you which one to choose. BTW another simple solution may be turning off the error notification and when retrieving a name is failed, just retry it until succeeded. The result/name will be an empty string when failed. Or you can obtain the hResult(s) of the current invoke by using the global variable COM_HR/COM_LR or by calling COM_Error().

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I guess I'll have to use one of those. The drawback of the SelectionChanged event would be having to split the function in two parts, but that's more of cosmetic nature. Thanks for your input!

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Hi Sean, I have an error in AutoHotkey_L53 but same code works using COM.ahk
Any Idea what is wrong :(
COM_Init() ; Initialize COM.
d := COM_CreateObject("Scripting.Dictionary") ; Create dictionary.
d.Item("a", "Athens")
MsgBox % d.Item("a")
COM_Release(d) ; Done using dictionary d.
		 
d := COMObjCreate("Scripting.Dictionary") ; Create dictionary.
d.Item("a", "Athens") ;[color=red]Error:  0x8002000E - Invalid number of parameters.[/color]
d.Item("a") := "Athens" ;works fine
MsgBox % d.Item("a")


jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
You already pointed out the issue - the item property is only supposed to have one param. The way the COM Library was designed, the second param was the value to be assigned. With built-in COM support, this is no longer valid syntax. See Item Property.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
I see, thanks jethrow :roll:

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
I'm not sure if you want these messages in this thread or not, but I noticed a difference in performance between the COM Library to Built-In COM. The following works as expected with COM_CreateObject, but errors out with ComObjCreate:
x:=ComObjCreate("ScriptControl"), x.Language:="jScript", a:=x.Eval("a=[1,2]")

loop, % a.length {
	MsgBox, % a[A_Index-1] ; <-- Error:  0x80020006 - Unknown name.
	; MsgBox, % a[n] ; works fine for both
	; MsgBox, % a["" A_Index-1] ; works fine for both
}
EDIT - the exact error message is: Error: 0x80020006 - Unknown name. (error in the MsgBox line)
EDIT2 - This has now been fixed.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
What was the exact error message? Anyway, the function name of a COM Object should be a string basically. And I suppose that the error was produced in your example since A_Index-1 was resolved to a name of an empty string. BTW, compare it with the following which will work as you expect:
MsgBox, % a[0] . "|" . a["0"]
MsgBox, % a[1] . "|" . a["1"]
Although making it work as you want is relatively straightforward (:which I don't like to add personally), I think you better post it in AHK_L thread.

ribbs2521
  • Members
  • 279 posts
  • Last active: Feb 23 2012 05:58 PM
  • Joined: 28 Sep 2007
I hate to keep being a bother about this but can someone help me out. I had a compiler working fine and now it doesn't.

I found that Compile_AHK II does not work with AutoHotKey_La.exe but the standard issue .ahk to .exe did. Now when using either I get issues.

When using Compile_AHK II I get:
Could not extract script from .EXE
When using .ahk to .exe I get:
Error at line 66.

The following variable name contains an illegal character:
".Name"

The program will exit.
It's at a line with rs.Fields(0).Name when trying to get the field name from an ADODB recordset.

I'm at a loss because it works without compiling.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
You need to use correct AutoHotkeySC.bin :!:

ribbs2521
  • Members
  • 279 posts
  • Last active: Feb 23 2012 05:58 PM
  • Joined: 28 Sep 2007
I don't know how that got screwed up but I know for next time, thanks. Sorry for the dumb mistake.

  • Guests
  • Last active:
  • Joined: --
Just a thought, but now that AHKL has built-in COM Support, should all the COM_Enwrap calls in the COM_L Library be changed to ComObjEnwrap. I noticed this when trying to determine the ComObjType from an object created with COM_AtlAxCreateControl.

lexios
  • Guests
  • Last active:
  • Joined: --
Many of the functions which use COM_Enwrap are also obsolete. I think that the following can probably be removed (but it wouldn't hurt to confirm): Init, Term, GetObject, GetActiveObject, AddRef, Release, Enumerate, Error, Invoke, Invoke_, Parameter, Dis/ConnectObject and dependencies (FindConnectionPoint, GetConnectionInterface, Advise, Unadvise, DispInterface, CreateIDispatch, GetDefaultEvents). That's a significant portion of the library. It's possible that some of these might be useful with non-dispatch COM interfaces (which aren't directly supported by AHK_L). On that note, CreateInstance must be kept as it allows non-dispatch objects to be created, but CreateObject can be removed as it's a simple wrapper around CreateInstance.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
Now you can think of COM.ahk as just a collection of miscellaneous functions which you can copy when you need them.

BTW, the supported features of COM_Invoke/COM_Parameter and those of the native COM are different. The most notable may be that COM.ahk does support named parameters. For the native COM to be competitive in this respect, I think it should support the same named parameters, or missing parameters, or both. My preference is the second one, support of missing parameters. Until then, I think better leave COM.ahk as it is.