有没有办法使用 C++ 的最新 IE9 MSHTML 界面?带有 TCPpWebBrowser 的 Builder(或 Delphi)?

发布于 2024-11-07 09:54:25 字数 1803 浏览 3 评论 0 原文

我有一种情况,我想使用通过 IHTMLDocument7 界面。特别是 getElementsByTagNameNS() 方法,因为我想使用特定的标签类型(比解析整个文档容易得多)。

我当前的代码如下所示:

IHTMLDocument2* doc = NULL;

    if (browser->ControlInterface->Document) // make sure TCppWebBrowser is OK
    {
        if (SUCCEEDED(browser->ControlInterface->Document->QueryInterface(IID_IHTMLDocument2, (void**)&doc)))
        {
            IHTMLElement* body;

            HRESULT hr = doc->get_body(&body);
            if (SUCCEEDED(hr))
            {
                WideString innerHtml;
                body->get_innerHTML(&innerHtml);
                txtInfo->Text = innerHtml;

                body->Release();
            }

          doc->Release();
        }
    }

这可以工作,并且可能有问题,但我最感兴趣的是获得我现在想要的功能。

如果我更改此代码以使用 IE9 提供的新接口:

browser->ControlInterface->Document->QueryInterface(IID_IHTMLDocument7, (void**)&doc)

我收到以下编译器错误:

[BCC32 Error] Unit2.cpp(134): E2451 Undefined symbol 'IID_IHTMLDocument7'
  Full parser context
    Unit2.cpp(129): parsing: void _fastcall TForm2::Button4Click(TObject *)

[BCC32 Error] Unit2.cpp(134): E2285 Could not find a match for 'IUnknown::QueryInterface(undefined,void * *)'
  Full parser context
    Unit2.cpp(129): parsing: void _fastcall TForm2::Button4Click(TObject *)

似乎找不到此接口的匹配项。

  • 我应该做什么才能做到这一点 接口可用吗?我猜 BCB 附带的 Windows SDK 版本 可能已经过时,或者不知道 关于 IE9 的类型库 MSHTML 版本。
  • 有没有办法 制作适当的标题 可用于该接口 (IID_IHTMLDocument7),并保留 TCPpWeb浏览器控件?或者我需要 导入单独的 ActiveX 控件?

我在 Windows 7 (x64) 和 IE9 上使用 C++ Builder Starter XE (15.0.3953.35171)。

I have a situation where I would like to use some methods available via the IHTMLDocument7 interface shipped with IE9. In particular the getElementsByTagNameNS() method because I want to work with specific tag types (a lot easier than parsing the whole document).

My current code looks like this:

IHTMLDocument2* doc = NULL;

    if (browser->ControlInterface->Document) // make sure TCppWebBrowser is OK
    {
        if (SUCCEEDED(browser->ControlInterface->Document->QueryInterface(IID_IHTMLDocument2, (void**)&doc)))
        {
            IHTMLElement* body;

            HRESULT hr = doc->get_body(&body);
            if (SUCCEEDED(hr))
            {
                WideString innerHtml;
                body->get_innerHTML(&innerHtml);
                txtInfo->Text = innerHtml;

                body->Release();
            }

          doc->Release();
        }
    }

This works, and may have issues, but I'm most interested in getting the functionality I want right now.

If I change this code to use the new interface available with IE9:

browser->ControlInterface->Document->QueryInterface(IID_IHTMLDocument7, (void**)&doc)

I get the following compiler error:

[BCC32 Error] Unit2.cpp(134): E2451 Undefined symbol 'IID_IHTMLDocument7'
  Full parser context
    Unit2.cpp(129): parsing: void _fastcall TForm2::Button4Click(TObject *)

[BCC32 Error] Unit2.cpp(134): E2285 Could not find a match for 'IUnknown::QueryInterface(undefined,void * *)'
  Full parser context
    Unit2.cpp(129): parsing: void _fastcall TForm2::Button4Click(TObject *)

