This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: dll question


On 27-May-1998, Tim Newsham <newsham@lava.net> wrote:
> 
>      I have a program which is trying to load a dll at runtime.  The
> program uses LoadLibraryEx to load the library in, then uses GetProcAddress
> to get addresses of various entry points (with appropriate cast operations).
> This much seems to work properly.  I am having problems, however, when
> I try to actually call one of the procedures.  The stack pointer (esp)
> seems to be incorrect after a call to the procedure.  In particular
> I am passing in 3 4-byte arguments (12 bytes).  The emitted code
> looks like:
> 
>     <push args>
>     call *%ebx
>     addl %0xc, %esp
> 
> After the call, the stack pointer seems to be off by 12 bytes (too high).
> Its as if the called procedure popped the arguments itself, leaving
> the stack as it was prior to the caller pushing, and then the caller
> also added 12 to the stack pointer to pop the values, after the function
> returned.
> 
> Is this analysis correct?

Yes, it looks like the called procedure is using the "stdcall"
calling convention rather than the default "cdecl" calling convention.

> If so,  is there some way to tell the compiler that the callee will be
> restoring the stack and that the caller shouldn't bother?

Yes, use `__attribute__((stdcall))' on the declaration of
the function pointer which you use to call the function.
See the "function attributes" section in the "C extensions"
section of the gcc documentation.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]