QueryInterface method for the IID_IPersistStreamInit quit working

555 Views Asked by At

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)
1

There are 1 best solutions below

5
On

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.