This example shows how to return an array of numbers from an add-in function.
// Function: MyDaysInMonth
// Returns: LPXLOPER
// Description: Returns an array of all the days in a given month
//{{XLP_SRC(MyDaysInMonth)
// NOTE - the FunctionWizard will add and remove mapping code here.
// DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(MyDaysInMonth, "RH", "MyDaysInMonth", "Month",
"User Defined", "Returns an array of all the days in a given"
" month", "Month number (1-12)\000", "\0", 1)
extern "C" __declspec( dllexport )
LPXLOPER MyDaysInMonth(USHORT usMonth)
{
CXlOper xloResult;
//}}XLP_SRC
if ( usMonth < 1 || usMonth > 12 )
xloResult = xlerrValue;
else
{
// How many days in the month ?
int cDays;
switch ( usMonth ) {
case 2:
cDays = 28;
break;
case 4: case 6: case 9: case 11:
cDays = 30;
break;
default:
cDays = 31;
break;
}
// Allocate and fill array
double* adDays = new double[cDays];
for ( int i = 0; i < cDays; i++ )
adDays[i] = (double)(i + 1);
// Apply to xloResult
xloResult.FromDoubleArray(adDays, cDays);
// Clean up array
delete[] adDays;
}
return xloResult.Ret();
}