Home Dashboard Directory Help
Search

MFC class CStreamOnCString stops working with IE9 by zirconia


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 687736
Opened: 9/9/2011 4:32:19 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

This code worked until IE8. Now Save() returns E_NOTIMPL.

CComQIPtr<IPersistStreamInit> spPSI;
spPSI = spHTMLDocument;
if (spPSI)
{
    CStreamOnCString stream;
    hr = spPSI->Save(static_cast<IStream*>(&stream), FALSE);
    ASSERT(hr != E_NOTIMPL);
}

The problem lies in the Seek() and SetSize() callbacks. They should return S_OK!

STDMETHOD(Seek)(LARGE_INTEGER, DWORD, ULARGE_INTEGER *)
{
    return S_OK;
}

STDMETHOD(SetSize)(ULARGE_INTEGER)
{
    return S_OK;
}
Details
Sign in to post a comment.
Posted by Microsoft on 9/21/2011 at 3:00 PM
Hello,

Thanks for the repro project. I was able to reproduce the problem and I have fixed it as you suggested.
The fix will be available in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by zirconia on 9/17/2011 at 11:48 AM
See attached sample project. It demonstrates the problem.

Hit F5 and wait for the ASSERT to trigger!
Posted by Microsoft on 9/16/2011 at 4:46 PM
Hello,

Maybe it's just the fact that it's Friday afternoon, but I don't understand your explanation of the repro project. I grabbed the sample from MSDN but the only GetDocumentHTML method I see is not virtual, so how do I override it? And then "start surfing the web?"

If you could attach a project that demonstrates what you're talking about, that would be a big help. Thanks!

Pat Brenner
Visual C++ Libaries Development
Posted by zirconia on 9/12/2011 at 2:56 PM
If you need a working sample, just use Paul DiLascia's excellent CHtmlCtrl:
http://msdn.microsoft.com/en-us/magazine/cc164109.aspx

Then extend CHtmlCtrl with the method below and start surfing the web!

HRESULT CHtmlCtrl::GetDocumentHTML(CString& strHTML) const
{
    HRESULT hr = E_NOINTERFACE;
    
    CComPtr<IHTMLDocument2> spHTMLDocument;
    GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&spHTMLDocument);
    if (spHTMLDocument)
    {
        CComQIPtr<IPersistStreamInit> spPSI;
        spPSI = spHTMLDocument;
        if (spPSI)
        {
            CStreamOnCString stream;
            hr = spPSI->Save(static_cast<IStream*>(&stream), FALSE);
            if (hr == S_OK)
            {
                if (!stream.CopyData(strHTML))
                    hr = E_OUTOFMEMORY;
            }
        }
    }

    return hr;
}


Also worth mentioning; I have a feeling this error has something to do with javascript-crafted webpages, but I could be wrong. Perhaps there are two paths inside the Save API - one that checks Seek/SetSize return value, and one that does not?
Posted by zirconia on 9/12/2011 at 2:47 PM
Well, if you don't return S_OK in these two functions, IPersistStreamInit::Save returns E_NOTIMPL. I don't know when this behavior changed. All I know is that my code worked a couple of months ago, and then stopped working.

What's new in my system? Internet Explorer 9.

And yes, I would argue that returing S_OK is the right thing to do. SetSize() obviously succeeds, since CString uses dynamic allocation. I'm a bit unsure about the Seek() function. Perhaps it should assign m_current_index to 0 before returning S_OK?

For my piece of software, the above fixes the problem so I'm quite confident that this is a valid fix.
Posted by Microsoft on 9/12/2011 at 2:26 PM
Hello,

Thanks for the report. Can provide a project that demonstrates this problem? I'm not convinced that returning S_OK from the Seek and SetSize methods is the correct fix in MFC, since they don't provide any other implementation. Thanks for any additional clarification you can provide.

Pat Brenner
Visual C++ Libraries Development
Posted by MS-Moderator07 [Feedback Moderator] on 9/11/2011 at 6:41 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by MS-Moderator01 on 9/9/2011 at 9:57 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
CStreamOnCString_bug_sample.zip (restricted) 9/17/2011 -