RE: Callback problem

new topic     » goto parent     » topic index » view thread      » older message » newer message

Andy Serpa wrote:
> 
> stabmaster_ at hotmail.com wrote:
> > >This sounds like the cdecl-stdcall problem.

> > 
> > I did just that in Glue, my GLUT wrapper for Euphoria. In glue.e there 
> > is a 
> > function called cdecl_callback that takes a routine_id and a sequence of 
> > 
> > 

Here's a little cleaner version of the function, without the need for 
asm.e.  I guess this way you are still limited to a less than 9 args:


constant cdecl_asm =
{
    #B8,#00,#00,#00,#00,    --    0: mov eax,callback (1)
    #FF,#D0,                --    5: call near eax
    #83,#EC,#00,            --    7: sub esp, [num args * 4] (9)
    #C3                     --    A: ret
}

function cdecl_callback(atom r_id, integer args)
-- your callback function must use an extra dummy arg
-- before the real args
atom addr

	addr = allocate(11)
	poke(addr,cdecl_asm)
	poke4(addr+1,call_back(r_id))
	poke(addr+9,args * 4)

	return addr
end function


Then, get your callback address like this:

my_callback_addr = cdecl_callback(routine_id("my routine"),num_args)

& don't forget your dummy arg...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu