I have a COM function:
GetData(SAFEARRAY ** pRetVal)
and following legacy code:
CComSafeArray<double> saDataArray;
hr = pmyInterface->GetData(&saDataArray.m_psa);
SafeArrayLock(saDataArray);
I doubt if that is good to manually manage locks. Will that code crash when m_psa
was returned as NULL
by GetData
?
How about following code? Is that better?
LPSAFEARRAY psa;
CComSafeArray<double> saDataArray;
hr = pmyInterface->GetData(&psa);
saDataArray.Attach(psa);
EDIT:
I tested both of the code above. There is one difference. If GetData
returns NULL
, directly Attach
it without NULL
check will invoke a exception. And the first version will return a E_INVALIDARG
. My question still remains, do you prefer the later version since it use SafeArray object to maintain the counting, rather than mixing it?
EDIT2:
If for whatever reason I choose the first version, is that okay to ignore the E_INVALIDARG
return value? Will that have any side effect when some code later use this saDataArray
?