处理 IE 窗口内的 ActiveX 组件

发布于 2024-11-27 06:41:12 字数 1619 浏览 1 评论 0原文

我有一个任务,包括使用“OBJECT id=S_DetectCom codeBase=xxxx.cab ...”抓取嵌入在 Internet Explorer 网页中的第三方 ActiveX 组件内的一些文本,

我有包含 activeX dll 的 .cab 文件( 4 dll)

我不熟悉 OLE 和 activeX,但是做了一些研究和试验,我可以通过以下步骤获得 ActiveX 对象的 IDispatch :-

1- 获取句柄具有“Internet Explorer_Server”类的 IE 选项卡

2- 使用 ObjectFromLresult 获取 IHTMLDocument2

3- 从 IHTMLDocument2 获取 IHTMLElementCollection

4- 从 IHTMLElementCollection 获取 IDispatch,其元素名称为“S_DetectCom”

所要考虑的是从 DLL 获取类型库以了解方法。 ..及其参数 通过尝试和错误找到cab中的哪个dll嵌入到该网页中,

现在我被卡住了,因为我不知道如何到达Invoke来调用IDispatch中的方法,

如果有人可以帮助我,我将不胜感激下面的思路和实现是从hwnd获取IDispatch的代码部分

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

将军与妓 2024-12-04 06:41:12

如果您使用 WM_HTML_GETOBJECT 来获取 HTML 文档,那么您绝对不是预期的调用者,因为您已脱离当前线程。 ActiveX 可能不是线程安全的。

无论如何,如果您可以获得在 IE 的 Tab 线程中执行的代理插件(可能通过安装 BHO),以下是访问 ActiveX 属性和方法的步骤。它用于访问 Adob​​e Flash ActiveX,但您可以更改导入语句中的文件名以从 ocx 文件导入接口。

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.

话少情深 2024-12-04 06:41:12

如果我是你,而不是尝试直接使用 COM,我会编写一个 FireBreath 插件,然后该插件可以在 Firefox 上运行等以及 IE(它实现了 ActiveX 控件以及 NPAPI 插件)。

这将为您完成所有 IDispatch 的工作,然后您可以绑定到较低级别的类(查看 IDispatchAPI),以在获取元素并为您需要的接口执行查询接口后获取该元素的直接 COM 句柄。

如果没有别的办法,您可以使用 IDispatchAPI 类作为如何访问 IDispatch 方法的示例。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文