Search code examples
c++comolevariantsafearray

How to convert string array to SAFEARRAY or VARIANT or COleVariant?


i'm working about OLE(COM) ,so that i want to convert string array to SAFEARRAY or CComSafeArray or COleSafeArray or VARIANT or COleVariant.

  1. CString[100] -> SAFEARRAY
  2. CString[100] -> CComSafeArray
  3. CString[100] -> COleSafeArray
  4. CString[100] -> VARIANT
  5. CString[100] -> COleVariant

converted string array to SAFEARRAY or CComSafeArray or COleSafeArray or VARIANT or COleVariant is sended OLEMethod to do COM.

please help me


Solution

  • CString strings[100];
    
    CComSafeArray<BSTR> myArray(100);
    for (int i = 0; i < 100; ++i) {
      myArray.SetAt(i, strings[i].AllocSysString(), /*copy=*/ false);
    }