|
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
|