views:

191

answers:

1

Hi,

I have a structure defined in IDL. This structure has following members:


{
    BSTR m_sFirst;
    BSTR m_sSecond;
    VARIANT m_vChildStruct; //This member encapsulate a sub structure 
    SAFEARRAY __RPC_FAR * m_saArray;
}CustomINFO;

I am allocating the memory for the structs using CoTaskMemAlloc and encapsulating it in Variant as follows:



vV->vt = VT_RECORD;
vV->pvRecord = pStruct; //Pointer of sturct
vV->pRecInfo = pRI; //RecordInfo Interface

Is it enough to call VariantClear to deallocate the memory of struct and its members? Will it also release the IRecordInfo interface?

Or i have to manually get the encapsulated struct and deallocate each member myself and then use CoTaskMemFree to deallocate sturct.

Thanks

Picaro De Vosio

+1  A: 

VariantClear will call IRecordInfo::Clear, which releases the memory held by members of the struct, but supposedly doesn't release the struct itself (that's why you can't correctly return a struct in an [out] VARIANT). the IRecordInfo should be released, too.

("should" means "otherwise, a lot of existing code would break/be broken").

Some more info here: http://vcfaq.mvps.org/com/4.htm

peterchen
thanks for reply.
Picaro De Vosio