Returning arrays from custom worksheet functions in xll files

J

JacksonRJones

Hello. I was trying to figure out how to return an array from a custom
worksheet function in an .xll file created using visual c++ 2005 express. I
haven't had a problem returning single numbers, but arrays don't seem to be
working. I want the returned array to fill a column of cells, but I can't
quite seem to figure it out. I've tried returning an XLOPER and it compiles
fine, and the add-in opens, but I get the following error when I try to use
the function:

Unhandled exception at 0x1000144c (xceltest.xll) in EXCEL.EXE: 0xC0000005:
Access violation writing location 0x00000000.

Here is the relevant portion of the code (the function table and the
function). I haven't updated the descriptions of the function in the
function table, but that shouldn't make a difference. Thanks in advance to
anyone who helps with this:

static char gszFunctionTable[NUM_FUNCTIONS][NUM_REGISTER_ARGS][MAX_LENGTH] =
{
{" AddTwo", // procedure
" RBB", // type_text
" AddTwo", // function_text
" d1, d2", // argument_text
" 1", // macro_type
" xceltest Add-In", // category
" ", // shortcut_text
" ", // help_topic
" Adds the two arguments.", // function_help
" The first number to add.", // argument_help1
" The second number to add." // argument_help2
}
};


EXPORT XLOPER WINAPI AddTwo(double d1, double d2)
{
XLOPER xlArray, xlValues[2];


xlValues[0].xltype = xltypeNum;
xlValues[1].xltype = xltypeNum;
xlValues[0].val.num = d1;
xlValues[1].val.num = d2;


xlArray.xltype = xltypeMulti;
xlArray.val.array.lparray = &xlValues[0];
xlArray.val.array.rows = 1;
xlArray.val.array.columns = 2;

return xlArray;
}
 

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