Discussion:
DLL for VBA
(too old to reply)
Jag Man
2004-01-17 18:33:05 UTC
Permalink
I posted this in the Excel Programming NG but so far have gotten no answer.
Perhaps
there are some VBA people?

I have successfully created C++ functions and compiled/linked them into a
DLL,
and called them from VBA after using the Declare statement in the VBA module
where used. However, I need to bind the function to the call at run time,
like can be
in C/C++ using function pointers. One is supposed to be able to do something
like
this using the Application.Run command, but that's where my problem arises.

VBA Help gives a syntax:

expression.Run(Macro, Arg1, Arg2, ...)

where expression evaluates to something that supports the Run method.
"Macro"
is the name of the function to be run. Specifically, it says:
"Macro Required Variant for Syntax 1 (not used with Syntax 2). The macro
to
run. This can be either a string with the macro name, a Range object
indicating where the function is, or a register ID for a registered DLL
(XLL) function. If a string is used, the string will be evaluated in the
context of the active sheet."

I have not been able to make this work for functions that I write and put in
a DLL. Most likely, my problem is I don't know exactly what
" a register ID for a registered DLL (XLL) function" means in this context.
How
does one "register" a DLL function in the sense used here?


TIA

Ed
c***@gmail.com
2017-11-08 21:07:58 UTC
Permalink
This is an old post, I donĀ“t see an answer here, so making my own contribution.

Did you add a .def file with the name of the functions to the C++ project? I believe that the problem was just it, then you just would have to handle the proper arguments of the functions.
Post by Jag Man
I posted this in the Excel Programming NG but so far have gotten no answer.
Perhaps
there are some VBA people?
I have successfully created C++ functions and compiled/linked them into a
DLL,
and called them from VBA after using the Declare statement in the VBA module
where used. However, I need to bind the function to the call at run time,
like can be
in C/C++ using function pointers. One is supposed to be able to do something
like
this using the Application.Run command, but that's where my problem arises.
expression.Run(Macro, Arg1, Arg2, ...)
where expression evaluates to something that supports the Run method.
"Macro"
"Macro Required Variant for Syntax 1 (not used with Syntax 2). The macro
to
run. This can be either a string with the macro name, a Range object
indicating where the function is, or a register ID for a registered DLL
(XLL) function. If a string is used, the string will be evaluated in the
context of the active sheet."
I have not been able to make this work for functions that I write and put in
a DLL. Most likely, my problem is I don't know exactly what
" a register ID for a registered DLL (XLL) function" means in this context.
How
does one "register" a DLL function in the sense used here?
TIA
Ed
Loading...