Type conversion from System:Object * to double

G

Guest

I'm trying to write a routine that mixes managed and unmanaged types
I'm having trouble getting the data elements from the managed array
datatype using GetValue and storing them in a unmanaged dat
structure. I'm a c programmer who is brand new to MC++ and C++
in general and don't know how to do type conversions yet between
simple managed types and unmanaged types. Anyone out there have
some tips for me

#using <mscorlib.dll
#include "fcvbdotnet.h

int ConvertObjectDouble( double ArrayObject __gc[], LPXLOPER far * MTObject

int dimensions = 0
int rowcount = 0, colcount = 0
int rowlobound = 0, rowhibound = 0
int collobound = 0, colhibound = 0
int rowindex = 0, colindex = 0
System::Object __gc * temp
double far *templist = NULL
//double element

dimensions = ArrayObject->Rank

/* check the array dimensions *
if ((dimensions != 1) || (dimensions != 2)
return( -1 ); /* bad array input *

/* get the bounds of the rows and cols *
switch (dimensions

case 0
break
case 1
rowlobound = ArrayObject->GetLowerBound(0)
rowhibound = ArrayObject->GetUpperBound(0)
rowcount = rowhibound - rowlobound + 1
colcount = 1
break
case 2
rowlobound = ArrayObject->GetLowerBound(0)
rowhibound = ArrayObject->GetUpperBound(0)
rowcount = rowhibound - rowlobound + 1
collobound = ArrayObject->GetLowerBound(1)
colhibound = ArrayObject->GetUpperBound(1)
colcount = colhibound - collobound + 1
break
default
return( -1 ); /* bad array input *


// allocate enough memory to hold all the elmenents in the arra
templist = (double far *) malloc( (rowcount * colcount * sizeof(double)) );
if (templist == NULL) return(ABEND)

// copy the vb array to the temporary lis
switch (dimensions)

case 1
for(rowindex = 0; rowindex < rowcount; rowindex++)

*(templist + rowindex) = dynamic_cast<double *> (ArrayObject->GetValue(rowlobound + rowindex, collobound))

break

case 2
for(rowindex = 0; rowindex < rowcount; rowindex++)

for(colindex = 0; colindex < colcount; colindex++)

*(templist + (rowcount * colindex) + rowindex) = dynamic_cast<double> (ArrayObject->GetValue( rowlobound + rowindex, collobound + colindex))

}
break

default
free( templist ); /* free local temporary table *
return(ABEND)
}

// convert the array to XLOPER data typ
//*MTObject = ConvertToXLOPER2(templist, (int) rowcount, (int) colcount)

// return to caller as successfu
return(NORMAL)

} /* ConvertObjectDouble */
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top