Delphi extension

  • Thread starter Donald L. Dietmeyer
  • Start date
D

Donald L. Dietmeyer

I was given a libxx.so that was probably written in Delphi.
I need to wrap it so that I can call the functions/procedures
of the library from Python. I tried the usual extension
technique compiling a C file. I don't get anything meaningful
back when I call, so it doesn't work, or I am missing some
critical point. I have spent a good deal of time searching
the net, and found one or two comments about doing the job,
but no evidence that anyone has done it.

I would appreciate any suggestions or advice.
Don
 
C

Christopher T King

I was given a libxx.so that was probably written in Delphi.
I need to wrap it so that I can call the functions/procedures
of the library from Python. I tried the usual extension
technique compiling a C file. I don't get anything meaningful
back when I call, so it doesn't work, or I am missing some
critical point. I have spent a good deal of time searching

I don't know anything about Delphi; it may use a different calling
convention than C (unlikely). If that's the case, however, you're out of
luck unless you can find a Delphi-C or Delphi-Python interface module.

Assuming it uses the C calling convention, you can possibly use the dl
module:

import dl
c=dl.open('/path/to/my/lib.so')
c.call('myfunc',arg1,arg2)

dl is unfortunately limited to passing integers, strings, and NULL, and to
returning integers, so it's likely not to be useful for complex data
structures.
 
P

Peter Hansen

Donald said:
I was given a libxx.so that was probably written in Delphi.
I need to wrap it so that I can call the functions/procedures
of the library from Python. I tried the usual extension
technique compiling a C file. I don't get anything meaningful
back when I call, so it doesn't work, or I am missing some
critical point. I have spent a good deal of time searching
the net, and found one or two comments about doing the job,
but no evidence that anyone has done it.

I would appreciate any suggestions or advice.

Would ctypes work for you? http://starship.python.net/crew/theller/ctypes/
 
J

Jarek Zgoda

Christopher T King said:
I don't know anything about Delphi; it may use a different calling
convention than C (unlikely). If that's the case, however, you're out of
luck unless you can find a Delphi-C or Delphi-Python interface module.

Register is default call convention for libraries written in Delphi, but
one may use any other at will.
 
J

John J. Lee

Jarek Zgoda said:
Register is default call convention for libraries written in Delphi, but
one may use any other at will.

A bit of a Delphic utterance...

Googling, it seems 'Register' is what MSVC calls __fastcall.

Not sure how you tell which Delphi functions obey which calling
convention, but (in the absence of a more polished method) I think I'd
attempt to find that out, then write a thin wrapper of the Delphi
interface in C, with explicit calling convention declarations
(eg. __fastcall), then wrap *that* with SWIG.


John
 
C

Christophe Cavalaria

John said:
A bit of a Delphic utterance...

Googling, it seems 'Register' is what MSVC calls __fastcall.

Not sure how you tell which Delphi functions obey which calling
convention, but (in the absence of a more polished method) I think I'd
attempt to find that out, then write a thin wrapper of the Delphi
interface in C, with explicit calling convention declarations
(eg. __fastcall), then wrap *that* with SWIG.


John

Use cdecl in Delphi so declare a function with C calling convention. No need
to create a wraper in C to do that.

procedure DoSomething; cdecl;
 
J

John J. Lee

Christophe Cavalaria said:
Use cdecl in Delphi so declare a function with C calling convention. No need
to create a wraper in C to do that.

procedure DoSomething; cdecl;

He probably doesn't even have a Delphi compiler. He just has this
Delphi DLL somebody's given him to wrap.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
FloridaHan

Latest Threads

Top