Sen a pointer to function to external DLL from VBA (Excel 97)

How can I send a pointer to a function (developed in my excel 97 workbook, in VBA) to an external function in a DLL? The function pointed to by the pointer will follow the rules of parameter needed.
Do you know if it's possible, and if I must care about the parameter passing, erc?

Please, send a simple example. Thanks a lot
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

rondeaujConnect With a Mentor Commented:
inside your dll you would use this line:

if the name of your function is

MyFunction(Anything as Long) as Long

then you would get the address like this:

Lx = Addressof(MyFunction)

you could also include it in your enum api call like this

hwnd& = me.hwnd
retval& = 0

EnumWindows(hWnd&, Addressof(Myfunction), retval&)

I don't know if it is yet a feature of VBA, but VB has a keyword, "AddressOf", which is used for exactly that - to create a pointer to a procedure in order to pass it in an API call.

Check your VBA Help files to see if "AddressOf" appears.  If so, it will probably even have an example that's relevant.  If not, if VBA doesn't have this, then it's going to be very difficult to do what you want.

mquilesAuthor Commented:
Unfortunately, it doen't work in VBA. Thanks for your help
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

VBA does not support SubClassing. You could write a Dll in VB and call that from your VBA mod
mquilesAuthor Commented:
But, how can I give the address of the fucntion in the VB DLL, to a C DLL?
mquilesAuthor Commented:
Ok, it works! Thanks for your help
All Courses

From novice to tech pro — start learning today.