Can I invoke instance method using JNI pointer

Hi,
In my work, I need to pump data from dll to my java application.. for this I came to the following workaround.
1. Created a static method with (printMe()) in my java class (GrabTest.java)
    public static int count = 5;
    public static int printMe(int a)
        System.out.println("result printMe : " + a);
        return count--;
    }2. Invoked this class object in dll side as follows
     jclass cls = env->FindClass("GrabTest");
     jmethodID mid = env->GetStaticMethodID(cls, "printMe", "(I)I");
     jint count = env->CallIntMethod(cls, mid, 10);
     cout<<"Count =" <<count<<endl;This works fine, i able to invoke the static method of GrabTest class from dll and I can pass an int value from there.
I tried to call a not static method which in GrabTest.java, from dll as follows
        jmethodID mid2 = env->GetMethodID(cls, "printMe", "(I)I");
     jint counter = env->CallIntMethod(cls, mid2, 10);
     cout<<"Counter =" <<counter<<endl;when I try to invoke the instance method from dll, my application get crashes.
So, I would like know,
1. Is there any other way to pump data from dll side to the client application,
2. If i go with the static method to pump the data from dll, weather the other values of class variables of my GrabTest will give problem?
Looking for your guidance on this issue.
Thanks in advance,
Ramesh

856989 wrote:
I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
Why i not want to use reflection because it have "invocation overhead"Wrong.
If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
And the first uses "reflection".
If you use a proxy interface via something like java.lang.reflect.Method
then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
If it was me I would be far more concerned that inserting byte codes was correct for all cases.

