problem returning an array to Excel

Jan 9, 2013 at 6:33 PM
Edited Jan 9, 2013 at 6:35 PM

Hi, thank you for the library which makes very convenient coding the functions in Excel.

While trying to implement a simple test case of a calculator, using handles and cpp domain classes, all works except for ability to return an array with results.

Read several times through the FP page and ARRAY addin examples - still no intended result, getting "1.09327E+16" instead of 3 cells filled in - am I missing something obvious? The code is below:

Any help is much appreciated!

Alex

 

static AddInX xai_viewBasicStats(
	FunctionX(XLL_FP, _T("?xll_viewBasicStats"), _T("Calculator.viewBasicStats"))
	.Arg(XLL_HANDLEX, _T("Handle"), _T("is a handle to BasicStats object "))
	.Category(CATEGORY)
	.FunctionHelp(_T("Displays the given BasicStats instance as a row"))
	.Documentation(
		_T("Calculator.viewBasicStats - Displays the given BasicStats instance as a row")
	)
);

_FP* WINAPI
xll_viewBasicStats(HANDLEX h)
{
#pragma XLLEXPORT
	static FPX output;
	
	try {
		handle<BasicStats> stats_(h);
		ensure (stats_);

		output.reshape(4, 1);
		ensure (output.size() >= 4);

		output[0] = stats_->getCount();
		output[1] = stats_->getAvg();
		output[2] = stats_->getSum();	
	}
	catch (const std::exception& ex) {
		XLL_ERROR(ex.what());
	}

	return output.get();
}