Financial Instruments carry risks... & plenty of rewards for those who master them!

|

Tools

 | 

Analytics

 |

Risk-Engine

|

Technology 

|

Data

|

 
     

XLL and DLLs

 

XLL/DLL packaging has been available since Excel Version 3.0.
Typelibs, Standalone COM, automation and the win32 declare just cannot, at least yet, 
fit right into that cell as the users would like. 
Truth is the callback mechanism used to load the XLL/Excel dll is at the heart of Excel. 
This means that other hookups are merely additional layers on top of this mechanism.

Running XLLs Online directly from your browser

All the tools are designed to run while you are online and offline. 
To run the add-ins directly from your browser while you are online, open the zip file 
(that is, select open rather than save when you download the file), 
this will launch the unzip package and display the decompressed files in the standard zip dialog box.
double-click on the xll add-in. Then  double-click on the xls spreadsheet.
You can now use all the functions directly from your browser!
 

The XLL Registration

The are actually two different ways you can register an XLL.

Temporary Registration: Loading the XLL during the current session.

Simply double-click on the file with an XLL extension in explorer. This will instruct Excel® to load the library and register the functions until the file is closed. 
If you use this method, your file will only be registered temporarily during the current session. You therefore need to load the .xll file each time you want to use the functions in your spreadsheet.

This mechanism has been disabled in Office XP, however security issues have been alleviated. This makes complete sense, since the web is about distributing data not processes.

 

Persistent Registration: Loading the Add-In through the Add-In Manager.

Select the Tools menu and choose Add-Ins. From the dialog box, press the browse button and select the file with the xll extension. Once you have selected the file you want to load, the library name should appear at the top of the list on the left hand side. The check box should be enabled.
This confirms the add-in has been loaded properly by Excel.

This approach loads the add-in permanently at least until you decide to remove it.

To remove, simply click on the add-in name displayed in the list. This should remove the checkmark. If the add-in was designed properly, you should get a confirmation with a message box prompt.

This approach is only recommended if you use the library frequently since it hogs the Excel® resources, which are somewhat limited.

 Register standard DLLs in Excel®

You can actually load any win32 DLL as if it was an XLL, by using the =REGISTER (& CALL) spreadsheet function. (for more information on this function, type = Register/CALL and then press F1 or call the help menu).

Since version 8 VBA carries exactly the same type of function as native VBA code.

CAVEAT EMPTOR:

The REGISTER function mimics the XLL registration sequence.
The VBA declare statement is identical to any standard WIN32 API call.

The results are completely different.

If you use VBA declare, your exported functions will only be available in the VBA code. (This means you will not be able to access the function from the spreadsheet directly). You can however create an additional function wrapper, but this is will never provide the same power offered by XLOPERS. This approach would also add another layer of inefficiency between you and the function.

If you decide to follow the = REGISTER route (which I strongly recommend), you can opt to register your exported procedures as either Macros, Hidden or standard. The difference between hidden and standard function being that the standard function will appear in the Excel® Function Wizard (select Function in the Insert menu). The hidden does not. The Macro (Type 2) will appear as any other VBA Macro function. (ALT+F8).

DLL Registration via =Register

As explained in the Spreadsheet server section, there are two ways of loading dlls in Excel. 
The first is standard to VB and uses the declare to provide Visual Basic the means to access the functions. There are a few problems with this approach. You cannot pass values by reference, you cannot use the XLOPER or FORTRAN _FP structure, there are often portability issues on machines that have slightly different configurations (usually CLSID version conflicts). Worse you cannot access directly the spreadsheet cells.

The Second Method is the method of choice, but requires you understand how a function is registered:

The easiest way to understand how register works is to look at an example:

Let's say you have a c function call DF (DaycountFactor). This function has the following signature:

double DF(long start, long end, char* calculationMethod, char* convention)

With this function you have enclosed the export definition (DEF) file and compiled this file into a dll called dates.dll 

This is typically the statement you would include in the spreadsheet to register the function.

 

=REGISTER(

"D:\dates.dll", 

"DF",
"BJJCC",
"DayCountFactor",
"Start,End,Calculation method,Convention"
,1,
"Financial Dates"
,,"DATES.HLP!103")

The First Argument simply tells the function where to look for the dll.

The Second Argument gives the name of the function as it is known to the dll.

the third argument tells what type of arguments are expected by the function. 
In this specific instance we have "BJJCC" which means the function will return a double (B) and take two long integers (JJ) and two strings (CC).

The Next argument tells the Register function how we want to call the function within Excel. You can change the name and run the macro to see for yourself.

Then we name the arguments as we want them to appear in the Function Wizard (Menu->insert -> Function)

Then we tell Register if our function will be hidden, standard or a macro. Here we give it a 1, which means we want  standard registration.

Then we define the name of the function category, as it appears in the ("Insert" "Function" list prior to the Wizard.

Then we define the hookup ID for the Help File if we want to provide support when the user clicks on help or presses F1

for further details refer to the spreadsheet server section.

 

Setting up the Help File

 

Top of Page