After you have installed XLL+, follow these instructions for the quickest possible introduction to using XLL+. You can find out more about any of the steps by clicking on the "More..." links.
Start Microsoft Visual Studio.
Open the New Project window and use the XLL+ AppWizard to create a new project of type XLL+ 7 Excel Add-in. Accept all the default choices in the Wizard's pages.
Open the main (.cpp) source file and use the XLL+ Function Wizard item on the Tools menu to open the create a new add-in function.
On the Tools menu, click the New XLL+ Function item and then fill in the function's name, and press OK.
In the XLL+ Function Wizard, add the function's description and category, add the names, types and descriptions of your function's arguments, and press OK.
In Visual Studio, add your own code to the skeleton generated by the Wizard, then
build and test your project. The code below sets the result of the function to
-999.9
.
As with all the example code in this guide, the code which the developer should add
is shown in inverse.
CXlOper* HISTVOL_Impl(CXlOper& xloResult, const CXlOper* Prices_op, double DaysPerYear) { // Input buffers std::vector<double> Prices; // Validate and translate inputs XlReadVector(*Prices_op, Prices, L"Prices", XLA_TRUNC_ONEMPTY| XLA_TRUNC_ONBLANK); // End of generated code //}}XLP_SRC // TODO - set the value of xloResult, or return another value // using CXlOper::RetXXX() or throw a CXlRuntimeException. xloResult = -999.9; return xloResult.Ret(); }
In a real-world example, you would now pass the inputs to a useful function, and return the result, or handle any errors. For example, you might add the try-catch block shown below:
CXlOper* HISTVOL_Impl(CXlOper& xloResult, const CXlOper* Prices_op, double DaysPerYear) { // Input buffers std::vector<double> Prices; // Validate and translate inputs XlReadVector(*Prices_op, Prices, L"Prices", XLA_TRUNC_ONEMPTY| XLA_TRUNC_ONBLANK); // End of generated code //}}XLP_SRC try { xloResult = CalcHistVol(Prices, DaysPerYear); } catch(...) { xloResult = xlerrValue; } return xloResult.Ret(); }
For a more thorough introduction to XLL+, read through the topics in the Getting Started section.