Search code examples
dllcom

Invoke a COM Method from a dll


The question is this: i've been inspecting kaspersky gadget and found out it uses a COM object as i can see declared in the gadget's main html file, so i looked in the registry by the CLSID and got to the "gadget.dll" located in the kaspersky instalation folder. Mi interest is to invoke specific kaspersky's app tab just the same way they do. Examining the .js files on the gadget's folder i could see the syntax of the method i would need to use which is "OpenWindow(WindowID)" and the WindowID's are also specified in another file. I've been trying this from a simple VisualBasic Script:

Set kavCOM = WScript.CreateObject("KISGadgetCOM.COMClass.1")
kavCOM.OpenWindow(1)

that should invoke the Main Window, also tried a AutoHotKey Script:

^!k::
{
kavCOM := ComObjCreate("{ED6E691B-E662-4aae-AECC-705C9B014C75}")
kavCOM.OpenWindow(1)
}

they both result in the error: 80004004 (Operation aborted) at the line with "kavCOM.OpenWindow(1)

what's wrong?


Solution

  • Ok, the problem was the Object instantiation delay, i solved it by adding WScript.Sleep 1000 just before calling the "OpenWindow" method.

    My final(finer) solution so that it doesn't wait more than needed:

    Dim kavCOM, Cnt
    Cnt = 0
    Set kavCOM = CreateObject("KISGadgetCOM.COMClass.1")
    On Error Resume Next
    Do
     Cnt = Cnt + 1
     kavCOM.OpenWindow(1)
     If Err = 0 Then 
      Exit Do
     Else
      Err.Clear
     End If
     WScript.Sleep 10
    Loop
    On Error Goto 0
    MsgBox "It took " & 10*Cnt & " miliseconds."
    Set kavCOM = Nothing