Link to home
Start Free TrialLog in
Avatar of cdgough
cdgough

asked on

Creating SAFEARRAY with multiple data types.

I want to create a safe array that contains different types of data. For example, I am trying to create a 2d array with legnth 4. I want all the elements array[0][0], array[0][1], array[0][2], array[0][3], to be BSTRs. I want all the elements array[1][0], array[1][1], array[1][2], array[1][3] to be floats. How can I create this array and set the elements correctly? Please provide sample code.

Here is what I have so far.

  VARIANT ChartData;
  VariantInit( &ChartData );
  ChartData.vt = VT_ARRAY | VT_VARIANT;

  SAFEARRAYBOUND rgb[] = { 4, 0 };
  SAFEARRAY *psa = SafeArrayCreate( VT_VARIANT, 2, rgb );

  if( psa )
  {
    long* data;

    SafeArrayAccessData( psa, ( void ** )&data );

    // SET ARRAY ELEMENTS!!?

    SafeArrayUnaccessData( psa );
  }

  ChartData.parray = psa;
Avatar of ntdragon
ntdragon

you should build a template class named safearray
something like:

template <class T,int S>
class SafeArray:parent{
   T arr1[S];
public:
SafeArray(){}
T&operator[](int x){
//something like
   return arr1[x];
}
~SafeArray(){}
};

in main to make safearray of BSTRs
and another one for flosts

then to make a container in size two that cont[0] will the first safearray
and cont[1] the second

i hope you got the idea






Avatar of cdgough

ASKER

This doesn't look right.

I need two different types of variants in the same array. A single array with some BSTRs and some floats.
ASKER CERTIFIED SOLUTION
Avatar of sharonk
sharonk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdgough

ASKER

This is exactly what I was looking for. Thanks.