ComObjType: Are the Fields Blank for your Object?

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
User avatar
lmstearn
Posts: 332
Joined: 11 Aug 2016, 02:32
GitHub: lmstearn
Contact:

ComObjType: Are the Fields Blank for your Object?

26 May 2020, 05:20

Running this code from the docs for ComObjType:

Code: Select all

X :=  ComObjCreate("Test_COM_Object") 
VarType := ComObjType(obj)
IName   := ComObjType(obj, "Name")
IID     := ComObjType(obj, "IID")
CName   := ComObjType(obj, "Class")  ; Requires [v1.1.26+]
CLSID   := ComObjType(obj, "CLSID")  ; Requires [v1.1.26+]
MsgBox % "Variant type:`t" VarType
	. "`nInterface name:`t" IName "`nInterface ID:`t" IID
	. "`nClass name:`t" CName "`nClass ID (CLSID):`t" CLSID
; ObjRelease(X) if there is an IID
exitapp
There are all kinds COM objects out there which come in different shapes and forms- all the common ones only appear to provide blank fields.
Curious as to what objects provide a non-blank field for VarType, IName, IID, CName, and CLSID besides the example provided in the docs. (Unable to get anything for Internet Explorer due to this issue.)
Some stock objects tested (via Google popularity) are:
  • "Shell.Application".
  • "WinHttp.WinHttpRequest.5.1"
  • "WScript.Shell"
  • "HTMLFile"
  • "Microsoft.Windows.ActCtx"
  • "ScriptControl"
  • "Scripting.Dictionary"
  • "Schedule.Service"
  • "msxml2.DOMDocument.6.0"
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
User avatar
Ragnar
Posts: 320
Joined: 30 Sep 2013, 15:25

Re: ComObjType: Are the Fields Blank for your Object?

28 May 2020, 04:39

Actually, it does not work because you use X instead of obj in the first line.
User avatar
lmstearn
Posts: 332
Joined: 11 Aug 2016, 02:32
GitHub: lmstearn
Contact:

Re: ComObjType: Are the Fields Blank for your Object?

28 May 2020, 06:09

Cripes- What happened there? :wtf: :facepalm:
Here's the output from the above list with the fields from the corrected code:
Edit: Another error with CLSID corrected- see post below:
"Shell.Application"
Variant type: 9
Interface name: IShellDispatch6
Interface ID: {286E6F1B-7113-4355-9562-96B7E9D64C54}
Class name: Shell
Class ID (CLSID): {13709620-C279-11CE-A49E-444553540000}
"WinHttp.WinHttpRequest.5.1"
Variant type: 9
Interface name: IWinHttpRequest
Interface ID: {016FE2EC-B2C8-45F8-B23B-39E53A75396B}
Class name: WinHttpRequest
Class ID (CLSID): {2087C2F4-2CEF-4953-A8AB-66779B670495}
"WScript.Shell"
Variant type: 9
Interface name: IWshShell3
Interface ID: {41904400-BE18-11D3-A28B-00104BD35090}
Class name: IWshShell3
Class ID (CLSID): {41904400-BE18-11D3-A28B-00104BD35090}
"HTMLFile"
Variant type: 9
Interface name: DispHTMLDocument
Interface ID: {3050F55F-98B5-11CF-BB82-00AA00BDCE0B}
Class name: HTMLDocument
Class ID (CLSID): {25336920-03F9-11CF-8FD0-00AA00686F13}
"Microsoft.Windows.ActCtx"
Variant type: 9
Interface name: IActCtx
Interface ID: {8FA7728F-B69B-4EE5-99F2-E2AA021BEF28}
Class name: ActCtx
Class ID (CLSID): {85BB4477-6DC3-4A8D-84D6-86A0FA1AAF8B}
"ScriptControl"
Variant type: 9
Interface name: IScriptControl
Interface ID: {0E59F1D3-1FBE-11D0-8FF2-00A0D10038BC}
Class name: ScriptControl
Class ID (CLSID): {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}
"Scripting.Dictionary"
Variant type: 9
Interface name: IDictionary
Interface ID: {42C642C1-97E1-11CF-978F-00A02463E06F}
Class name: Dictionary
Class ID (CLSID): {EE09B103-97E0-11CF-978F-00A02463E06F}
"Schedule.Service"
Variant type: 9
Interface name: ITaskService
Interface ID: {2FABA4C7-4DA9-4013-9697-20CC3FD40F85}
Class name: TaskScheduler
Class ID (CLSID): {0F87369F-A4E5-4CFC-BD3E-73E6154572DD}
"msxml2.DOMDocument.6.0"
Variant type: 9
Interface name: IXMLDOMDocument3
Interface ID: {2933BF96-7B36-11D2-B20E-00C04F983E60}
Class name: DOMDocument60
Class ID (CLSID): {88D96A05-F192-11D4-A65F-0040963251E5}
"WMPlayer.OCX"
Variant type: 9
Interface name: IWMPPlayer4
Interface ID: {6C497D62-8919-413C-82DB-E935FB3EC584}
Class name: WindowsMediaPlayer
Class ID (CLSID): {6BF52A52-394A-11D3-B153-00C04F79FAA6}
Last edited by lmstearn on 30 May 2020, 09:05, edited 1 time in total.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
lexikos
Posts: 6960
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ComObjType: Are the Fields Blank for your Object?

30 May 2020, 00:27

Why are the CLSID lines blank in your post? It should be impossible for an object to return a class name but fail to return a CLSID. If I replace your first line with one of the following, for example, I get a CLSID.

Code: Select all

obj := ComObjCreate("Scripting.Dictionary") 
obj := ComObjCreate("Shell.Application")
VarType is always an integer if you give the function a COM wrapper object. ComObjType is not querying the COM object for this information, just the wrapper object. It will give you an answer even if the wrapped COM object or value is invalid (which should happen only if you create a wrapper object directly, with an invalid value). ComObjType returns blank only if what you passed it is not a COM wrapper object.

All of the other modes depend on the wrapper containing a valid COM object.

"Name" and "IID" depend on the IDispatch::GetTypeInfo method, which is not always implemented. They require VarType to be 9 (VT_DISPATCH).

"Class" and "CLSID" depend on class information being available by one of the following means. They require VarType to be 9 (VT_DISPATCH) or 13 (VT_UNKNOWN), but which one doesn't matter (only the actual interfaces supported by the object matter).
  1. The object implements the IProvideClassInfo interface and its GetClassInfo method succeeds.
  2. The object implements IDispatch, IDispatch::GetTypeInfo succeeds, ITypeInfo::GetContainingTypeLib succeeds, and the relevant type information can be found in the type library.
Once type information is retrieved,
  • "Name" and "Class" depend on the ITypeInfo::GetDocumentation method returning a name for MEMBERID_NIL.
  • "IID" and "CLSID" depend only on ITypeInfo::GetTypeAttr, which probably always succeeds.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests