0
votes

I have a task, that includes grabbing some text that lie inside a third party ActiveX component that's embedded inside Internet Explorer webpage using "OBJECT id=S_DetectCom codeBase=xxxx.cab ..."

i have the .cab file having the activeX dlls(4 dlls)

i'm not familiar with OLE and activeX, but doing some research and trials , i could get an IDispatch to ActiveX object by the following steps :-

1- get handle to IE tab having class "Internet Explorer_Server"

2- get IHTMLDocument2 using ObjectFromLresult

3- get IHTMLElementCollection from IHTMLDocument2

4- get IDispatch from IHTMLElementCollection with element of name "S_DetectCom"

what lies in mind, is getting the typelib from DLLs to know the methods,... and their parameters by try and error find which dll in the cab is embedded into that web page

right now i'm stuck, as i don't know how to reach Invoke to call methods from IDispatch i got

i'd appreciate if somebody could help me with ideas and implementation below is the code part that gets IDispatch from hwnd

int msg;
DWORD lRes = NULL ;
IHTMLDocument2 *pDoc= NULL; 
IHTMLElementCollection *pElement = NULL ;
IHTMLInputTextElement *ppvInput ;
IDispatch *ppvDisp;
ITypeInfo *TypeInfo = NULL ;
VARIANT ObjName ;
_variant_t index = NULL;
HRESULT hr;
LRESULT lr ;
UINT cntTypeInf= NULL ;
long pItems = NULL;
BSTR pszOptText[200];


OleInitialize(NULL);

msg = RegisterWindowMessage(L"WM_HTML_GETOBJECT");
lr = SendMessageTimeout(hwnd, msg, 0, 0, SMTO_ABORTIFHUNG, 1000, &lRes);
hr = ObjectFromLresult((LRESULT)lRes, IID_IHTMLDocument2, 0, (void**)&pDoc);
hr = pDoc->get_all( &pElement );

BSTR BStrObjName = _com_util::ConvertStringToBSTR((const char *)"S_DetectCom");
ObjName.vt = VT_BSTR ;
ObjName.bstrVal = BStrObjName ;
hr = pElement->item( ObjName , index , &ppvDisp );
if (hr == S_OK && ppvDisp)
{
    hr = ppvDisp->GetTypeInfoCount(&cntTypeInf);
    hr = ppvDisp->GetTypeInfo(NULL , NULL , &TypeInfo);
    // to do here

}
2

2 Answers

0
votes

If you are using WM_HTML_GETOBJECT to get the HTML document you are definitely not an expected caller, since you are out of the current thread. The ActiveX is probably not thread-safe.

Anyway, if you can get a proxy plugin to execute in the IE's Tab thread (probably by installing a BHO), here are the steps to access the ActiveX's properties and methods. It is for accessing an Adobe Flash ActiveX but you can change file name in the import statement to import interfaces from the ocx file.

0
votes

If I were you instead of trying to use COM directly I'd write a FireBreath plugin, which would then work on firefox, etc as well as IE (it implements an ActiveX Control as well as a NPAPI plugin).

That will do all of the IDispatch stuff for you, and then you can tie into the lower level classes (look at IDispatchAPI) to get the direct COM handle for the element after you grab it and do a queryinterface for the interface you need.

If nothing else you could use the IDispatchAPI class as an example of how to access IDispatch methods.