Hi guys,
This most likely has a very simple answer, but I can't figure it out.
I'm trying to refactor some code that looks like this:
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;
I would like to change the code to something like:
CComSafeArray<BSTR> sa;
long* count;
hr = pSomeInterface->ListSomething(&(sa.m_psa), &count);
if (SUCCEEDED(hr))
{
// perform operations on sa
}
But when I execute this, sa contains garbage. What's happening and why? What is the correct syntax?