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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dobedani

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

    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.GetCu rrentDirectory( );
    }
    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/DotNet...NetInterop.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.LoadLibr ary("MyLib");
    mylib.getInstan ce.restype = ?
    myInst = mylib.getInstan ce();
    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

Working...