1. How do you pass data in and out of Euphoria DLLs?
- Posted by axtens Oct 16, 2008
- 1056 views
G'day everyone
I'm developing a Euphoria DLL for use with VB6. How does one pass sequences out from the Euphoria end to the VB6 end?
So far I've worked out that I can pass in an atom that points to the first item of an array of long and fill out the array. I first have to ask the DLL how many longs there are, so that I don't pass in any array that's too small and end up with corrupted memory.
object resultObj global function resultSize() if atom( resultObj ) then return 1 else return length( resultObj ) end if end function global procedure getResult( atom ptr ) if atom( resultObj ) then poke4( ptr, resultObj ) else for i = 1 to length( resultObj ) do poke4( ptr, resultObj[ i ] ) ptr += 4 end for end if end procedure
It's similar to a technique I developed for reading BSTRs that have been passed in using StrPtr(), as below:
function peek_vb( atom ptr ) sequence str, temp, len str = "" ptr -= 4 len = peek( {ptr,4} ) -- get length DWORD ptr += 4 temp = peek( {ptr, 2} ) ptr += 2 while not equal( temp, {0,0} ) do str &= ( temp[2] * 256 + temp[1] ) temp = peek( {ptr,2} ) ptr += 2 end while return { bytes_to_int(len) / 2 , str } end function
The context for all this is that I'm wrapping Mike Sabal's HexMath.e.
Is this all that there is available, or are there other techniques available for returning sequences?
Kind regards, Bruce.
2. Re: How do you pass data in and out of Euphoria DLLs?
- Posted by mattlewis (admin) Oct 16, 2008
- 997 views
I'm developing a Euphoria DLL for use with VB6. How does one pass sequences out from the Euphoria end to the VB6 end?
I think that one issue you may be running into (or might in the future) is passing full 32-bit pointers. If the VB code is actually calling a euphoria generated callback, then this isn't a problem, because the callback mechanism handles this for you. However, if you have external code directly calling a translated routine, euphoria will misinterpret some values as pointers to atoms or sequences, or as simply invalid euphoria objects.
You can use my 32-bit integers in dlls library to allow translated routines to properly use 32-bit integers. Note that if you call a routine converted in this way from euphoria code, you'll need to use the C_* data types instead of E_* datatypes when defining your c-routines. Also, any routine converted in that way shouldn't be called by any euphoria routines in the dll, which is why the documentation recommends the routine be simply a thin wrapper around the real routine, so your internal stuff can safely call the 'real' routine, and external users can call the wrapper.
Matt
3. Re: How do you pass data in and out of Euphoria DLLs?
- Posted by axtens Oct 16, 2008
- 1010 views
You can use my 32-bit integers in dlls library to allow translated routines to properly use 32-bit integers.
Okay, I'll give that a shot as well. But later, as it's just ticked past midnight here in Perth, WA, Australia.
Thanks for all your help thus far.
Kind regards,
Bruce.