Re: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values



alex <alecla@xxxxxxxxxx> wrote:

Jon
Thank you for your answer. I tried it with no success.

However I tried with
tst=cdll.LoadLibrary("f:\\scratch\\test2\\footst.dll") instead of
tst=windll.LoadLibrary("f:\\scratch\\test2\\footst.dll")

and it runs now with no error message, I can't figure for now why, but
it's great! This is motivating for going ahead.

cdll is for importing functions which use the cdecl calling convention
where the caller must clean up the stack.

windll is for functions that use the stdcall calling convention: the
function that is called is responsible for cleaning up the stack.

If you were using windll when you should have been using cdll then ctypes
will have been expecting the library to clean up the stack, and the library
will have been expecting the caller to do the cleanup, so nobody cleaned up
the stack.

The error message was telling you that ctypes pushed 4 bytes of argument
onto the stack which weren't popped off by the caller. If you had been
using the correct calling convention that would have indicated you had
passed too many arguments, but as you were using the wrong calling
convention the message was a bit unclear.


--
Duncan Booth http://kupuguy.blogspot.com
.



Relevant Pages

  • Re: StdCall vs. CDecl
    ... __cdecl means that the caller needs to remove the args. ... caller to clean up the stack, while the caller will expect the function to ... why does our VB.NET code work well when the calling convention ...
    (microsoft.public.dotnet.framework.interop)
  • Re: passing to C function less argument than required
    ... problem running at all. ... argument, these will be 7 argument in stack, and if the function ... The caller clears the ... calling convention", since most Pascal implementations work that way. ...
    (comp.lang.c.moderated)
  • Re: error in function call
    ... Under __stdcall calling convention, caller ... pushes parameters onto the stack, and callee is responsible for popping ... the stack is corrupted upon return. ... error message tells you. ...
    (microsoft.public.vc.atl)
  • Re: printf doubt
    ... If the format is exhausted while arguments remain, ... same stack, like the old 6502, manage this. ... At least one popular compiler does not. ... The __stdcall calling convention is used to call Win32 API functions. ...
    (comp.lang.c)
  • Re: Calling a "procedure of object" routine w/variable parameters
    ... > Which calling convention are you using for your routines? ... > due to the way cdecl functions put parameters on the stack. ... Basically a Delphi routine is called from C, ...
    (borland.public.delphi.language.basm)