How to return array from XLL function

c++, xll

Solution

I can print an 1X2 array in Excel worksheet now, the following is my code.

**use Func signature type U

1.select one row and two columns

2.Type command =GetArray() in first cell

3.Ctrl + shift + enter

 __declspec(dllexport) LPXLOPER12 WINAPI GetArray(void)
{
    static XLOPER12 xlArray;
    XLOPER12 xlValues[2];
    xlValues[0].xltype = xltypeNum;
    xlValues[1].xltype = xltypeNum;
    xlValues[0].val.num = 123;
    xlValues[1].val.num = 456;
    xlArray.xltype = xltypeMulti|xlbitDLLFree;
    xlArray.val.array.rows = 1;
    xlArray.val.array.columns = 2;
    xlArray.val.array.lparray = &xlValues;
    return (LPXLOPER12)&xlArray;
}

Problem

I am new in writing XLL, Anyone knows how to return a 6x1 array to Excel ? The following is my function (some codes came from other post): ``` __declspec(dllexport) LPXLOPER12 WINAPI GetArr(char* arg1, char* arg2) { vector<double> arr = functionReturnVector; XLOPER12 list; list.xltype = xltypeMulti | xlbitDLLFree; list.val.array.lparray = new XLOPER12[6]; list.val.array.rows = 6; list.val.array.columns = 1; for(int i = 0; i < 6; ++i) { list.val.array.lparray[i] = arr[i]; // error: IntelliSense: no operator "=" matches these operands } return &list; } ``` [2013-02-23] Currently I read the codes from XLL RETURN ARRAY and review my code, it can compile but returns 0 ... ``` __declspec(dllexport) LPXLOPER12 WINAPI GetArr(void) { XLOPER xlArray, xlValues[2]; xlValues[0].xltype = xltypeNum; xlValues[1].xltype = xltypeNum; xlValues[0].val.num = 11; xlValues[1].val.num = 17; xlArray.xltype = xltypeMulti|xlbitDLLFree; xlArray.val.array.rows = 1; xlArray.val.array.columns = 2; xlArray.val.array.lparray = &xlValues; return &xlArray; } ```

Original source