Similar Messages

  • Can we invoke a method using BCEL(byte code engineering library)

    Hi i am new in Java bcel,So can anyone guide me in this problem.
    I am searching for some techniques in BCEL to invoke a method of some class just like we use to invoke methods using Java Reflection.I have also tried a Java Assembler named "Jasmin" that used to interact with Operand Stack,Local variable array & Constant Pool etc so i guess this is the same containers with which our BCEL also interact with so then i am wondering why not then there exists a way through which we can invoke a method using BCEL IF this will happen in any case then kindly point it out some direction of help.
    thanks in advance

    856989 wrote:
    I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
    Why i not want to use reflection because it have "invocation overhead"Wrong.
    If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
    And the first uses "reflection".
    If you use a proxy interface via something like java.lang.reflect.Method
    then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
    And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
    If it was me I would be far more concerned that inserting byte codes was correct for all cases.

  • Invoking a method using reflection with json data as argument

    Hi,
    I want to invoke a method using reflection and this method have one argument . Now I want to pass a json data as an argument to this method .Please see the following code.
    int HelloWorld(int Id){
    return Id;
    json data{"Id":43}
    how can I use the reflection to use the json.
    Please provide your guidelines

    Thanks for your reply, I am building a windows console application .And I want to convert the json data to object array to use in Method Base.Invoke method.
    Regards,
    Ethan
    Maybe you could select the correct language development forum here:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages&filter=alltypes&sort=lastpostdesc
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Difference between invoking a method using reflect.proxy and reflect.Method

    Could any one tell me the difference between invoking a method using reflection java.lang.reflect.Method and java.lang.reflect.Proxy
    using both the class, we can invoke a method at runtime
    1)
    Method mthd=cl.getMethod("methodName",parameterName);
    Integer output=(Integer)mthd.invoke(new RunMthdRef(),input);
    2)
    Proxy.newProxyInstance(super.getClass().getClassLoader(), new Class[] { adapter }, new SomeClass(this));
    Does anybody have any idea?

    The two idioms are fundamentally different. Using java.lang.reflect.Method is how we call a method on a class, using Proxy is how we intercept that method call. An exercise for you, to illustrate that they do not do the same thing: write a simple class with one method, then use java.lang.reflect.Method to invoke that method, and then use a Proxy to invoke that method

  • [u][b]perl- can't locate objet method "USE" via strict  package[/b][/u]

    [b[u]
    i am working on Redahat Linux 7.3 with perl 5.6.0
    when ever run the perl script to connect oracle
    i get following message
    " can't locate object method "USE" via package "strict"
    i installed the oracle for perl
    can anyone help to get rid of the problem

    implement synchronizable and createa constructor, then check it once again.

  • How to invoke a window using JNI?

    Hello,
    I need to invoke a C++ DLL from a Java Applet using JNI. The DLL should display an image in a separate window. Further I should be able to set the position of the DLL window, and should be able to minimize, maximize the DLL window from the Applet.
    Well I am fairly new to C++. Any suggestions regarding how I should proceed?
    GLim

    Hi jschell,
    Thanks for the reply.
    But I am sorry that I am not sure whether I understood your point. What I understood is I make an exe that displays the image and run it from Java like SHELL function in VB. In that case can I specify a particular image to be loaded from the applet? The applet and exe needs to be constant touch as the location , size etc of the window displaying the image could be controlled by the applet.
    I have created a DLL which displays the specified the image in a modeless dialog box. I have succeded in invoking the DLL from applet. But the dll window hangs as soon as it loads! I got a suggestion to implement the display of modeless dialog box inside thread. Now I am investigating how to implement thread :) Please send in your advice if you have any?
    Also it could be real help if you could mentions common problems that might occur in such situations.
    Thanks in advance
    gLim

  • How can I invoke a method on a subclass based on the runtime type?

    Hi all,
    I have defined a base class OrderDetail, and 2 subclasses which extend it: OrderDetailSingleReservation and OrderDetailMonthReservation. Furthermore, I have a method:
        public Order order_generate(OrderDetail orderDetail) {
            if (orderDetail instanceof OrderDetailSingleReservation) {
                return order_generate((OrderDetailSingleReservation) orderDetail);
            }  else if (orderDetail instanceof OrderDetailMonthReservation) {
                return order_generate((OrderDetailMonthReservation) orderDetail);
            } else {
                Misc.alert("orderAndInvoice_Generate(GENERIC): unsupported type.");
                return null;
        }The type of this method's parameter is OrderDetail, as you can see. (This particular method only serves as a kind of dispatcher and is therefore not very interesting in itself, but the same pattern using 'instanceof' occurs in a codebase I am working on several times, and I would like to factor it out if possible.)
    My question: it seems that the invocation of order_generate() from within this method requires an explicit downcast to one of the two subclasses. If not, java invokes the method on the superclass. But at runtime, the JVM knows what type of object it is dealing with, right? So is there no way to do this without the explicit downcast?
    A similar problem occurs when trying to invoke a method on an object whose type is one of the subclasses; the method on superclass is called, instead of the one in the appropriate subclass that overrides it.
    Any help would be greatly appreciated!
    Thanks,
    Erik

    Thanks for your replies! I was editing my post last night to clarify it, but my connection went down and the edit was lost :(
    Anyway, yes, it should be done with polymorphism. I was constructing an example using the famous Animal, Cat and Dog classes to demonstrate my question more clearly, and to my surprise the problem does not occur in my example code.
    LRMK: Invoking a method such as in your example, where the method is inside the class itself, works fine. However for MVC's sake, I have a separate class called Invoicing with methods as below:
    class invoicing
      // the method for the superclass
      public Invoice invoice_create(OrderDetail orderDetail) {
         System.out.println("type: " + orderDetail.getClass());
         return null;
      // the method for one of the subclasses (this method is being not invoked)
      public Invoice invoice_create(OrderDetailSingleReservation orderDetail) {
         return null;
      // ...nor is this one.
      public Invoice invoice_create(OrderDetailMonthReservation od) {
         return null;
    }Now I attempt to invoke these methods:
    // create example objects
    OrderDetailSingleReservation odSingle = new OrderDetailSingleReservation();
    OrderDetailMonthReservation odMonth = new OrderDetailMonthReservation();
    // this call displays "odSingle type: OrderDetailSingleReservation"
    System.out.println("odSingle type: " + odSingle.getClass());
    // this call displays "odMonth type: OrderDetailMonthReservation"
    System.out.println("odMonth type: " + odMonth.getClass());
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailSingleReservation)
    Invoicing.invoice_create(odSingle);
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailMonthReservation)
    Invoicing.invoice_create(odMonth);So these calls will invoke the method for the superclass, i.e. Invoicing.invoice_create(OrderDetail od). That method then then executes the System.out.println() call which displays the class type of its parameter as one of { OrderDetailSingleReservation | OrderDetailMonthReservation }, that is, the expected subclass types!
    So the dynamic dispatch isn't working the way I would expect it to. If I do the explicit if-else checking using instanceof, as described in my first post, the correct methods are called.
    I hope the problem is somewhat clearer now. I am a bit lost as to what might be causing this, or how to monitor what's going on inside the jvm. Any ideas? BTW, the OrderDetail class and its subclasses are JPA entities (though I don't think it should matter).
    Thanks!
    Erik

  • Can i invoke a method of a different class?

    I want to tell my method that if a certain event occurs, to invoke a method thats located in a different class but in the same package. But neither inherit each other.
    I also want the original method to pass parameters to the remote method so it can perform actions on them.
    Is this possible somehow, or am I barking up the wrong tree?
    I've included an example to illustate.
    edu.example;
    public class one extends bank{
    protected void count (){
    If i>100{
    spend(5); // method thats in the two class
    else break;
    edu.example;
    public class two extends bank{
    protected void spend (int x){
    i = i - x;

    either the method you want to invoke will have to be static, or you will need an instance of the class that contains the method you want to invoke.
    If your not in school, its probably best you buy a Java book. It will speed things along considerably.
    I have always bought books by Ivor Horton. "Beginning Java" is a good one. Wrox publisher I think. Once you pass that book you will not need any other books unless you go deep into a particular subject such as encryption.

  • Can not locate Java class using JNI within C++ DLL

    I am using trying to use JNI to call a Java class from C++. The Java class uses JMS to send messages to a JMS message queue. At first I coded the C++ in a console application that created the JavaVM and used JNI to access the Java class. All worked fine. Then I called the Java class using JNI from threads and ran into the problem of the Java class not able to locate the JMS related classes. This was solved by placing the following line in the constructor of the Java class.
    Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
    Then I moved the JNI code from a console application to a DLL in specific an extension DLL that is called by SQL Server or Oracle server. The DLL will use JNI to call the Java class and send messages to a JMS message queue.
    The problem I am having now when the DLL code is called by SQL Server the call to
    JNI_CreateJavaVM
    appears to work correctly but the call to find the Java class using
    jvmEnv->FindClass(pName)
    fails. It appears the is a class loading problem which occurs due to the fact JNI is called from a DLL. When the VM is created I pass the class path information using the statement
    -Djava.class.path=
    And as I stated before it all works when running from a console application. I am new to JNI and really need help in the form of some sample code that will solve this problem. I believe I need to somehow load the classpath information from the DLL but I can not find examples on how to do this using JNI. I have tried several ways using URLClassLoader and getSystemClassLoader from JNI and either it does not work or it crashes very badly.
    I used the following code to determine what the existing class path is and the string returns empty.
    jcls = jvmEnv->FindClass("java/lang/System");
    jmid = jvmEnv->GetStaticMethodID(jcls, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
    jstrClassPath = jvmEnv->NewStringUTF("java.class.path");
    jstr = (jstring)jvmEnv->CallStaticObjectMethod(jcls, jmid, jstrClassPath);
    m_jstr = (jstring)jvmEnv->NewGlobalRef(jstr);
    pstr = jvmEnv->GetStringUTFChars(m_jstr, 0);
    Can anyone please help with example code that will solve this problem. Thanks in advance for any help.
    Charles�

    I have determined the problem occurs when the application/component is compiled using VC 6.0. The test application was compiled using VC 7.1 and works correctly by locating the class path information. If the test application is compiled using VC 6.0 it has the same problem.
    The jvm.dll I am using is version 1.4.2.80. Currently this is not an option to compile all the applications that use JNI using VC 7.1 so can someone please tell me how to solve this problem.

  • How can I invoke a JSP using a URL instance from another JSP?

              Hi all.
              I've been developed a J2EE application using Oracle 9iAS.
              Now I'm migrating to WL Server and I have the following problem.
              I was using the following code to read a URL contents from another JSP:
              URL url = config.getServletContext().getResource("/path/to/url/of/textfile.xsl");
              This was working fine in a expanded directory project structure (typical during
              development time) and Oracle 9iAS.
              When I execute this code from my WL packed .ear file I get a URL not found exception.
              Which is the right way to get a resource available from the same context root?
              Thanks in advance for your answers (and sorry for my bad english ;-))
              

    The previous owner of that machine should have wiped it and install the original OS that shipped with the system leaving the system at the point where the new owner takes over and enters all there own information.
    Before you go much further with this machine you should seriously consider backing up any new stuff you have done and wiping it and starting from scratch. If you keep the system like it is you  will be plagued with problems. Even doing OS updates will prove frustrating.
    Right now the best you can do is to move the Aperture that is on the system into the trash, log into the App Store using your ID and buying Aperture. That should work but to be honest I have never had to do it so can;t say for sure.
    You might want to look at this What to do before selling or giving away your Mac from Apple to read what they recommend.
    good luck
    regards

  • Error while compiling javacode with native method using jni

    im trying to call function in dll that is written in vc++ from java application.
    For that i write a native method .the method name is StopDS1.
    my native method is : public native DWORD StopDS1();
    when compiling using javac i'm getting message like this:
    testdss.java:4: cannot found symbol
    symbol:class dword
    location :class testdss
    1error

    DWORD isn't a Java type, therefore you cannot use it as one.

  • Advantage/disadvantage:invoke method using refllection vs normal instance

    What is the difference in invoking the method using refflection and normal method invocation using the instance.

    Techchies wrote:
    Thanks for the response.
    can you please eloberate "extra cpu time and obscurity". In case of refflection would it take more CPU time.Yes. Whether that matters or not is irrelevant. Actually, in practice, as alluded to above by EJP, it doesn't matter at all because you shouldn't be in a situation where you are choosing between the two. Either you actually need reflection, or you don't bother using it. Anything else is just "shiny thing" syndrome.
    Can you tell me the scenario where we need to use Refflection to invoke the method instead of normal invocation, when instance is available either by Refflection or using new operator.When you don't know the types involved at compile-time, basically. Like, if you know - or suspect - that an object will have a method called foo, but at compile-time, don't have the actual type upon which that method is declared, you might need reflection. Or another common case is when you have arbitrary objects that follow a vague spec, such as the JavaBeans spec, and you want to find, then invoke, all the methods that obey that spec. That's a case for possible reflection. This is how things like OR/M tools and certain containers work.
    If you've managed to instantiate a class using the new keyword, you almost certainly don't need reflection. If you don't know what type you're instantiating until runtime, you may have a case where reflection is necessary, but in many of these cases, it can be avoided by the use of interfaces.
    But the bottom line is, if you're asking "shall I use direct invocation here, or reflection?" the answer is "direct invocation".

  • Error while invoking ContactQueryPage method from contact.wsdl

    Hi All,
    Could any one provide me the java client for OnDemand webservice (contact.wsdl). I want to query ContactQueryPage operation.
    I am facing some problem while making a call. I am trying with both Axis call as well as ContactStub. but its not working in either way.
    Here is the snnipet I am using to invoke a method using ContactStub
    String endpoint = "https://secure-ausomxdsa.crmondemand.com/Services/Integration;"+jessionId;
                   ContactStub stub = new ContactStub(endpoint);
                   ContactWS_ContactQueryPage_Output queryOutput = null;     
                   ContactWS_ContactQueryPage_Input queryInput = new ContactWS_ContactQueryPage_Input();
                   ListOfContact listOfContact = new ListOfContact();
                   Contact contact = new Contact();
                   queryInput.setListOfContact(listOfContact);
                   queryInput.setUseChildAnd("Contact");
                   queryInput.setPageSize("10");
                   queryInput.setStartRowNum("1");
                   queryOutput = stub.ContactQueryPage(queryInput);
    When I run the program..I get following exception :
    org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '"' (code 34) in DOCTYPE declaration; expected a space between public and system identifiers
    Can any one help me out. Its needed urgently.
    Thanks & Regards,
    Sanjay

    Hi !
    From what I see, the only problem is the setUseChildAnd function which is waiting for a true or false argument and not a char...
    Hope this will help, feel free to ask more !
    Max

  • How to invoke a method in application module or view objects interface?

    Hi,
    perhaps a stupid RTFM question, but
    How can i invoke a method that i have published in the application modules or view objects interfaces using uiXml with BC4J?
    Only found something how to invoke a static method (<ctrl:method class="..." method="..." />) but not how to call a method with or without parameters in AM or VO directly with a uix-element.
    Thanks in advance, Markus

    Thanks for your help Andy, but i do not understand why this has to be that complicated.
    Why shall i write a eventhandler for a simple call of a AM or VO method? That splatters the functionality over 3 files (BC4J, UIX, handler). Feature Request ;-)?
    I found a simple solution using reflection that can be used at least for parameterless methods:
    <event name="anEvent">
      <bc4j:findRootAppModule name="MyAppModule">
         <!-- Call MyAppModule.myMethod() procedure. -->
          <bc4j:setPageProperty name="MethodName" value="myMethod"/>
          <ctrl:method class="UixHelper"
                  method="invokeApplicationModuleMethod"/>
       </bc4j:findRootAppModule>
    </event>The UixHelper method:
      public static EventResult invokeApplicationModuleMethod( BajaContext context,
                                                               Page page,
                                                               PageEvent event ) {
        String methodName = page.getProperty( "MethodName" );
        ApplicationModule am = ServletBindingUtils.getApplicationModule( context );
        Method method = null;
        try {
          method = am.getClass(  ).getDeclaredMethod( methodName, null );
        } catch( NoSuchMethodException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        try {
          method.invoke( am, null );
        } catch( InvocationTargetException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        } catch( IllegalAccessException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        return null;
      }Need to think about how to handle parameters and return values.
    Btw. Do i need to implement the EventHandler methods synchronized?
    Regards, Markus

  • Invoking java methods

    hi
    i have used flash builder 4.
    i can't plugin eclipse ide.
    can i invoke java methods in flash builder 4 .
    is it possible.
    if it's possible pls give some ideas.
    thanks in advance
    regards
    athi

    If you want to invoke java methods that are remote though, you might want to use a Java Remoting technology like BlazeDS.
    Using a <s:RemoteObject> tag, you could connect to the server and invoke java methods.
    Here is a small sample app code that helps me execute a remote java method.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
       creationComplete="ro.getProducts()">
    <fx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    protected function ro_resultHandler(event:ResultEvent):void
    Alert.show(event.result.toString())
    protected function ro_faultHandler(event:FaultEvent):void
    Alert.show(event.fault.faultString);
    ]]>
    </fx:Script>
    <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:RemoteObject id="ro"
    destination="productService"
    endpoint="http://localhost:8400/samples"
    fault="ro_faultHandler(event)"
    result="ro_resultHandler(event)"/>
    </fx:Declarations>
    </s:Application>
    Hope this helps,
    Balakrishnan V

Maybe you are looking for