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

Dobedani dobedani at gmx.net
Tue Jul 15 11:30:19 EDT 2008


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




More information about the Python-list mailing list