XLL+ Class Library (6.3)

CXlRef Example

This example shows how to use CXlOper::IsRef() and CXlOper::GetRef() to obtain a range reference from a reference-type function argument. The range is inspected and the greater of its width and height is returned.

CopyC++
//{{XLP_SRC(CheckArgSize) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN3(CheckArgSize, CheckArgSize_4, CheckArgSize_12, "RR", "UU", 
    L"CheckArgSize", 0, L"Input", 0, L"Demo functions", 0, L"Inspect a XLREF p"
    L"assed from Excel", 0, L"Input reference\0", 0, 0, L"{CheckArgSize,,,Insp"
    L"ect a XLREF passed from Excel,Demo functions,1,128,U,{{0,{Input,Referenc"
    L"e,0,,Input reference,,,,}}},{},3,,0,0}", 1)
CXlOper* CheckArgSize_Impl(CXlOper&, const CXlOper*);

extern "C" __declspec(dllexport)
LPXLOPER12 CheckArgSize_12(LPXLOPER12 Input)
{
    XLL_FIX_STATE;
    CXlOper xloResult, Input__port(Input);
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(CheckArgSize_Impl(xloResult, &Input__port));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 CheckArgSize_4(LPXLOPER4 Input)
{
    XLL_FIX_STATE;
    CXlOper xloResult, Input__port(Input);
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(CheckArgSize_Impl(xloResult, &Input__port));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret4();
}

CXlOper* CheckArgSize_Impl(CXlOper& xloResult, const CXlOper* Input)
{
    // End of generated code 
//}}XLP_SRC 
 
    // Assume that function will fail
    xloResult = xlerrNA;

    // Is the argument a reference ? 
    if ( Input->IsRef() )
    {   
        // Get a pointer to the range 
        const CXlRef xlr = Input->GetRef();
        // Return larger of width and height, as a number
        xloResult = (double)((xlr.Width() > xlr.Height()) 
            ? xlr.Width() : xlr.Height());
    }
    return xloResult.Ret();
}

Uses

CXlRef