c++ calling java calling c++ ...

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

    c++ calling java calling c++ ...

    Hi,

    i'm currently working on a plugin for Adobe InDesign and i have some
    problems with that. I'm not really a c++ guru, maybe somebody here has
    an idea how to solve this.

    The plugin is written in C++ and it's calling a java application. This
    application displays a window and pushing a button is calling back the
    c++-plugin again.

    // The plugin class. CActionComponen t is part of the InDesign SDK
    class MyJNIComponent : public CActionComponen t {
    public:
    ...
    static void onCreateDocumen t();
    ...
    private:
    ...
    void registerCallbac ks();
    ...
    }

    // this is called from the java application
    JNIEXPORT void JNICALL Java_createDocu ment(JNIEnv *e, jobject o);

    // this is called from Java_createDocu ment()
    void MyJNIComponent: :onCreateDocume nt() {
    ...
    // Here i'm using SDK-methods and functions to create and display a
    document.
    // And here is the problem - i get an assertion from the SDK.
    // The code to create the document is ok, i used this code before
    and i can
    // call this method from inside the plugin without assertion
    ...
    }

    // Register Callback from the Java Application back to the Plugin
    void MyJNIComponent: :registerCallba cks() {
    jint res;
    JNINativeMethod nm;

    // if this method is called in the java application ..
    CJavaClassInsta nce layoutSystemToo lBox("path/to/my/java/class");
    nm.name="create Document";
    nm.signature="( )V";

    // .. call this function in the plugin
    nm.fnPtr=Java_c reateDocument;

    res=CJavaVM::en v()->RegisterNative s(layoutSystemT oolBox.getClass Definition(),&n m,1);
    if (res!=0) {
    CJavaVM::report Error("Can't find the Java_createDocu ment
    method.");
    return ;
    }
    }

    // this function is called from java
    JNIEXPORT void JNICALL Java_createDocu ment(JNIEnv *e, jobject o){
    CJavaVM::env()->ExceptionClear ();
    // calling method in plugin class
    MyJNIComponent: :onCreateDocume nt();
    }

    I think the problem is, that Java_createDocu ment() is not part of the
    MyJNIComponent class and when i'm calling
    MyJNIComponent: :onCreateDocume nt() from Java_createDocu ment() some
    variables are not proper initialized.
    And i don't know how to make Java_createDocu ment() part of the class.
    Or if there is another way to solve this?

    Thanks for any suggestions.
  • benben

    #2
    Re: c++ calling java calling c++ ...

    I don't know but have you tried communicating via socket?

    Ben


    Comment

    • Klaus Friese

      #3
      Re: c++ calling java calling c++ ...

      >I don't know but have you tried communicating via socket?
      No. It's an idea but we have to change everything. At the moment the
      java application works standalone and we're using some code and
      dialogs for the plugin and for an extension for QuarkXPress.

      Comment

      • Vijai Kalyan

        #4
        Re: c++ calling java calling c++ ...

        comp.lang.c++

        The name implies questions concerning the C++ language. Questions about
        JNI and interaction with C++ should go to Java newsgroup because it
        relates to JNI. Not C++.

        -vijai.

        Comment

        • Alf P. Steinbach

          #5
          Re: c++ calling java calling c++ ...

          * Klaus Friese <kfriese at dataplan punkt de>:[color=blue]
          > // And here is the problem - i get an assertion from the SDK.
          > // The code to create the document is ok, i used this code before
          > // and i can call this method from inside the plugin without
          > // assertion
          > ...
          > }[/color]

          So, the problem is in the code you haven't shown.

          Anyway, the title is probably wrong: it seems your problem is "Java calling
          C++ calling Java", or "Java calling C++ calling some Adobe API".

          I do not think at all that the general area is off-topic, because such
          integration is what C++ is often used for. Many questions in that area
          would most be accepted in [clc++m]. However, it seems that what you have is
          not a problem related to C++ usage in general, or the language, but rather
          it seems to be a bug in your code, which would make the question -- with
          relevant code included! -- more appropriate for e.g. [comp.programmin g].

          But in general, if you can get rid of the Java part, do that: pure C++.

          And in general, your problem description seems to be to vague to say more.

          --
          A: Because it messes up the order in which people normally read text.
          Q: Why is it such a bad thing?
          A: Top-posting.
          Q: What is the most annoying thing on usenet and in e-mail?

          Comment

          • Klaus Friese

            #6
            Re: c++ calling java calling c++ ...

            On Sat, 13 Aug 2005 04:11:51 GMT, alfps@start.no (Alf P. Steinbach)
            wrote:
            [color=blue]
            >* Klaus Friese <kfriese at dataplan punkt de>:[color=green]
            >> // And here is the problem - i get an assertion from the SDK.
            >> // The code to create the document is ok, i used this code before
            >> // and i can call this method from inside the plugin without
            >> // assertion
            >> ...
            >> }[/color]
            >
            >So, the problem is in the code you haven't shown.
            >[/color]
            [color=blue]
            >Anyway, the title is probably wrong: it seems your problem is "Java calling
            >C++ calling Java", or "Java calling C++ calling some Adobe API".[/color]
            Java calling c++ is the standard way to use JNI, but i have the other
            direction here.
            We have an large application written in java and now we are writing
            c++ code that uses parts of the java application. So people can use
            the main application and they can use InDesign or XPress and they see
            the same windows and dialogs.
            [color=blue]
            >I do not think at all that the general area is off-topic, because such
            >integration is what C++ is often used for. Many questions in that area
            >would most be accepted in [clc++m].[/color]
            I can try it in clc++m tomorrow (i'm writing from my home account at
            the moment). I also tried to find help in the Adobe User Forums, but
            calling Java from the Plugin is not very commom.

            ---
            Mail-Antworten bitte an klaus punkt friese at hamburg punkt de
            Die andere Adresse ist nur ein Spam-Collector.

            Comment

            • j-integra_support@intrinsyc.com

              #7
              Re: c++ calling java calling c++ ...

              An easier route would be to use J-Integra for COM. It is a
              bi-directional Java/COM interop bridge which allows C++ to talk to Java
              and vice-versa. It supports callbacks, events, etc. It even has a high
              performance native mode (i.e. JNI) built in. Have a look...

              Java interoperability with COM Automation (OLE) & ActiveX components. 100% Java software. Run on any platform. No native code or JNI required.


              Shane Sauer
              J-Integra Interoperabilit y Solutions
              Java interoperability with COM Automation (OLE) & ActiveX components. 100% Java software. Run on any platform. No native code or JNI required.

              When Web Services are not enough

              Comment

              • Roland Pibinger

                #8
                Re: c++ calling java calling c++ ...

                On Sun, 14 Aug 2005 10:38:15 +0200, Klaus Friese <klaus punkte friese
                at hamburg punkt de> wrote:
                [color=blue]
                >Java calling c++ is the standard way to use JNI, but i have the other
                >direction here.[/color]

                No, JNI is both directions, see e.g.


                At first glance, bottle feeding seems simple. All you need is a sterilized bottle and a baby formula prepared according to the instructions on the packaging

                [color=blue]
                >We have an large application written in java and now we are writing
                >c++ code that uses parts of the java application. So people can use
                >the main application and they can use InDesign or XPress and they see
                >the same windows and dialogs.[/color]

                I've used JNI to call Java from C++ but I wouldn't do it again. The
                JNI C++-to-Java interface is _very_ ugly and clumsy (but not the
                Java-to-C++ interface, guess why). Moreover, a minimal Swing
                application consumes at least 40 MB (up to 80MB or more) and you
                cannot unload Java once it has been loaded with the shared library.
                I'd rather communicate by socket (or COM?) with the Java application
                or use a commercial product. You have been warned!!

                Best wishes,
                Roland Pibinger

                Comment

                Working...