Re: stdcall / cdecl -- please clarify

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

Andy Serpa writes:

> Regarding the problem with calling functions using cdecl in .dll files:
> 
> I am not a C programmer, so this is not completely clear to me.  Will 
> the corruption/errors only occur when using the Translator?  If I use 
> the interpreter with these .dll's, do I have no worries?
> Can this problem be gotten around by using the Translator with Watcom 
> for my Euphoria programs, or is it the .dll that needs to be altered?  
> (I believe the latter, but I'm not positive.)

Euphoria was designed to call  __stdcall routines, not __cdecl.
However, I noticed that the interpreter (compiled by Watcom), as well as
Translated code compiled by Watcom, can handle almost all
calls to __cdecl routines. This is due to the way that Watcom generates
code for handling the stack pointer. It's really just by luck that this works,
and I suspect it won't work if you try to pass or receive C doubles.
Most calls however use C integers and C pointers.

> Would it be possible to make a simple "intermediate" C program or .dll 
> that is called with stdcall, which then in turn calls the desired .dll 
> using cdecl?  In other words, my Euphoria program calls a function in a 
> .dll using stdcall.  That fuction calls the 2nd .dll  using cdecl.  

Yes, that should work fine.

> Would this slow things down?

It will slow things down slightly. 
The question is whether you will notice the slow down.
If you are calling WIN32 GUI routines, you won't notice it at all.
For it to be noticable, you'd have to be calling C routines
that do almost nothing before returning.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu