Invoking non-static methods of a non-Python object instance

D

Dobedani

Dear All,

For some time now, I have been working with the ctypes module on
Windows. First I got my hands on a library developed with Delphi 7.
That library is exporting plain functions. Internally, reference is
made to the instance of a class, which is instantiated in a kind of
initialization section. Everything works fine.
Now, I have developed a library in C#. I am able to get the result
from static methods, e.g.
public static String sayHello() {
String msg = "Hello from MyLib, working in folder ";
return msg + Directory.GetCurrentDirectory();
}
To make sure that the libray can work as a Win32 library, I have added
a V-Table by disassembling and then editing the IL code then compiling
again, see: http://www.blong.com/Articles/DotNetInteropD8/Interop1/Win32AndDotNetInterop.htm

However, in my code I am actually exporting the methods of a class and
I added non-static methods - unlike what was the case with the DLL
developed in Delphi. Unfortunately, it appears impossible to keep a
reference to an instance of my class in the Python code. Suppose, I
remove the keyword "static" from the above method declaration, this
fails whatever I try:
from ctypes import *;
mylib = windll.LoadLibrary("MyLib");
mylib.getInstance.restype = ?
myInst = mylib.getInstance();
print myInst.sayHello();

Is there a way to do this? FYI: I don't want to work with win32client,
because this will require that my users install an extra extension and
I am expected to deliver something which can work without such extra
extensions. I look forward to your ideas!

Kind regards,
Dobedani
 

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

No members online now.

Forum statistics

Threads
473,828
Messages
2,569,736
Members
45,520
Latest member
JudithMorf

Latest Threads

Top