Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
VC7: Newly introduced bugs in MFC\Src\viewhtml.cpp
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
chensu  
View profile  
 More options Jan 31 2004, 3:02 pm
Newsgroups: microsoft.public.vc.mfc
From: chensu <che...@hotmail.com>
Date: Sat, 31 Jan 2004 11:51:08 -0800
Local: Sat, Jan 31 2004 2:51 pm
Subject: VC7: Newly introduced bugs in MFC\Src\viewhtml.cpp
Have a look at the following MFC source code in Visual Studio .NET 2003.

void CHtmlView::OnFilePrint()
{
        // get the HTMLDocument

        if (m_pBrowserApp != NULL)
        {
                CComPtr<IDispatch> spDisp = GetHtmlDocument();

                if (spDisp != NULL)
                {
                        // the control will handle all printing UI

                        CComQIPtr<IOleCommandTarget> spTarget = spDisp;
                        if (spTarget != NULL)
                                spTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
                }
        }

}

LPDISPATCH CHtmlView::GetHtmlDocument() const
{
        ASSERT(m_pBrowserApp != NULL);

        LPDISPATCH result;
        HRESULT hr = m_pBrowserApp->get_Document(&result);
        if(FAILED(hr))
        {
                ASSERT(FALSE);
                return NULL;
        }

        return result;

}

CHtmlView::GetHtmlDocument() calls m_pBrowserApp->get_Document() to get the IDispatch. So the RefCount is increased by one. Then in CHtmlView::OnFilePrint(), the returned interface pointer is passed to CComPtr. The constructor of CComPtr will call AddRef() on the interface pointer. So now the RefCount is increased by two. In the end, the destructor of CComPtr will call Release() once. But the original RefCount returned by CHtmlView::GetHtmlDocument() is never released. All the functions using GetHtmlDocument() have this bug, including

CHtmlView::OnFilePrint
CHtmlView::ExecFormsCommand
CHtmlView::QueryFormsCommand
CHtmlView::GetSource

This is a new bug in VC7. The bug was not in VC6 in that it didn't use CComPtr.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"Ed Dore [MSFT]"  
View profile  
 More options Feb 3 2004, 12:17 pm
Newsgroups: microsoft.public.vc.mfc
From: e...@online.microsoft.com ("Ed Dore [MSFT]")
Date: Tue, 03 Feb 2004 17:15:27 GMT
Local: Tues, Feb 3 2004 12:15 pm
Subject: RE: VC7: Newly introduced bugs in MFC\Src\viewhtml.cpp
Thanks for the bug report. That is definitely a bug in the GetHtmlDocument
function. Not sure why that smart pointer was introduced, but I've reported
the problem to the MFC development team, and we'll hopefully see that
corrected in the next release.

Sincerely,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google