PageRenderTime 65ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/commands/ComObjQuery.htm

https://github.com/Lexikos/AutoHotkey_L-Docs
HTML | 123 lines | 97 code | 26 blank | 0 comment | 0 complexity | 2e530d50feba032dd8d9be8262b43be0 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>ComObjQuery() - Syntax &amp; Usage | AutoHotkey</title>
  5. <meta name="description" content="The ComObjQuery function queries a COM object for an interface or service." />
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  8. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  9. <script src="../static/content.js" type="text/javascript"></script>
  10. </head>
  11. <body>
  12. <h1>ComObjQuery() <span class="ver">[v1.0.96.00+]</span></h1>
  13. <p>Queries a COM object for an interface or service.</p>
  14. <pre class="Syntax">InterfacePointer := <span class="func">ComObjQuery</span>(ComObject, <span class="optional">SID,</span> IID)</pre>
  15. <h2 id="Parameters">Parameters</h2>
  16. <dl>
  17. <dt>ComObject</dt>
  18. <dd><p>A COM wrapper object or raw interface pointer.</p></dd>
  19. <dt>IID</dt>
  20. <dd><p>An interface identifier (GUID) in the form "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}".</p></dd>
  21. <dt>SID</dt>
  22. <dd><p>A service identifier in the same form as IID. When omitting this parameter, also omit the comma.</p></dd>
  23. </dl>
  24. <h2 id="General_Remarks">General Remarks</h2>
  25. <p>In its two-parameter mode, this function is equivalent to <a href="http://msdn.microsoft.com/en-us/library/ms682521.aspx">IUnknown::QueryInterface</a>. When SID and IID are both specified, it internally queries for the <a href="http://msdn.microsoft.com/en-us/library/cc678965.aspx">IServiceProvider</a> interface, then calls <a href="http://msdn.microsoft.com/en-us/library/cc678966.aspx">IServiceProvider::QueryService</a>. In either case, the return value is either zero or a pointer to the requested interface. Generally this pointer must be <a href="ObjAddRef.htm">released</a> when the script is finished with it.</p>
  26. <h2 id="Related">Related</h2>
  27. <a href="ObjAddRef.htm">ObjRelease()</a>, <a href="ComObjCreate.htm">ComObjCreate()</a>, <a href="ComObjGet.htm">ComObjGet()</a>, <a href="ComObjActive.htm">ComObjActive()</a>, <a href="ComObjError.htm">ComObjError()</a>
  28. <h2 id="Examples">Examples</h2>
  29. <div class="ex" id="ExClassName">
  30. <p><a class="ex_number" href="#ExClassName"></a> Determines the class name of an object.</p>
  31. <pre>obj := ComObjCreate("Scripting.Dictionary")
  32. MsgBox % "Interface name: " ComObjType(obj, "name")
  33. IID_IProvideClassInfo := "{B196B283-BAB4-101A-B69C-00AA00341D07}"
  34. <em>; Request a pointer to the object's IProvideClassInfo interface.</em>
  35. if !(pci := ComObjQuery(obj, IID_IProvideClassInfo))
  36. {
  37. MsgBox IProvideClassInfo interface not supported.
  38. return
  39. }
  40. <em>; Call GetClassInfo to retrieve a pointer to the ITypeInfo interface.</em>
  41. DllCall(vtable(pci, 3), "ptr", pci, "ptr*", ti)
  42. <em>; Call GetDocumentation to get the object's full type name.</em>
  43. DllCall(vtable(ti, 12), "ptr", ti, "int", -1, "ptr*", pname, "ptr", 0, "ptr", 0, "ptr", 0)
  44. <em>; Convert the BSTR pointer to a usable string.</em>
  45. name := StrGet(pname, "UTF-16")
  46. <em>; Free the BSTR referenced by pname.</em>
  47. DllCall("OleAut32\SysFreeString", "ptr", pname)
  48. <em>; Release raw interface pointers.</em>
  49. ObjRelease(ti)
  50. ObjRelease(pci)
  51. <em>; Display the type name!</em>
  52. MsgBox % "Class name: " name
  53. vtable(ptr, n) {
  54. <em>; NumGet(ptr+0) returns the address of the object's virtual function
  55. ; table (vtable for short). The remainder of the expression retrieves
  56. ; the address of the nth function's address from the vtable.</em>
  57. return NumGet(NumGet(ptr+0), n*A_PtrSize)
  58. }
  59. </pre>
  60. </div>
  61. <div class="ex" id="ExIE">
  62. <p><a class="ex_number" href="#ExIE"></a> Automates an existing Internet Explorer window.</p>
  63. <pre>sURL := "https://www.autohotkey.com/boards/"
  64. if WebBrowser := GetWebBrowser()
  65. WebBrowser.Navigate(sURL)
  66. return
  67. GetWebBrowser()
  68. {
  69. <em>; Get a raw pointer to the document object of the top-most IE window.</em>
  70. static msg := DllCall("RegisterWindowMessage", "Str", "WM_HTML_GETOBJECT")
  71. SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_class IEFrame
  72. if (ErrorLevel = "FAIL")
  73. return <em>; IE not found.</em>
  74. lResult := ErrorLevel
  75. DllCall("oleacc\ObjectFromLresult", "Ptr", lResult
  76. , "Ptr", GUID(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}")
  77. , "Ptr", 0, "Ptr*", pdoc)
  78. <em>; Query for the WebBrowserApp service. In this particular case,
  79. ; the SID and IID are the same, but it isn't always this way.</em>
  80. static IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
  81. static SID_SWebBrowserApp := IID_IWebBrowserApp
  82. pweb := ComObjQuery(pdoc, SID_SWebBrowserApp, IID_IWebBrowserApp)
  83. <em>; Release the document object pointer.</em>
  84. ObjRelease(pdoc)
  85. <em>; Return the WebBrowser object, wrapped for usability:</em>
  86. static VT_DISPATCH := 9, F_OWNVALUE := 1
  87. return ComObject(VT_DISPATCH, pweb, F_OWNVALUE)
  88. }
  89. GUID(ByRef GUID, sGUID) <em>; Converts a string to a binary GUID and returns its address.</em>
  90. {
  91. VarSetCapacity(GUID, 16, 0)
  92. return DllCall("ole32\CLSIDFromString", "WStr", sGUID, "Ptr", &amp;GUID) &gt;= 0 ? &amp;GUID : ""
  93. }
  94. </pre>
  95. </div>
  96. </body>
  97. </html>