Calling VB OCX problem using jni

Hi all
I am new in JNI based application actually i have to send 3 parameter to vb ocx and it will return the result in java.
So please give me some suggestion to call vb ocx in java .
Thanks in Advance
nick

There is a JNI forum, you may have better luck there.

Similar Messages

  • Calling C++ DLL's Using JNI

    I have a question.. I need to call few C++ DLL methods from java. So I planned use JNI to do that. The question is there any probable or known performance issues if tried to call DLL's from java application. And also I also appreciate If you can you please send me a link where I can find a sample code for running DLL's using Java application
    Note: I know I dont have any control on performance issues with DLL's

    look at http://staff.develop.com/halloway/code/jawin.html

  • Problems using JNI and JSP in WebLogic 6.0

    Hello everybody. My problem is that I've got a Java class that is called from a JSP. That class connects to a C function and it returns a String. A want this string to be shown by the JSP. The code is:
    JSP
    <html>
    <head>
    <title>prueba JNI</title>
    </head>
    <body>
    <%@ page import="ejemplosJNI.*, conversiones.*;"%>
    <%
    Texto texto = new Texto();
    out.println(texto.realizado());
    %>
    </body>
    </html>
    Java class
    package ejemplosJNI;
    public class Texto
    private native String getLine(String prompt);
    String input = null;
    public static void main(String args[])
    Texto t = new Texto();
    static
    System.loadLibrary("MyImpOfPrompt");
    public String realizado()
    input = this.getLine("Mando una l�nea desde Java");
    return input;
    C function
    #include <stdio.h>
    #include <jni.h>
    #include "Texto.h"
    JNIEXPORT jstring JNICALL
    Java_Texto_getLine(JNIEnv *env, jobject obj, jstring prompt)
    char buf[128];
    const char str = (env)->GetStringUTFChars(env, prompt, 0);
    (*env)->ReleaseStringUTFChars(env, prompt, str);
    return (*env)->NewStringUTF(env, str);
    I compile de C function and put the .dll library in the 'bin' folder in webLogic.
    When I call the JSP, I get the next exception:
    Servlet failed with Exception
    java.lang.UnsatisfiedLinkError: getLine
    at ejemplosJNI.Texto.getLine(Native Method)
    at ejemplosJNI.Texto.realizado(Texto.java:19)
    at jsp_servlet._jsp._pruebasjni._prueba1._jspService(_prueba1.java:93)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:213)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:246)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:1265)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:1622)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Is there any place where I have to put the .dll?
    Is there any place where I have to put the generated .lib?
    Where do I have to put the Texto.h file generated with javah?
    Can anybody help me to solve this problem?
    Thanks in advance.

    Hi, jschell! Maybe you can see my problem if I give you the code. My Java class and the C funtions are:
    Java class
    package ejemplos.cadena;
    public class Texto
    private native String getLine(String prompt) throws Exception;
    String cadenaFinal = null;
    public static void main(String args[])
    Texto t = new Texto();
    static
    System.loadLibrary("LibreriaCadena");
    public String realizado(String cadena)
    try
    cadenaFinal = getLine(cadena);
    catch(Exception e)
    System.out.println(e.toString());
    return cadenaFinal;
    C code
    #include <stdio.h>
    #include <jni.h>
    #include "ejemplos_cadena_Texto.h"
    JNIEXPORT jstring JNICALL
    Java_ejemplos_cadena_Texto_getLine(JNIEnv *env, jobject obj, jstring prompt)
    int cero =0;
    int division = 10 / cero;
    const char str = (env)->GetStringUTFChars(env, prompt, 0);
    (*env)->ReleaseStringUTFChars(env, prompt, str);
    return (*env)->NewStringUTF(env, str);
    I have done something like "int division = 10 / cero;" in order to get an exception in my C code. When I run my Java class I get an error message and the application breaks. I would like to know how to catch the C exception in order to pass it to my Java class that can manage it into the try-catch clause. I have read I have to use something like "FindClass" or "ThrowNew", but my problem is that I have no idea about C programming.
    Can you help me?
    Thanks for your time.

  • OCX problems Using Designer 2.1 to Generate VB 5.0/6.0

    We are using Designer 2.1 to Generate VB 5.0 which we are
    actually bringing into and opening up in VB 6.0. We are running
    into problems with the controls gauge32.ocx and threed32.ocx. We
    retrieved copies of the ocxs, but we can't put them on our NT
    machines.
    I've seen documentation that indicates we need Oracle Objects
    also, is this true?
    Any information on any issue relating to VB 5.0/6.0 generation
    out of Designer would be appreciated!
    null

    Hi (Miss?) Donna,
    You need to install Oracle OLE 2 Object which is accompanied with
    Oracle Server for Win NT or Oracle Developer disks. In addition,
    to run apps generated as VB 5/6 apps by Designer/2000 , you need
    some legacy OCXs, which are placed on controls directory of VB
    5/6 installation directory.
    WM_HOPETHISHELP
    =====
    Donna Pinkerton (guest) wrote:
    : We are using Designer 2.1 to Generate VB 5.0 which we are
    : actually bringing into and opening up in VB 6.0. We are
    running
    : into problems with the controls gauge32.ocx and threed32.ocx.
    We
    : retrieved copies of the ocxs, but we can't put them on our NT
    : machines.
    : I've seen documentation that indicates we need Oracle Objects
    : also, is this true?
    : Any information on any issue relating to VB 5.0/6.0 generation
    : out of Designer would be appreciated!
    null

  • Calling Java from C++  using JNI

    I have been looking into JNI, and I ran sample where the Java calls Native c/c++ methods. Now to do it the other way, having C/C++ to call Java method by passing argument and getting the results back, I think I need to follow the example in Chapter 5 sun, which is creating JVM in the native code, accessing the Java class and method, and then finally calling the Java method.
    First I like to know if I'm right above, and second if I need to pass a C++ class as the argument to the Java method and then the result from the method is Java class, what would be the best way to do? I know I need some to convert the class type some how.
    Thanks,
    Eli

    Are you also wanting to launch Java from C++? Unzip JAVA_HOME/src.zip and look at the source code for java.exe
    If you have native called by a Java object then you can call any non native method in the Java object from the C/C++ side. Example Java method, reportCurrentStagePosition :
        public void reportCurrentStagePosition (int fault, double x, double y, double z, double &#966;)
            if (fault == 0)
                reportCurrentStagePosition (x, y, z, &#966;);
            else
                faultMessage = "Stage Positioning Fault: X="+eFormat(x)+", Y="+eFormat(y)+", Z="+eFormat(z)+", phi="+eFormat(&#966;);
                System.out.println ("***Aero Fault Message: "+faultMessage);
        public native long moveLinearXYZPhiAxes() throws PositionException;Then from the native side of moveLinearXYZPhiAxes the obj is the calling object and has the reportCurrentStagePosition method
    JNIEXPORT jlong JNICALL Java_com_hypernex_goniometer_AerotechWrapperN_moveLinearXYZPhiAxes (JNIEnv *env, jobject obj)
         jmethodID jReportPositions = env->GetMethodID(env->GetObjectClass(obj), "reportCurrentStagePosition", "(IDDDD)V");
         if (jReportPositions == NULL)
              printf ("***ERROR*** about to call jReportPositions but it is NULL ***\n");
         else
             env->CallVoidMethod (obj, jReportPositions, 0, xFeedBack, yFeedBack, zFeedBack, phiFeedBack);
    }Since reportCurrentStagePosition returns a void you use the CallVoidMethod of env. The "(IDDDD)V" is the signature of the method. If it is there GetMethodID returns a non null.

  • 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.

  • Problem calling C# dll using JNI

    Hi,
    I'm trying to call C# functions from a JNI interface. I built a C++ DLL to link the Java and C# calls together, but I am always getting the same error. Calling the C# DLL directly from the C++ code (compiled as an application) does not cause this error. I have to be able to connect our java application with a third party C# DLL, so I cannot just right the DLL directly in C++... Here is my code:
    //C# Class Library::
    namespace ClassLibrary2
         /// <summary>
         /// Summary description for Class1.
         /// </summary>
         public class Class1     
              public Class1()
                   // TODO: Add constructor logic here
              public void Bidon1()
         MessageBox.Show("Affiche", "Toi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    //C++ DLL::
    #using "ClassLibrary2.dll"
    BOOL APIENTRY DLLMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
      return TRUE;
    JNIEXPORT void JNICALL Java_com_blablabla_CommJNIDLL_Init
    (JNIEnv * enivronmt, jobject obj)
         new ClassLibrary2::Class1();
         (new ClassLibrary2::Class1())->Bidon1();
    Olivier dit :
    //Java JNI Calls::
    //From CommJNIDLL::
         static {
              System.loadLibrary("MyCDLL");
         public native void Init();     If I comment the calls within the C++ DLL, they get fired, and no exception is raised. What am I doing wrong?
    Thanks, bumpert

    Hi,
    I am currently also trying to call some C# code within JNI. So far I have managed to call some simple C# code in Java through JNI based on the example on codeproject. However, now my problem is that instead of doing JNI-->C++->M C++->C#, I need to include one more reference to some other DLLs in the C# code. Therefore I need to do JNI-->C++-->M C++-->C#-->DLL. So is there a way to do this? I can compile all the code sucessfully in C++, but when I try to execute the .netmodule (for C#) and DLL for C++ through JNI in Java, it gives me an error. I have tried to put all the relevant DLLs in the same directory, but it still does not work. So is there someway to combine the .netmodule of C# with the DLLs it references to? Perhaps that could solve the problem? I am new to C# and C++, really appreciate if someone can give some advices since there's nothing much on the net.
    thanks,
    Lee

  • ORA_FFI problem in using JNI from C dll

    Hi,
    I am encountering a strange problem in ORA_FFI while calling a C dll.
    The C program uses JNI to dynamically load a jvm (using LoadLibrary('C:\\jdev1012\\jdk\\jre\\bin\\server\\jvm.dll'))and then call an
    instance object. The problem is when invoked at runtime it executes
    fine the first time but from the same session if its invoked again the
    JVM fails to initialize. It seems the JVM is not getting released though
    I am using DestroyJavaVM.
    I am using forms10g and could have used ORA_JAVA but i have some
    other C projects with which i am trying to integrate into one dll.
    I am really stuck and any experience on this will really be helpful.
    -Thanks,
    Samrat

    I suspect the "-d64" switch is interpreted by the java launcher to make it load a 64-bit JVM library rather than one of the the usual 32-bit JVM libraries. If so, you would need to load the same 64-bit JVM in your own program. Try looking in SDK source files java.c and java_md.c to get started.
    (I don't have HP-UX or any 64-bit system here, so this is just a best guess.)
    -slj-

  • Memory Allocation problem when using JNI

    For a Project we need to interface Labwindows-CVI/ Teststand with an application written in Java. we are using JNI. The code uses JNI_CreateJavaVM to start a JVM to run the Java interface code. The code did run for some time , but now ( without any obvious change nor on the CVI side neither on the Java side) JNI_CreateJavaVM fails with -4 error code, that means that the start of the JVM failed due to memory allocation failure. First investigation showed, that even if Windows Task Manager shows about 600M free physical memory, you can allocate in CVI only about 250M as a single block at the time we are calling  JNI_CreateJavaVM. That might be a little bit to less as we need to pass -Xmx192m to the JVM to run our code. Unfortunately just increasing the physical memory of that machine from 1.5G to 2G doesn't change anything. The free memory showed by Task Manager increases, but the allocatable memory block size does not. Are the any trick to optimize CVI/Teststand for that use case ?  Or maybe known problems with JNI ?
    Solved!
    Go to Solution.

    hi,
    have you tried other functions to allocate memory?
    the -Xmx command only sets the maximum heap size. You can try to use -Xms. This command sets the initial Java heap size. 

  • How can i call a VB6 project from my java application using JNI

    hi
    can anyone tell me the procedure of calling a VB6 project from any java application using JNI
    if anyone does know then tell me the detail procedure of doing that. I know that i have to create a dll of that VB6 project then to call it from the java application.
    if anyone know that procedure of creating dll file of an existing VB6 project please reply
    please if anyone know then let me know

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Hello apple I have the problem with my iPhone and my friends have this problem too. My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it bu

    Hello apple
    I have the problem with my iPhone and my friends have this problem too.
    My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it but when answer both of us can't hear anything and when I put my iPhone to my face the screen is still on and when I quit the phone application and open it again it will automatic call my recent call. And when my friends call me my iPhone didn't show anything even the missed call I'm only know that I missed the call from messages from carrier. Please check these problem I restored my iPhone for 4 time now in this week. I lived in Hatyai, Songkhla,Thailand and many people in my city have this problem.
    Who have this problem??

    Apple isnt here. this is a user based forum for technical questions. The solution is to restart, reset, and restore as new which is in the manual after that get it replaced for hard ware failure. if your within your one year warranty its replaced if it is out of the warranty then it is 199$

  • Call to a C++ DLL, using JNI - C++ method has char*

    I am trying to link into an existing C++ Dynamically Linked Library(DLL) using the Java Native Interface(JNI).
    All goes fine, and the library loads into the current program, however when I try to call the function, it crashes. The function has char pointers, and I haven;t been able to get Java to simulate them. Is there a way?????
    I have tried using and array of chars .....char[], and String, but no dice.
    Any suggestions O'learned Java ones??

    It will be necessary for you to write a JNI adapter in C/C++ to accomplish this. Java character strings and arrays are very different from those of C/C++ and you'll have to use JNI functions to adapt.
    Chuck

  • Is it possible to call c# dll using JNI

    Using JNI we can invoke native code written in c or c++.
    Steps:
    1) All we have to do is write a class and have a method of type native.
    2) Invoke javah with -jni option to create a .h file.
    3) Include this header file and implement the method in c or c++ code.
    Now my question is:
    Is it possible to call I want to know whether we can implement the native method in c# instead of c or c++.
    Thanks

    No you can't, but you can have the JNI C/C++ code call C# code. How to do that is no longer a JNI question but a C# question.

  • I have problem when use 'JNI'

    Hello every body,
    I have an application language "C", which, I must make a wrapper java.
    To do this using "JNI".
    First I try to understand the functioning of JNI, I try it for the first example helloWorld.
    all steps works well, and dynamic library was well create: libHelloWorld.so
    The execution, it does'nt work
    When I try to java Helloworld, here's what I see:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/java/jniexamples/HelloWorld/libHelloWorld.so: Can't load IA 32-bit .so on a IA 32-bit platform
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
    at java.lang.Runtime.loadLibrary0(Runtime.java:822)
    at java.lang.System.loadLibrary(System.java:993)
    at HelloWorld.<clinit>(HelloWorld.java:7)
    Although I added the link to my library like this:
    export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: / home / Install / java / jniexamples / HelloWorld
    I dont understand where is the problem may be in the version I use of java, I use jdk-1.5.0-13?
    Thank you in advance for your help
    Regards
    Daniel

    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/java/jniexamples/HelloWorld/libHelloWorld.so: Can't load IA 32-bit .so As a guess that would suggest that it found a file (thus the name is correct) but that the contents do not represent a shared library that the VM will load.
    That is usually because the compile/link options are wrong for the target VM.

  • Problems creating a Java Array using JNI-HELP!

    Hi,
    I am trying to create a Java Array using JNI.I have posted the code below. The problem is that the oth element is added correctly to the Array but when the JVM gets to the next element...it goes for a toss. It is not able to create a new instance of the object in GetUGEntity() function...there seems to be some problem in creating a new instance of the object!
    Can somebody help me with this?
    jobject GetUGEntity(JNIEnv *env, UF_DISP_j3d_entity_t* entity_list)
         int numVerts=0, numStrips=0;
         jfieldID fid;
         jdoubleArray jTransform=NULL;
         jstring jstrName=NULL;
         jdoubleArray jNormals=NULL;
         //Init an Entity object
         cout<< "**Getting New Class Reference...";
         jclass jEntity = env->FindClass("Lcom/wipro/java3d/rmi/Entity;");
         cout << "**got Class reference..."<<endl;
         if (jEntity == NULL)
              return NULL;
         cout<<"Creating new object instance...";
         jmethodID mIDInit = env->GetMethodID(jEntity, "<init>", "()V");
         cout<<"Got java method id...";
         jobject javaObj = env->NewObject(jEntity, mIDInit);
         if (javaObj==NULL)
              return NULL;
         cout << "Created!" << endl;
         //Entity ID
         cout<< "**Setting eid...";
         fid=env->GetFieldID(jEntity,"eid","I");
         jint eid = (jint)(entity_list)->eid;
         env->SetIntField(javaObj, fid, eid);
         //env->DeleteLocalRef(eid);
         cout << "Done!" << endl;
         cout << "Done!" << endl;
         cout<< "**Returning jobject...";
         return javaObj;
    jobjectArray createJArray(JNIEnv* env, UF_DISP_j3d_entity_t** entity_list, int noOfEntities )
         UF_DISP_j3d_entity_t* tempVar=NULL;
         cout<<"*Creating Jobjectarray...";
         jobjectArray jEntityArray = (jobjectArray) env->NewObjectArray(noOfEntities,
              env->FindClass("Lcom/wipro/java3d/rmi/Entity;"),NULL);
         cout<<"Created!"<<endl;
         for(int i=0; i<noOfEntities;++i)
              tempVar = &(*entity_list);
              if (tempVar !=NULL)
                   cout<<"*Trying to get Entity...."<<endl;
                   jobject jEntity = GetUGEntity(env, tempVar);
                   if (jEntity!= NULL)
                        cout<<"Got Entity!" <<endl;
                        cout <<"*Setting Array Element....";
                        env->SetObjectArrayElement(jEntityArray, i, jEntity);
                        cout << "Done!" << endl;
                   else
                        printf("ERROR: Did not get Entity Reference");
              else
                   printf("ERROR: Got a NULL Reference!");
         return jEntityArray;

    Hi Deepak,
    Could you please let us know upto which line your code is going safe. Try printing the value in the structure before you send that to the method GetUGEntity().
    I am not too sure that would be a problem. But I have faced a problem like this, wherein I tried to access a structure for which I have not allocated memory and hence got exception because of that.
    Since your JNI code seems to be error free, I got doubt on your C part. Sorry.
    Dhamo.

Maybe you are looking for