XLL+ Class Library

Completing the code

Code generated by the wizard

As you return to DevStudio, you will see that the wizard will has inserted the following source code at the end of your C++ file.

// Function:    NORMSDIST2
// Purpose:     Returns the standard normal cumulative distribution function (has a mean of zero and a standard deviation of one)

//{{XLP_SRC(NORMSDIST2)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(NORMSDIST2, "BB", "NORMSDIST2", "Z", "Statistica"
    "l", "Returns the standard normal cumulative distribution"
    " function (has a mean of zero and a standard deviation of"
    " one)", "Z is the value for which you want the distribution"
    , "\0", 1)

extern "C" __declspec( dllexport )
double NORMSDIST2(double Z)
{
//}}XLP_SRC

    // TODO - Calculate and return the result
    return 0;
}

In the following sections, we'll examine all this code.

Delimiters

The first thing to notice are the comments that delimit the generated code:

//{{XLP_SRC(NORMSDIST2)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    ...
//}}XLP_SRC

The Function Wizard "owns" all the code between the delimiters. Everything between these comments is liable to be written over if you use the Function Wizard again to change the function in any way. Be very careful to make your changes outside these delimiters.

Macro

The next section of interest is the IMPLEMENT_XLLFN2(...) macro:

IMPLEMENT_XLLFN2(NORMSDIST2, "BB", "NORMSDIST2", "Z", "Statistica"
    "l", "Returns the standard normal cumulative distribution"
    " function (has a mean of zero and a standard deviation of"
    " one)", "Z is the value for which you want the distribution"
    , "\0", 1)

This macro contains all the information you typed into the Function Wizard. At run-time, the XLL+ runtime library will pass all this data to Excel, in order to register your function and to tell Excel about its arguments. (Again, be careful not to alter it yourself.)

Declaration

The next line exports the function and ensures that the exported name of the function is not mangled.

extern "C" __declspec( dllexport )

The declaration of the function follows.

We have a complete skeleton of the function; now we need to add some useful code.

Adding some useful code

Add code to the function to call our stand-alone function, as shown below:

extern "C" __declspec( dllexport )
double NORMSDIST2(double Z)
{
//}}XLP_SRC

    return CumNormal(Z);                     
}

That's it. We're now ready to build and test our add-in function.

Next: Building your add-in library in Visual Studio 6 >>