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

Discussion in 'Python' started by Dobedani, Jul 15, 2008.

  1. Dobedani

    Dobedani Guest

    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
    Dobedani, Jul 15, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo
    Replies:
    1
    Views:
    506
    Scott Allen
    Jan 7, 2005
  2. Alex Vinokur
    Replies:
    1
    Views:
    398
    Jakob Bieling
    Jul 24, 2003
  3. ketan
    Replies:
    6
    Views:
    281
    Nate Barney
    Sep 14, 2006
  4. lightning
    Replies:
    4
    Views:
    892
    Daniel Pitts
    Oct 30, 2008
  5. Kenneth McDonald
    Replies:
    5
    Views:
    301
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page