RE: cdecl support
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> Feb 26, 2002
- 421 views
> -----Original Message----- > From: euman at bellsouth.net [mailto:euman at bellsouth.net] > I gave up about a week ago trying to get it to work properly. > I tried Matts routines, Mic has some routines in his GLU project > and some of my own routines that never seemed to work right. > > I can get handles to the Euphoria routine but when a .dll requires > that these routines (Eu routines) be cdecl also, I threw up my hands. > > I too would like a work around cause I wanted to use cabinet.dll > to extract files from compressed MS-Cab's. > > Euman > euman at bellsouth.net > > From: "Brian Broker" <bkb at cnw.com> > > For Matt Lewis and/or Euman: Did you guys come up with a > relatively > > clean solution for defining cdecl callbacks? > > > > For Robert Craig: How long before a 2.4 alpha with cdecl support? > > > > For anybody with source: Anybody willing to build me a PD > interpreter > > with cdecl support? I'm getting frustrated without it. I finally had some time to look at the problem in detail. I've got cdecl callbacks to Euphoria working (ie, you can call Eu routines using cdecl), and I think I figured out how to call a cdecl routine (had an epiphany right before bed last night). Here's how to make a cdecl callback: -- Start code include machine.e include misc.e include dll.e constant func_asm = { #55, -- 0: push ebp #89,#E5, -- 1: mov ebp, esp #51, -- 3: push ecx #B9,#00,#00,#00,#00, -- 4: mov ecx, argnum (5) #89,#E6, -- 9: mov esi, esp #83,#C6,#0C, -- B: add esi, 12 #BF,#00,#00,#00,#00, -- E: mov edi, myargs (15) #F3,#A5, -- 13: rep movsd; next we call the proc #FF,#15,#00,#00,#00,#00,-- 15: call dword ptr [pfunc] (#17) #59, -- 1B: pop ecx #89,#EC, -- 1C: mov esp, ebp #5D, -- 1E: pop ebp #C2,#00,#00,#00,#00} -- 1F: ret [argnum] (#20) constant offset = length( func_asm ) global function new_pfunc_cdecl( atom callback, integer args ) atom func_addr, func_retval, func_pfunc, func_args func_addr = allocate( length(func_asm) + 4 * 12 ) poke( func_addr, func_asm ) func_retval = func_addr + offset func_pfunc = func_retval + 4 func_args = func_pfunc + 4 poke4( func_addr + #05, args ) poke4( func_addr + #0F, func_args ) poke4( func_addr + #17, func_pfunc ) --poke4( func_addr + #20, ( args + 0 ) * 4 ) poke4( func_pfunc, callback ) return { func_addr, func_args } end function atom my_cdecl_args function my_cdecl_func() sequence args args = peek4u( {my_cdecl_args , 2}) -- do stuff return 1 end func object my_cdecl_callback my_cdecl_callback = new_pfunc_cdecl( call_back(routine_id("my_cdecl_func")), 2 ) my_cdecl_args = my_cdecl_callback[2] my_cdecl_callback = my_cdecl_callback[1] -- Now you can pass my_cdecl_callback to a dll that uses cdecl