ComObjQuery()

提供: AutoHotkey Wiki
移動: 案内検索

実行制御 | GUI表示 | 演算・変数 | メモリ・DLL操作 | 文字列操作 | キーボード | マウス | シェル | ウィンドウ | ウィンドウグループ
ステータスバー | コントロール | サウンド | ファイル | INIファイル | レジストリ | 環境変数 | AutoHotkey | その他 | 設定関係 | オブジェクト

ComObjQuery() [v1.0.96.00+][編集]

このページの訳はかなり怪しいです。あまり信用しないように。
AHKL インターフェイスまたはサービスのCOMオブジェクトを照会する。

InterfacePointer := ComObjQuery(ComObject, [SID,] IID)

Parameters[編集]

引数名 説明
ComObject COMラッパーオブジェクトまたは生のインターフェイスポインタ。
IID ​​インタフェース識別子(GUID)形式。 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
SID IIDと同じ形式、サービス識別子。

Remarks[編集]

その2つのパラメータ·モードでは、この関数は IUnknown::QueryInterface に相当する。 SIDとIIDが両方指定されている場合、IServiceProviderインターフェイスの内部クリエは、次に IServiceProvider::QueryService 呼び出す。 いずれの場合も、戻り値はゼロまたは要求されたインターフェイスへのポインタである。 通常、スクリプト終了時にはこのポインターが解放されている必要がある。

Related[編集]

ObjRelease(), ComObjCreate(), ComObjGet(), ComObjActive(), ComObjError()

Example(s)[編集]

; Example: Determine the class name of an object.

obj := ComObjCreate("Scripting.Dictionary")

MsgBox % "Interface name: " ComObjType(obj, "name")

IID_IProvideClassInfo := "{B196B283-BAB4-101A-B69C-00AA00341D07}"

; Request a pointer to the object's IProvideClassInfo interface.
If !(pci := ComObjQuery(obj, IID_IProvideClassInfo))
{
    MsgBox IProvideClassInfo interface not supported.
    Return
}

; Call GetClassInfo to retrieve a pointer to the ITypeInfo interface.
DllCall(vtable(pci, 3), "ptr", pci, "ptr*", ti)

; Call GetDocumentation to get the object's full type name.
DllCall(vtable(ti, 12), "ptr", ti, "int", -1, "ptr*", name, "ptr", 0, "ptr", 0, "ptr", 0)

; Convert the BSTR pointer to a usable string.
name := StrGet(name, "UTF-16")

; Release raw interface pointers.
ObjRelease(ti)
ObjRelease(pci)

; Display the type name!
MsgBox % "Class name: " name

vtable(ptr, n) {
    ; NumGet(ptr+0) returns the address of the object's virtual function
    ; table (vtable for short). The remainder of the expression retrieves
    ; the address of the nth function's address from the vtable.
    Return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
; Example: Automate an existing Internet Explorer window.

sURL := "http://www.autohotkey.com/forum/"
If webBrowser := GetWebBrowser()
   webBrowser.Navigate(sURL)
Return

GetWebBrowser()
{
    ; Get a raw pointer to the document object of the top-most IE window.
    static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
    SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_class IEFrame
    If ErrorLevel = FAIL
        Return  ; IE not found.
    lResult := ErrorLevel
    DllCall("oleacc\ObjectFromLresult", "ptr", lResult
        , "ptr", GUID(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}")
        , "ptr", 0, "ptr*", pdoc)
    
    ; Query for the WebBrowserApp service. In this particular case,
    ; the SID and IID are the same, but it isn't always this way.
    static IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
    static SID_SWebBrowserApp := IID_IWebBrowserApp
    pweb := ComObjQuery(pdoc, SID_SWebBrowserApp, IID_IWebBrowserApp)
    
    ; Release the document object pointer.
    ObjRelease(pdoc)
    
    ; Return the WebBrowser object, wrapped for usability:
    static VT_DISPATCH := 9, F_OWNVALUE := 1
    Return ComObject(VT_DISPATCH, pweb, F_OWNVALUE)
}

GUID(ByRef GUID, sGUID) ; Converts a string to a binary GUID and returns its address.
{
    VarSetCapacity(GUID, 16, 0)
    Return DllCall("ole32\CLSIDFromString", "wstr", sGUID, "ptr", &GUID) >= 0 ? &GUID : ""
}