Re: Excel
- Posted by mattlewis (admin) Oct 11, 2010
- 1531 views
Thanks.
I know Jeremy uses Excel, he can probably run a test in much less time than it would take me. {hint, hint} Just to see whether VBA can successfully utilize a dll created in this manner.
I've done something like this in the past, so I know that it's possible.
I know this is going to sound dumb, but, in looking back on what you wrote, I don't see where the Euphoria logic that I want to apply (within MyFunction) goes. I see that you ran a translation. But it appears the translation was just of the signature. Was it also of the simplistic code that I included? If so, does that imply that the course of action I would need to follow would be to develop the logic of the dll in Euphoria, then translate that into C, so that I could append the appropriate signature wrapper at the end, and then compile at that point?
Sorry for sounding so out of it, but I'm out of my depth here.
This message contains the translated version of the simple example (multiplying two atoms and returning the result). The first block (in the post) contains the translated version, which looks like this:
int _1MyFunction(int _a_144, int _b_145) { ...
That was simply what the translator created based on the euphoria code. My little wrapper function that I hand wrote in C is what's meant to be called by your Excel VBA code. It takes the 'native' double values, and turns them into Euphoria atoms, uses those to call your code, then releases the memory it reserved, and returns the value.
So, the basic idea here is to write your euphoria code, then translate, add the additional wrappers, and finally compile the dll so you can use it. By default, when you run the translator, it translates, compiles and cleans up after itself (deleting the c and obj files).
For this task, however, we need to edit the C files before we build it. I like to use the -makefile-full option. It translates your code, and writes out a makefile that your compiler / build system can use. When using Watcom (as I presume you are), it might look like this:
> euc -makefile-full -dll mikes_excel_code.e Translating code, pass: 1 2 3 4 5 6 7 8 9 10 11 generating 19.c files were created. To build your project, type wmake -f mikes_excel_code.mak -- do your editing here... > wmake -f mikes_excel_code.mak
And it will build your dll for you. I haven't tried this with Watcom lately, but you might need to specify this file for export by adding it to another generated file that defines all of the exported functions.
Matt