SWIG CallBack from C++ into Java-Class

Discussion in 'Java' started by HalloUlrich, Apr 12, 2007.

  1. HalloUlrich

    HalloUlrich Guest

    I tried from Java-Example in SWIG:

    public static void main(String[] args)
    {
    System.out.println("Adding and calling a normal C++ callback");
    System.out.println("----------------------------------------");

    Caller caller = new Caller();
    Callback callback = new Callback();

    caller.setCallback(callback);
    caller.call();
    caller.delCallback();

    callback = new JavaCallback();

    System.out.println();
    System.out.println("Adding and calling a Java callback");
    System.out.println("------------------------------------");

    caller.setCallback(callback);
    caller.call();
    caller.delCallback();

    // Test that a double delete does not occur as the object has
    already been deleted from the C++ layer.
    // Note that the garbage collector can also call the delete()
    method via the finalizer (callback.finalize())
    // at any point after here.
    callback.delete();

    System.out.println();
    System.out.println("java exit");
    }
    }

    class JavaCallback extends Callback
    {
    public JavaCallback()
    {
    super();
    }

    public void run()
    {
    System.out.println("JavaCallback.run()");
    }
    }

    ***********************************************

    But the Call into Java does not work. (Both callbacks only in c++).
    Knows somebody why?

    Regards, Ulrich
     
    HalloUlrich, Apr 12, 2007
    #1
    1. Advertising

  2. HalloUlrich

    migger

    Joined:
    May 4, 2011
    Messages:
    1
    Location:
    Moscow
    Most probably you just forgot to add
    Code:
    %module(directors="1") example
    ....
    %feature("director") Callback;
    ... 
    
    In your *.i file
     
    migger, May 4, 2011
    #2
    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. Markus von Ehr

    SWIG callback problem on win32

    Markus von Ehr, May 18, 2004, in forum: Python
    Replies:
    1
    Views:
    414
    Markus von Ehr
    May 18, 2004
  2. Jeff
    Replies:
    0
    Views:
    730
  3. HalloUlrich
    Replies:
    0
    Views:
    948
    HalloUlrich
    Apr 12, 2007
  4. Keith Sabine
    Replies:
    0
    Views:
    580
    Keith Sabine
    Jun 6, 2008
  5. Lyes Amazouz
    Replies:
    2
    Views:
    170
    Lyes Amazouz
    Aug 20, 2008
Loading...

Share This Page