It appears that it cannot find a match for this interface.

  • What should I do to make this
    interface available? I'm guessing the
    Windows SDK version shipped with BCB
    may be out of date, or doesn't know
    about a type library for the IE9
    version of MSHTML.
  • Is there a way to
    make the appropriate headers
    available for this interface
    (IID_IHTMLDocument7), and keep the
    TCppWebBrowserControl? Or do I need
    to import a separate ActiveX control?

I am using C++ Builder Starter XE (15.0.3953.35171) on Windows 7 (x64) with IE9.

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

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

发布评论

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

评论(3

°如果伤别离去 2024-11-14 09:54:25

使用IHTMLDocument3 界面< /a> 而不是 IHTMLDocument7,或执行 javascript 返回您需要的内容,例如:

IHTMLDocument2  *doc = NULL;
IHTMLWindow2 *win;

if(SUCCEEDED(CppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&doc)))  {
    HRESULT hr = doc->get_parentWindow(&win);
    if (SUCCEEDED(hr))  {
      BSTR cmd = L"function deltag(){\
    var all    = this.document.getElementsByTagNameNS('IMG');  \
    var images = [];                           \
    for(var a=0;a<all.length;++a)               \
    {                                           \
        if(all[a].tagName == 'NAME')         \
            images.push(all[a]);         \
    }                                             \
    for(var i=0;i<images.length;++i)               \
    {                                               \
        images[i].parentNode.removeChild(images[i]); \
    }  " ;           \                           

   VARIANT v;
   VariantInit(&v);
   win->execScript(cmd,NULL,&v);
   VariantClear(&v);
   win->Release();
    }
    doc->Release();
  }

Use IHTMLDocument3 Interface instead of IHTMLDocument7, or execute javascript to return what you need, like:

IHTMLDocument2  *doc = NULL;
IHTMLWindow2 *win;

if(SUCCEEDED(CppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&doc)))  {
    HRESULT hr = doc->get_parentWindow(&win);
    if (SUCCEEDED(hr))  {
      BSTR cmd = L"function deltag(){\
    var all    = this.document.getElementsByTagNameNS('IMG');  \
    var images = [];                           \
    for(var a=0;a<all.length;++a)               \
    {                                           \
        if(all[a].tagName == 'NAME')         \
            images.push(all[a]);         \
    }                                             \
    for(var i=0;i<images.length;++i)               \
    {                                               \
        images[i].parentNode.removeChild(images[i]); \
    }  " ;           \                           

   VARIANT v;
   VariantInit(&v);
   win->execScript(cmd,NULL,&v);
   VariantClear(&v);
   win->Release();
    }
    doc->Release();
  }
浪推晚风 2024-11-14 09:54:25

IE9 标头可从 http://msdn.microsoft.com/en-us/ 下载ie/aa740471

我不确定你的 BCB 链接器有多少年了。 VC 2005 的链接器需要 KB949009 修补程序 才能在调试配置中链接到 IE9 库。

IE9 headers are available for downloading at http://msdn.microsoft.com/en-us/ie/aa740471

I am not sure how old is your BCB linker. VC 2005's linker requires the KB949009 hotfix to link against IE9 libs in a debug configuration.

奢华的一滴泪 2024-11-14 09:54:25

至少在 C++Builder 2010 中,IHTMLDocument7 未在 mshtml.h 中定义,但 IHTMLDocument6 已定义。如果您从 Microsoft 下载最新的 SDK,则可以将 IHTMLDocument7 定义直接复制到现有代码中。

或者,尝试查看 BCCSDK 是否已更新为支持 IHTMLDocument7。

At least in C++Builder 2010, IHTMLDocument7 is not defined in mshtml.h, but IHTMLDocument6 is. If you download an up-to-date SDK from Microsoft, you can copy the IHTMLDocument7 definition directly into your existing code.

Alternatively, try seeing if BCCSDK has been updated to support IHTMLDocument7 yet.

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