RE: QWORD (int64) question
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Oct 17, 2002
- 450 views
Thanks, it looks great. I'd like to know a few other things first though. First off, to get the first param for that function, I'm using GetProcAddress(). I'm using the value returned from open_dll(). I'm not sure if that is right, so I'd like to know. Second, I have a few functions that need to pass floats. So, how would I do this exactly? Just atom_to_float32() and then bytes_to_int() ? TIA Euphoria Instant Messenger Have YOU Joined? http://groups.yahoo.com/group/euim/ >From: Matthew Lewis <matthewwalkerlewis at YAHOO.COM> > > From: Robert Craig [mailto:rds at RapidEuphoria.com] > > Elliott Sales de Andrade writes: > > > I think I asked this before, but I would like to know how > > > to get return values that are QWORD's. Someone said > > > that QWORD's are pointers, but they are not. When > > > passing QWORD's they use two INT's in VB, so it is definitely > > > not 32 bits. I am guessing that I would have to use ASM to do this. > > > > More likely, they use two 32-bit registers. You'd have to > > maybe disassemble some compiled C code to get the answer, > > and then use some machine code similar to Matt Lewis' DLL code. > >I found this on http://gcc.gnu.org/ml/gcc-bugs/2000-02/msg00104.html > >/* > * All the functions listed here are C callable, and may also be called > * from assembly using the C calling mechanism. All INT64 functions > * return their results in edx:eax, where edx is the upper longword. > * Functions returning a long place the result in eax, and the contents > * of edx are destroyed. All other registers are preserved. > */ > >Based on that, I think this code (untested) should work. The only real >change from the standard code (in fptr.e) is that I added the mov edx to >get >the second dword. A similar fix could be added to the cdecl calls. You >can >use this to call a function that returns a qword, and it will return a >sequence of two 32-bit unsigned integers. When I get a chance, I'll work >this into the main lib. > >include machine.e >constant >q_fptr_asm = { > #60, -- 0: pusha > #BB,#00,#00,#00,#00, -- 1: mov ebx, paramcount (2) > #B9,#00,#00,#00,#00, -- 6: mov ecx, params (7) > -- B: start: > #8B,#01, -- B: mov eax, [ecx] > #50, -- D: push eax > #83,#C1,#04, -- E: add ecx, 4 > #4B, -- 11: dec ebx > #75,#F7, -- 12: jnz start > #FF,#15,#00,#00,#00,#00,-- 14: call dword ptr [comfunc] (22) > #A5,#00,#00,#00,#00, -- 1A: mov [retpointer], eax (27) > #A3,#00,#00,#00,#00, -- 1A: mov [retpointer], edx (31) > #61, -- 20: popa > #C3}, -- 21: ret > >q_fptr_paramcount = 2, >q_fptr_params = 7, >q_fptr_funcptr = 22+0, >q_fptr_retptr = 27+0, >q_retval = allocate(8), > >q_fptr_asm_addr = allocate( length( q_fptr_asm ) + 20 * 5 ) > >constant >q_fptr_func = q_fptr_asm_addr + 33, >q_fptr_retval = q_fptr_asm_addr + 37, >q_fptr_param_ptr = q_fptr_asm_addr + 41 > >poke( fptr_asm_q_addr, fptr_q_asm ) >poke4( q_fptr_asm_addr + q_fptr_funcptr, fptr_q_func ) >poke4( q_fptr_asm_addr + q_fptr_params, q_fptr_param_ptr ) >poke4( q_fptr_asm_addr + q_fptr_retptr, q_fptr_retval ) >poke4( q_fptr_asm_addr + q_fptr_retptr + 5, q_fptr_retval + 4 ) > >global function call_fptr_qword( atom fptr, sequence params ) > sequence ret > -- store the pointer to the function > poke4( q_fptr_func, fptr ) > > -- reverse the params for stdcall calling convention > params = reverse(params) > > -- store the params > poke4( q_fptr_param_ptr, params ) > > -- tell the asm how many params to push > poke4( q_fptr_asm_addr + q_fptr_paramcount, length(params) ) > -- run the asm > call( q_fptr_asm_addr ) > > -- get the value returned from the function > ret = peek4u( {q_fptr_retval,2} ) > return ret >end function > >Matt Lewis