Re: Excel
- Posted by mattlewis (admin) Oct 11, 2010
- 1542 views
One issue with this is that he wants to pass a double. Euphoria callbacks can't handle doubles being natively passed. They can only take 31-bit integers (or Euphoria Atoms or Sequences).
The desired signature is:
Public Declare Function MyFunction Lib "c:\MyDLLs\MyDLL.dll" _ (ByVal a As Double, ByVal b As Double) As Double
It was just an example. I can live with 31 bit values if I have to (I can get a date or a value up to 21,474,836.48, right?).
Yes, if you're certain you'll only pass integers like that, you should be fine. Bigger integers, or floats or doubles, however, and you'll need to do something like what I showed.
If you translate (I did this on Linux, but should be similar), you should get some thing like :
$ euc -makefile-full -dll vb.e // inside vb.c: int _1MyFunction(int _a_144, int _b_145) { ... snipped ... }
The easiest thing to do here is probably to write a wrapper function right below the above code:
When you say the "above code", what do you mean? In what language is the wrapper function (I only do EU, so if it is C, I'll be stuck).
Yes, that was C. It was from translated euphoria code. You can adapt the wrapper code easily to call a different function. This basic code will work for anything that takes two doubles and returns a double. Other signatures are pretty easy, too.
And then call that. I wrote this test program to use it:
... snipped...
This is testing whether the DLL works from EU, right? Does that necessarily translate into success if the DLL is being called from VBA within Excel?
It was meant just to show that it was working in general, and calling it from euphoria was the easiest way to do it. You'll have to try it yourself in VBA.
Matt