RE: Callback problem
- Posted by Andy Serpa <ac at onehorseshy.com> Oct 13, 2002
- 364 views
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...