Converting between array sorts

Apologies if this is a daft question cant seem to find much documentation on MSDN about this.

I would like to take all CStrings out of my CStringArray and put them into a "SAFEARRAY". But I am struggling this is what i have so far:

void convert_between_array_types(CStringArray &str_array, VARIANT &pVariant)

{

SAFEARRAYBOUND safeBound[1];

safeBound->cElements = str_array.GetSize();

safeBound->lLbound = 0;

LONG *temp;

pVariant.vt = VT_BSTR;

pVariant.parray = SafeArrayCreate(VT_BSTR,1,safeBound);

for (int i =0; i < str_array.GetSize(); i++)

{

CComVariant variantText( SysAllocString (str_array.GetAt(i) ) );

SafeArrayPutElement(pVariant.parray,(LONG*)i,&variantText);

}

}

It seems to fail on the second itteration of the for loop. I think this is because i need to be adding a range using the SafeArrayPutElement method Please indicate otherwise if i'm wrong. If this is the case how would i do that

Thanks

Will



Answer this question

Converting between array sorts

  • TiborK

    wdhough wrote:

    My Mistake! It would seem the second parameter for the SafeArrayPutElement, requires a two dimensional reference despite the fact that i assumed that i declared it 1 dimenional.

    Sorry chaps

    If it's an option, I'd recommend that you use CComSafeArray - will save you a lot of pain :-)



  • YCT

    My Mistake! It would seem the second parameter for the SafeArrayPutElement, requires a two dimensional reference despite the fact that i assumed that i declared it 1 dimenional.

    Sorry chaps


  • simakas

    Hi All,

    I have a TextBox in a form that has the property RightToLeft is set to Yes.

    The TextBox is also Right to Left by default.

    I need to set the default language of the TextBox to arabic.

    Thank you.
    Bishoy


  • Converting between array sorts