Greetings!
First of all it is nessesary to get an info from type library using IRecordInfo interface:
GUID GUID_SMyObj2 = __uuidof(SMyObj2);
HRESULT hr;
CComPtr<IRecordInfo> srecnfo;
hr = GetRecordInfoFromGuids(LIBID_MyLib , 1, 0, 0, GUID_SMyObj2, &srecnfo);
if(FAILED(hr))
_com_issue_errorex(hr, NULL, IID_NULL);
If this part will be successful, then it is possible to create a safearray or custom type:
const LONG l_bound = 0, u_bound = 2;
LPSAFEARRAY lpSMyObj2 = SafeArrayCreateVectorEx(VT_RECORD, l_bound,
u_bound - l_bound + 1, srecnfo);
if(!lpSMyObj2)
_com_issue_errorex(E_FAIL, NULL, IID_NULL);
or access and use existing:
LONG l_bound = 0, u_bound = 0;
HRESULT hr1 = SafeArrayGetLBound(lpSMyObj2, 1, &l_bound);
HRESULT hr2 = SafeArrayGetUBound(lpSMyObj2, 1, &u_bound);
if(FAILED(hr1) || FAILED(hr2) )
{
}
else
{
...
SMyObj2 * pSMyObj2 = NULL;
HRESULT hr = SafeArrayAccessData(lpSMyObj2, (void**)&pSMyObj2);
if(FAILED(hr))
_com_issue_errorex(hr, NULL, IID_NULL);
...
}
for(int i = l_bound; i <= u_bound - l_bound; i++)
{
}
...
hr = SafeArrayUnaccessData(lpSMyObj2);
if(FAILED(hr))
_com_issue_errorex(hr, NULL, IID_NULL);
Please see
http://msdn.microsoft.com/en-us/library/aa148975.aspx[
^] for more details