Re: Excel
- Posted by mattlewis (admin) Oct 11, 2010
- 1556 views
I'm a little confused, but that's ok. Things are looking like it will work, so I will plow forward. One thing I'll need at some point, if you get a chance, is the C variations for different types of information which will be sent from Excel. I can see only three things: integers, strings and real numbers. I'll presume the real numbers were what your wrapper addressed and that I could probably make do with the same for integers. I have no clue on how to deal with text, though.
Strings coming from VB are a little weird. They're BSTRINGs. Basically, you receive them as a pointer. The length of the string is stored in the 4 bytes previous to the value of the pointer. The data itself is stored as wide characters. Take a look at EuCOM, which has some code for dealing with these, along with arrays, which you should try to avoid (because they're a PITA). I've actually used the code in EuCOM (about 9 or 10 years ago) to write a DLL that was called by Excel. The EuCOM code was mainly used for dealing with Strings and Arrays coming from VBA.
I don't know what Excel thinks "real numbers" are, but they're probably native doubles.
My confusion (one of many, of course) is based on the language of your wrapper. Where you use the lines:
a = NewDouble( ad ); b = NewDouble( bd ); c = _1MyFunction( a, b );
it doesn't seem to be consistent with: "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."
Unless, of course, NewDouble is the function for converting a double into a Euphoria atom.
Yes, NewDouble() is the back end euphoria function that allocates a Euphoria atom that is stored as a double. In addition to the actual double, it also stores reference counting and cleanup information. The calls to DeRefDS() de-reference the objects, making sure that the memory they use is freed.
Matt