XLL+ Class Library (7.0)

CXlOper::operator [] Example

CopyC++
//{{XLP_SRC(OperBraceExample) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code! 
 
#pragma region OperBraceExample support code
IMPLEMENT_XLLFN4(OperBraceExample, OperBraceExample_4, OperBraceExample_12, 
    "RPH", "UQH", L"OperBraceExample", 0, L"Vector,Index", 0, L"Example", 0, 
    L"Demonstrates the use of COper::operator[ ]", 0, L"Vector argument\0Zero-"
    L"based index into vector\0", 0, 0, L"{OperBraceExample,,,Demonstrates the"
    L" use of COper::operator[ ],Example,1,128,U,{{0,{Vector,Value,0,,Vector a"
    L"rgument,,,,}},{0,{Index,Unsigned Short Int,0,,Zero-based index into vect"
    L"or,,,,}}},{},3,,0,0,,,,0,0}", 1, 0, 0)
CXlOper* OperBraceExample_Impl(CXlOper&, const CXlOper*, unsigned short int);
extern "C" __declspec(dllexport)
LPXLOPER12 OperBraceExample_12(LPXLOPER12 Vector, unsigned short int Index)
{
    XLL_FIX_STATE;
    CXlOper xloResult, Vector__port(Vector);
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(OperBraceExample_Impl(xloResult, &Vector__port, 
            Index));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 OperBraceExample_4(LPXLOPER4 Vector, unsigned short int Index)
{
    XLL_FIX_STATE;
    CXlOper xloResult, Vector__port(Vector);
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(OperBraceExample_Impl(xloResult, &Vector__port, 
            Index));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret4();
}

#pragma endregion

CXlOper* OperBraceExample_Impl(CXlOper& xloResult, const CXlOper* Vector, 
    unsigned short int Index)
{
    // End of generated code 
//}}XLP_SRC

    BOOL bOk = TRUE;

    // Check that Arg1 is a vector, since operator[ ]  
    // demands that is a vector, and asserts if it is not.
    bOk = Vector->IsVector();
    // Check that Index is in range
    bOk = bOk && (Index >= 0);
    bOk = bOk && (Index < Vector->GetCount());

    // If all went well, extract the value. 
    // Otherwise return an error. 
    if ( bOk )
        xloResult = (*Vector)[Index];
    else
        xloResult = xlerrNA;
    return xloResult.Ret();
}

Uses

CXlOper::operator [] | CXlOper::GetCount | CXlOper::IsVector