IID_IPersistStreamInit 的 QueryInterface 方法停止工作

发布于 2024-08-07 20:49:41 字数 689 浏览 8 评论 0原文

我有一个应用程序,一直用来解析 HTML 文档中的数据。该应用程序已经工作了几年,直到本周 IID_IPersistStreamInit 的 QueryInterface 方法开始失败。对 QueryInterface 的调用返回 -2147467262,它未通过 SUCCEEDED(hr) 测试。有什么想法为什么会停止工作吗?

谢谢, 韦德

if (!myIE->IsValid())
   return;

HRESULT hr;
LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
LPPERSISTSTREAM lpPersistStream = NULL;

lpDispatch = myIE->GetHtmlDocument(); 

ASSERT(lpDispatch);

if (lpDispatch == NULL)
  AfxMessageBox("Couldn't get IHTMLDocument2 interface!");    
else
{ 
   hr = lpDispatch->QueryInterface(IID_IPersistStreamInit, (void**) &lpPersistStream);
   if (SUCCEEDED(hr) && lpPersistStream != NULL)

I have an application that I've been using to parse data from an HTML document. The application has been working for a few years until this week when the QueryInterface method for the IID_IPersistStreamInit started failing. The call to QueryInterface is returning -2147467262 which fails the SUCCEEDED(hr) test. Any ideas why this quit working?

Thanks,
Wade

if (!myIE->IsValid())
   return;

HRESULT hr;
LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
LPPERSISTSTREAM lpPersistStream = NULL;

lpDispatch = myIE->GetHtmlDocument(); 

ASSERT(lpDispatch);

if (lpDispatch == NULL)
  AfxMessageBox("Couldn't get IHTMLDocument2 interface!");    
else
{ 
   hr = lpDispatch->QueryInterface(IID_IPersistStreamInit, (void**) &lpPersistStream);
   if (SUCCEEDED(hr) && lpPersistStream != NULL)

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

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

发布评论

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

评论(1

染火枫林 2024-08-14 20:49:41

您在什么时候执行上面的代码?如果未完成,您应该仅在执行以下操作后执行它:

  1. 导航到 about:blank 以正确加载 mshtml
  2. 确保在继续之前调用 DocumentComplete 事件,这意味着导航已完成。

只有这样才能安全地请求流接口。有关详细信息,请参阅从流加载 HTML 内容

现在,如果所有这些都已了解并得到解决,您可能会从另一个方向寻求解决方案。错误代码的意思是“不支持此类接口”。我会尝试找出包含该接口的组件是什么,然后重新注册它。但考虑到这是你正在处理的 IE 东西,我有点怀疑它的安装被搞砸了。

At what point are you executing the code above? In case it's not done, you should execute it only after the followings:

  1. Navigating to about:blank to have mshtml loaded properly
  2. Make sure the DocumentComplete event is called, meaning the navigation has completed, before you move on.

Only then is it safe to ask for the stream interface. For more, see Loading HTML content from a Stream.

Now, if all this is known and taken care of, you might pursue the solution from the other direction. The error code means "No such interface supported". I'd try finding out what is the component that contains that interface, and then re-register it. But given this is IE stuff you're dealing with, I kind of doubt it's installation got screwed.

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