【发布时间】:2011-11-08 00:34:33
【问题描述】:
我不确定在函数内部使用 CComPtr 的这种方式,该函数的参数表示为双指针:
HRESULT D3DPresentEngine::CreateD3DSample(
IDirect3DSwapChain9 *pSwapChain,
IMFSample **ppVideoSample
)
{
// Caller holds the object lock.
D3DCOLOR clrBlack = D3DCOLOR_ARGB(0xFF, 0x00, 0x00, 0x00);
CComPtr< IDirect3DSurface9 > pSurface;
CComPtr< IMFSample > pSample;
// Get the back buffer surface.
ReturnIfFail( pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) );
// Fill it with black.
ReturnIfFail( m_pDevice->ColorFill(pSurface, NULL, clrBlack));
// Create the sample.
ReturnIfFail( MFCreateVideoSampleFromSurface(pSurface, &pSample));
// Return the pointer to the caller.
*ppVideoSample = pSample;
(*ppVideoSample)->AddRef();
return S_OK;
}
我对最后一次分配 + AddRef 调用有疑问。
它们适合你吗?
提前致谢
【问题讨论】:
标签: c++ atl smart-pointers