これにはおそらく非常に単純な答えがありますが、私にはわかりません。
次のようなコードをリファクタリングしようとしています。
SAFEARRAY* psa;
long* count;
HRESULT hr = pSomeInterface->ListSomething(&psa, &count);
if (SUCCEEDED(hr))
{
CComSafeArray<BSTR> sa;
if (*count > 0)
{
sa.Attach(psa);
}
}
// perform operations on sa
// allow CComSafeArray to destroy the object
return hr;
コードを次のように変更したいと思います。
CComSafeArray<BSTR> sa;
long* count;
hr = pSomeInterface->ListSomething(&(sa.m_psa), &count);
if (SUCCEEDED(hr))
{
// perform operations on sa
}
しかし、これを実行すると、sa にゴミが含まれます。何が起きているのか、その理由は? 正しい構文は何ですか?