BSTR Array Creation

Easy way to create BSTR array. Forget the hastle with SAFEARRAY APIs.                               Home

An easy to create an array of BSTRs. No need to hastle with SafeArray APIs.

STDMETHOD(GetStringArray)(SAFEARRAY** ppsaStrings)
   const int numStrings = 3;
   *ppsaStrings = ::SafeArrayCreateVectorEx(VT_BSTR, 0, numStrings, NULL);   
   BSTR* bstrArray = static_cast((*ppsaStrings)->pvData); 

   for (int i = 0; i < numStrings; ++i)  
      bstrArray[i] = CComBSTR(L"Hello World").Copy();

   return S_OK;