Fetching the IRecordInfo Interface

For passing a safearray of UDTs the type library is necessary for fetching the IRecordInfo Interface. For v-table binding you can retrieve the IRecordinfo interface from the type library. For late binding the IRecordInfo interface can be retrieved from the default type information.

The following is an example of loading the type library and retrieving the IRecordInfo interface:


ITypeLib * pTypeLib;
hr = LoadTypeLib(OLESTR("udt.tlb"), &pTypeLib);
if (FAILED(hr))
    goto ErrorOut;

ITypeInfo * pTypeInfo;
hr = pTypeLib->GetTypeInfoOfGuid(<guid of udt>, &pTypeInfo)
if (FAILED(hr))
   goto ErrorOut;

hr = pTypeLib->GetTypeInfo(0, &pTypeInfo);
if (FAILED(hr))
   goto ErrorOut;

pTypeLib->Release();
IRecordInfo * pRecInfo;
hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
pTypeInfo->Release();
if (FAILED(hr)) {
   printf("GetRecordInfoFromTypeInfo failed [0x%x]\n", hr);
   goto ErrorOut;
}
// Use record info

ErrorOut:;
// Put error handling code here


The type library containing the definition of the UDT is first loaded by calling LoadTypeLib and the type information of the UDT is obtained with GetTypeInfoOfGuid. The GetRecordInfoFromTypeInfo is then called to obtain the record information from the type information of the UDT. At this point the record information is returned to pRecInfo.

The following example demonstrates fetching the IRecordInfo interface from the default type information for late-binding. Error checking and variable declarations have been omitted for brevity.


hr = pdisp->GetTypeInfo(0, GetUserDefaultLCID(), &pTypeInfo);
_ASSERT(SUCCEEDED(hr) && pTypeInfo);
hr = pTypeInfo->GetContainingTypeLib(&pTypelib, &index);
_ASSERT(SUCCEEDED(hr) && pTypelib);
hr = pTypelib->GetTypeInfoOfGuid(UUID_StudentStruct, &pTypeInfo2);
_ASSERT(SUCCEEDED(hr) && pTypeInfo2);
hr = GetRecordInfoFromTypeInfo(pTypeInfo2, &pRecInfo);

 

 

Community Additions

ADD
Show:
© 2014 Microsoft