BUG: CComContainedObject::QueryInterface() Implementation Is Incorrect (272676)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 3.0
This article was previously published under Q272676 SYMPTOMS
When you are writing an aggregatable COM object in Active Template Library (ATL), unintended inner object interfaces could be exposed because of a bug in the implementation of the CComContainedObject::QueryInterface function.
CAUSE
The CComContainedObject::QueryInterface function calls the following lines in AtlCom.h:
STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
{
HRESULT hr = OuterQueryInterface(iid, ppvObject);
if (FAILED(hr) && _GetRawUnknown() != m_pOuterUnknown)
hr = _InternalQueryInterface(iid, ppvObject);
return hr;
}
If the OuterQueryInterface call fails, a "blind" _InternalQueryInterface is performed in the case of an aggregated object. This can cause a problem when, for instance, the outer object does not want to expose an interface of the inner object (and returns, E_FAIL, for example). The "blind" _InternalQueryInterface in the code returns that interface anyway.
RESOLUTION
To work around the problem and enable the aggregation to work correctly, comment out the highlighted lines in the AtlCom.h file:
STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
{
HRESULT hr = OuterQueryInterface(iid, ppvObject);
// Comment out the two lines below:
// if (FAILED(hr) && _GetRawUnknown() != m_pOuterUnknown)
// hr = _InternalQueryInterface(iid, ppvObject);
return hr;
}
Make these modifications to a copy of the AtlCom.h file (for instance, FixAtlCom.h). Then, in the Stdafx.h file, comment out AtlCom.h and use FixAtlCom.h instead:
// #include <AtlCom.h>
#include "FixAtlCom.h"
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. REFERENCESFor additional information, click the article number below
to view the article in the Microsoft Knowledge Base:
181265 HOWTO: Create ATL COM Objects
View the following topics in the Microsoft Developer Network (MSDN) library:
CComContainedObject
http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_atl_ccomcontainedobject.htm
CComAggObject
http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_atl_ccomaggobject.htm
CComPolyObject
http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_atl_ccompolyobject.htm
Modification Type: | Major | Last Reviewed: | 10/22/2002 |
---|
Keywords: | kbbug kbDSupport KB272676 |
---|
|