ComObjQuery() [v1.0.96.00+]

COM °´Ã¼¿¡ ÀÎÅÍÆäÀ̽º³ª ¼­ºñ½º°¡ ÀÖ´ÂÁö ÁúÀÇÇÕ´Ï´Ù.

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

¸Å°³º¯¼ö

ComObject

COM Æ÷Àå °´Ã¼ ¶Ç´Â ³¯ ÀÎÅÍÆäÀ̽º Æ÷ÀÎÅÍ.

IID

ÀÎÅÍÆäÀ̽º ½Äº°ÀÚ (GUID). Çü½Ä "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}".

SID

¼­ºñ½º ½Äº°ÀÚ. IID¿Í Çü½ÄÀÌ °ª½À´Ï´Ù. ÀÌ ¸Å°³º¯¼ö°¡ »ý·«µÇ¸é, ½°Ç¥µµ »ý·«µË´Ï´Ù.

ÃÑÆò

±×ÀÇ µÎ-¸Å°³º¯¼ö ¸ðµå¿¡¼­, ÀÌ ÇÔ¼ö´Â IUnknown::QueryInterface¿Í µ¿µîÇÕ´Ï´Ù. SID¿Í IID ¸ðµÎ ÁöÁ¤µÇ¸é, ³»ºÎÀûÀ¸·Î IServiceProvider ÀÎÅÍÆäÀ̽º¿¡ ÁúÀÇÇÑ ´ÙÀ½, IServiceProvider::QueryService¸¦ È£ÃâÇÕ´Ï´Ù. ¾î´À °æ¿ìµç, ¹Ýȯ °ªÀº 0 À̰ųª ¾Æ´Ï¸é ¿äûµÈ ÀÎÅÍÆäÀ̽º¸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍÀÔ´Ï´Ù. ÀϹÝÀûÀ¸·Î ÀÌ Æ÷ÀÎÅÍ´Â ¹Ýµå½Ã ½ºÅ©¸³Æ®°¡ ÀÏÀ» ¸¶Ä¥ ¶§ ÇØÁ¦µÇ¾î¾ß ÇÕ´Ï´Ù.

°ü·Ã Ç׸ñ

ObjRelease, ComObjCreate, ComObjGet, ComObjActive, ComObjError

¿¹Á¦

; ¿¹Á¦: °´Ã¼ÀÇ Å¬·¡½º À̸§À» ¾Ë¾Æ³À´Ï´Ù

obj := ComObjCreate("Scripting.Dictionary")

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

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

; ±× °´Ã¼ÀÇ IProvideClassInfo ÀÎÅÍÆäÀ̽º¸¦ °¡¸®Å°´Â Æ÷ÀÎÅ͸¦ ¿ä±¸ÇÕ´Ï´Ù.
if !(pci := ComObjQuery(obj, IID_IProvideClassInfo))
{
    MsgBox IProvideClassInfo interface not supported.
    return
}

; GetClassInfo¸¦ È£ÃâÇØ ITypeInfo ÀÎÅÍÆäÀ̽º¸¦ °¡¸®Å°´Â Æ÷ÀÎÅ͸¦ ¿­¶÷ÇÕ´Ï´Ù.
DllCall(vtable(pci, 3), "ptr", pci, "ptr*", ti)

; GetDocumentationÀ» È£ÃâÇÏ¿© ±× °´Ã¼ÀÇ ¿ÏÀüÇÑ À¯Çü À̸§À» ¾ò½À´Ï´Ù.
DllCall(vtable(ti, 12), "ptr", ti, "int", -1, "ptr*", name, "ptr", 0, "ptr", 0, "ptr", 0)

; BSTR Æ÷ÀÎÅ͸¦ ¾µ¸ðÀÖ´Â ¹®ÀÚ¿­·Î º¯È¯ÇÕ´Ï´Ù.
name := StrGet(name, "UTF-16")

; ³¯ ÀÎÅÍÆäÀ̽º Æ÷ÀÎÅ͵éÀ» ÇØÁ¦ÇÕ´Ï´Ù.
ObjRelease(ti)
ObjRelease(pci)

; À¯Çü À̸§À» º¸¿©ÁÝ´Ï´Ù!
MsgBox % "Class name: " name

vtable(ptr, n) {
    ; NumGet(ptr+0)Àº ±× °´Ã¼ÀÇ °¡»ó ÇÔ¼ö Å×À̺íÀÇ (¾àÀÚ·Î vtable)
    ; ÁÖ¼Ò¸¦ µ¹·ÁÁÝ´Ï´Ù. Ç¥Çö½ÄÀÇ ³ª¸ÓÁö´Â n¹ø° ÇÔ¼öÀÇ ÁÖ¼Ò¸¦
    ; vtable·ÎºÎÅÍ ¿­¶÷ÇÕ´Ï´Ù.
    return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
; ¿¹Á¦: ±âÁ¸ÀÇ ÀÎÅÍ³Ý ÀͽºÇ÷η¯ âÀ» ÀÚµ¿È­Çϱâ.

sURL := "http://ahkscript.org/boards/"
if webBrowser := GetWebBrowser()
   webBrowser.Navigate(sURL)
return

GetWebBrowser()
{
    ; ÃÖ»óÀ§ IE âÀÇ ¹®¼­ °´Ã¼¸¦ °¡¸®Å°´Â ³¯ Æ÷ÀÎÅ͸¦ ¾ò½À´Ï´Ù.
    static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
    SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_class IEFrame
    if ErrorLevel = FAIL
        return  ; IE°¡ ¹ß°ßµÇÁö ¾ÊÀ½.
    lResult := ErrorLevel
    DllCall("oleacc\ObjectFromLresult", "ptr", lResult
        , "ptr", GUID(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}")
        , "ptr", 0, "ptr*", pdoc)
    
    ; WebBrowserApp ¼­ºñ½º¿¡ ÁúÀÇÇÕ´Ï´Ù. ÀÌ Æ¯º°ÇÑ °æ¿ì´Â
    ; SID¿Í IID°¡ °°½À´Ï´Ù. ±×·¯³ª ¾ðÁ¦³ª ÀÌ·± °ÍÀº ¾Æ´Õ´Ï´Ù.
    static IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
    static SID_SWebBrowserApp := IID_IWebBrowserApp
    pweb := ComObjQuery(pdoc, SID_SWebBrowserApp, IID_IWebBrowserApp)
    
    ; ¹®¼­ °´Ã¼ Æ÷ÀÎÅ͸¦ Ç®¾îÁÝ´Ï´Ù.
    ObjRelease(pdoc)
    
    ; WebBrowser °´Ã¼¸¦, »ç¿ëÀ» À§ÇØ Æ÷ÀåÇؼ­, ¹ÝȯÇÕ´Ï´Ù:
    static VT_DISPATCH := 9, F_OWNVALUE := 1
    return ComObject(VT_DISPATCH, pweb, F_OWNVALUE)
}

GUID(ByRef GUID, sGUID) ; ¹®ÀÚ¿­À» ÀÌÁø GUID·Î º¯È¯ÇÏ°í ±×ÀÇ ÁÖ¼Ò¸¦ µ¹·ÁÁÝ´Ï´Ù.
{
    VarSetCapacity(GUID, 16, 0)
    return DllCall("ole32\CLSIDFromString", "wstr", sGUID, "ptr", &GUID) >= 0 ? &GUID : ""
}