XLL+ Class Library

CXlRef Example

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

//{{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_XLLFN2(CheckArgSize, "RR", "CheckArgSize", "Input", 
    "Demo functions", "Inspect a XLREF passed from Excel", 
    "Input reference\000", "\0", 1)

extern "C" __declspec( dllexport )
LPXLOPER CheckArgSize(const CXlOper* lpxlopInput)
{
    CXlOper xloResult;
//}}XLP_SRC

    // Assume that function will fail
    xloResult = xlerrNA;

    // Is the argument a reference ?
    if ( lpxlopInput->IsRef() )
    {   
        // Get a pointer to the range
        const CXlRef& xlr = lpxlopInput->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