XLL+ Class Library (7.0)

MySqrt Example

This example shows how to optionally return an error.

CopyC++
// Function:    MySqrt 
// Returns:     LPXLOPER 
// Description: Returns the square root of the input 
 
//{{XLP_SRC(MySqrt) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code! 
 
#pragma region MySqrt support code
IMPLEMENT_XLLFN4(MySqrt, MySqrt_4, MySqrt_12, "RB", "UB", L"MySqrt", 0, L"Inpu"
    L"t", 0, L"14", 0, L"Returns the square root of the input", 0, L"Number wh"
    L"ose square root is to be returned\0", 0, 0, L"{MySqrt,,,Returns the squa"
    L"re root of the input,14,1,0,U,{{0,{Input,Double,0,,Number whose square r"
    L"oot is to be returned,,,,}}},{},3,,0,0,,,,0,0}", 1, 0, 0)
CXlOper* MySqrt_Impl(CXlOper&, double);
extern "C" __declspec(dllexport)
LPXLOPER12 MySqrt_12(double Input)
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(MySqrt_Impl(xloResult, Input));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 MySqrt_4(double Input)
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(MySqrt_Impl(xloResult, Input));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret4();
}

#pragma endregion

CXlOper* MySqrt_Impl(CXlOper& xloResult, double Input)
{
    // End of generated code 
//}}XLP_SRC 
 
    if (Input < 0.0)
        throw CXlErrorException(xlerrValue);
    xloResult = sqrt(Input);
    return xloResult.Ret();
}

Uses

CXlOper::Ret