描述:
用ATL写了一个COM组件,组件中有一个查询接口,接口返回另一个对象的接口指针,但这种接口用户不能用CoCreateInstance,QueryInterface得到,要怎么做呢?
返回的对像写这个Com对像在同一DLL中.
解决方案1:
比如返回这样一个指针
STDMETHODIMP CTrackingLayer::AddEvent(IPolygon **shape)
{
if( shape== NULL )
return E_POINTER;
CComObject<CPolygon> *pObj = NULL;
CComObject< CPolygon>::CreateInstance( &pObj);
if(pObj)
{
pObj->QueryInterface(IID_IPolyogn,(void**)shape);
}
return S_OK;
}
同以上所说!
解决方案3: STDMETHODIMP CTrackingLayer::AddEvent(IPolygon **shape)
{
if( shape== NULL )
return E_POINTER;
CPolygonImpl *pObj = new CPolygonImpl;
if(pObj)
{
pObj->QueryInterface(IID_IPolyogn,(void**)shape);
}
return S_OK;
}