连接到正在运行的IE实例C ++ [英] Connect to running IE instance C++

查看:76
本文介绍了连接到正在运行的IE实例C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用AutoIt编写程序,但是我想将某些函数外包给C ++,因为它更安全。我设法创建了IE并导航到一个站点。

I'm currently writing a program in AutoIt but I want to outsource some functions to C++ because its more secure. I managed it to create an IE and navigate to a site.

但这不是我所需要的。我正在AutoIt中创建IE的实例,用C ++编写的部分必须连接到该IE并导航到特定页面。

But thats not what I need. I'm creating an instance of the IE in AutoIt and the part written in C++ has to connect to this IE and navigate to a specific page.

现在它是C ++应用程序,但是稍后,当一切运行正常时,我将在其中创建一个.Dll并使用AutoIt对其进行调用。这样我就可以传递诸如hWnd之类的值。

Right now its an C++ Application but later on, when everything runs fine, I will create a .Dll out of it and call it with AutoIt. So I can pass values like hWnd and so on.

我想这样做是有原因的,所以请不要问我为什么这样做。

I want to do this with good cause so please do not ask me why I am doing this.

有人知道我该如何管理吗?

Does anybody know how I can manage it? Thanks in advance.

    CoInitialize(NULL);
IWebBrowser2* pBrowser = NULL;
HRESULT hr = CoCreateInstance(CLSID_InternetExplorer, NULL, 
    CLSCTX_SERVER, IID_IWebBrowser2, (LPVOID*)&pBrowser);

if (SUCCEEDED(hr) && (pBrowser != NULL))
{
    VARIANT vEmpty;
    VariantInit(&vEmpty);

    VARIANT vFlags;
    V_VT(&vFlags) = VT_I4;
    V_I4(&vFlags) = navOpenInNewWindow;

    BSTR bstrURL = SysAllocString(L"http://www.ard.de");

    pBrowser->Navigate(bstrURL, &vFlags, &vEmpty, &vEmpty, &vEmpty);
    pBrowser->Quit();

    SysFreeString(bstrURL);
}
if (pBrowser)
    pBrowser->Release();
CoUninitialize();
return 0;


推荐答案

您发布的代码创建了一个新的IE(标签)实例,这不是您想要的。您要连接到现有实例,并且必须使用其他方法。

The code that you posted creates a new IE (tab) instance, which is not what you want. You want to connect to an existing instance and for that you have to use a different approach.

首先,创建一个 IShellWindows 实例。该对象是Shell窗口注册表(例如Windows Explorer或IE)的接口。

First you create a IShellWindows instance. This object is an interface to a registry of shell windows (e.g. Windows Explorer or IE).

您可以执行以下两项操作:您可以订阅其事件并成为在用户打开和关闭窗口时收到通知;您还可以枚举当前窗口。

You can do two things with this: you can subscribe to its events and be notified as the user opens and closes windows; You can also enumerate the current windows.

您使用 get_Count() IShellWindows Item() 方法。此枚举将为您提供 IDispatch 接口,然后您可以 QueryInterface() IWebBrowser2 接口(如果失败,则跳过,而不是IE)。请注意,您仍然可能会得到非IE的窗口,因此可能需要更多的过滤。

You enumerate the current windows using get_Count() and Item() methods of IShellWindows. This enumeration will give you IDispatch interfaces that you then can QueryInterface() to IWebBrowser2 interface (skip if it fails, not IE). Note that you might still get windows that are not IE, so more filtering might be required.

从这里您可以尝试找出它是否在寻找窗口

From here you can try to find out if it's the window you are looking for.

这篇关于连接到正在运行的IE实例C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