ctypes and delphi dll

Thomas Heller theller at python.net
Thu Nov 21 05:24:11 EST 2002


Bernd Zimmermann <zimmermann.edv at t-online.de> writes:

> Meanwhile I got it .... providing the procedures
> arguments in inverse sequence lets the bell ring!
> 
> I am happy with ctypes !
> 
> Bernd

Searching for Delphi calling conventions, I found this page:
http://info.borland.com/techpubs/delphi/delphi5/oplg/procfunc.html#8406

It seems your dll uses the pascal calling convention, while ctypes
only supports cdecl and stdcall. Below is a sketch (untested) of subclasses
which should do the trick:


    class PascalFunction(_DynFunction):
        def __call__(self, *args):
            pascal_args = list(args)
            pascal_args.reverse()
            return _DynFunction.__call__(self, *pascal_args)

    class PascalDLL(CDLL):
        def __getattr__(self, name):
            func = PascalFunction(name, self)
            setattr(self, name, func)
            return func

    pascaldll = _DLLS(PascalDLL)

Should ctypes support the pascal calling convention 'natively'?
Maybe later...

Thomas



More information about the Python-list mailing list