Microsoft
Software
Hardware
Network
Question : 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
spDisp = GetHtmlDocument();
if (spDisp != NULL)
{
// the control will handle all printing UI
CComQIPtr
t> 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_Documen
t(&result)
;
if(FAILED(hr))
{
ASSERT(FALSE);
return NULL;
}
return result;
}
CHtmlView::GetHtmlDocument
() calls m_pBrowserApp->get_Documen
t() 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::ExecFormsComman
d
CHtmlView::QueryFormsComma
nd
CHtmlView::GetSource
This is a new bug in VC7. The bug was not in VC6 in that it didn't use CComPtr.
Answer : VC7: Newly introduced bugs in MFC\Src\viewhtml.cpp
PAQed, with points refunded (50)
modulo
Community Support Moderator
Random Solutions
Is there a recycling bin in Windows 7?
CLR Stored Procedure
printing a file given the path in windows API
Basic steps for a Zip code search ASP.NET VB, MS SQL 2008
Calendar question
video card driver
How to restrict on categories with recurrent items using VBA in access
active directory, W2k8 R2 DC, Kerberos failures, Event ID: 3, 4771, 4769, 4768, 4776, 4625 source: Microsoft Windows security
Access attaching a file as xls when it should be rtf
insert image via bookmark