XLL+ Class Library

matrix<T>::add_col() Example

// Function:    TestAddMatrixCol
// Returns:     LPXLOPER
// Description: Add a column to a matrix

//{{XLP_SRC(TestAddMatrixCol)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(TestAddMatrixCol, "RJP", "TestAddMatrixCol", 
    "ColsToAdd,Strings", "Example", "Add a column to a matrix", 
    "Number of columns to add\000Vector of strings to be"
    " added\000", "\0\0", 1)

extern "C" __declspec( dllexport )
LPXLOPER TestAddMatrixCol(long lColsToAdd, const COper*
    lpopStrings)
{
    CXlOper xloResult;
//}}XLP_SRC

    BOOL bOk = TRUE;
    CString strError;
    xlp::matrix<CString> mat;
    std::vector<CString> vec;
    const COper& opStrings = *(const COper*)lpopStrings;

    // Check ColsToAdd is in range
    if ( bOk && !(bOk = ( lColsToAdd > 0 )) )
        strError.Format("expected positive integer for %s",
                        "ColsToAdd");

    // Read column of strings
    if ( bOk )
        bOk = lpopStrings->ColToVector(vec, &strError);

    // Resize the matrix
    if ( bOk )
        mat.resize(vec.size(), 0);

    // Add the column to the matrix lColsToAdd times
    // and return a copy of the matrix
    if ( bOk )
    {
        for ( long i = 0; i < lColsToAdd; i++ )
            mat.add_col(&vec[0]);
        xloResult = mat;
    }

    // Report any errors
    if ( !bOk )
        xloResult = "Error: " +  strError;
    return xloResult.Ret();
}

Uses

matrix<T>::add_col