How to create SafeArray of BSTR’s?

Here is a sample to create an array of BSTR’s…

[sourcecode language=’cpp’]const long lCount = 100;
_bstr_t bstrArray[lCount];

COleSafeArray cosaSafeArray;
cosaSafeArray.CreateOneDim( VT_BSTR, lCount )

// Fill out this array
for( long lIndex = 0; lIndex < lCount; ++lIndex ) { cosaSafeArray.PutElement( &lIndex, static_cast( bstrArray[lIndex] );
}

// Now you have a safe array of bstr’s and since COleSafeArray
// is inherited from VARIANT you can directly use this safearray
// in COM calls with no overhead for freeing safe array[/sourcecode]

5 thoughts on “How to create SafeArray of BSTR’s?

Appreciate your comments...