Re: cdecl support

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

"Matthew Lewis" <matthewwalkerlewis at YAHOO.COM>

 wrote:

> 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

Hey Matt,

By George I think youve done it!

ITS ALIVE!    hehe blink

I havent done extensive test on the routine but it works so far.
I should have more test done on this tonight and I'll let you know
what happens.

Only draw back thus far is, it sure is alot of extra typing.
But I sortof expected this.

Later,

Euman
euman at bellsouth.net

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

Search



Quick Links

User menu

Not signed in.

Misc Menu