gpt4 book ai didi

c++ - 双指针函数参数和 CComPtr

转载 作者:太空狗 更新时间:2023-10-29 20:30:06 28 4
gpt4 key购买 nike

我不确定这种在函数内部使用 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 调用有疑问。

它们适合你吗?

提前致谢

最佳答案

没关系,但可以简化:

HRESULT D3DPresentEngine::CreateD3DSample(
IDirect3DSwapChain9 *pSwapChain,
IMFSample **ppVideoSample
)
{
// Caller holds the object lock.

D3DCOLOR clrBlack = D3DCOLOR_ARGB(0xFF, 0x00, 0x00, 0x00);

CComPtr< IDirect3DSurface9 > pSurface;

// 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, ppVideoSample));

return S_OK;
}

在您的代码中,AddRef 是必需的,因为 pSample 在超出范围时将Release

关于c++ - 双指针函数参数和 CComPtr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8039150/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com