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

Similar Messages

  • Calling COM DLLs using JNI

    I am able to call ordinary dlls from my java application using JNI, by exporting the function from my DLL.
    What can I do to call COM DLLs using JNI which do not expose the
    Functions directly.
    please help!
    thanx,
    -sachin

    Is this a COM dll that you have written or do you merely have the dll?
    If you merely have the dll, there are some third party tools that will generate Java interfaces to COM objects from the dll.
    Although I don't endorse these products or work for them I've used them before with some success:
    o J-Integra -- http://www.intrinsyc.com/
    o jacoZoom -- http://www.infozoom.de/
    -- rob

  • 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

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

  • Calling Functions of Loading DLL using java

    I have a dll file
    I know the functions which are ther in the dll
    But how to call those functions using JAVA ?
    can anyone tell me how to do the same...
    Thanx in advance
    regards,
    Ritesh

    I assume that you have a regular DLL and that the functions in that DLL are exported and that you know the signatures of each function.
    With that in mind, you will need to use the Java Native Interface (JNI), to call those functions from Java. In a nutshell, you will need to create at least one class which declares some native methods, code a class static code block to load the JNI-DLL you are about to create, compile the class(es), run the javah tool supplied with the JDK which will emit a C compatible header file, implement the functions from the generated header file and compile that source file to into a DLL. It would be in this DLL that you would use the functions in the DLL that you ultimately want to access. So, what you wind up doing is creating a wrapper DLL.
    Take a look at the JNI tutorial trail from Sun at http://java.sun.com/docs/books/tutorial/native1.1/index.html.

  • How to solve these Errors when generating .dll (using JNI) ?

    Hello,
    I am very new about JNI. As I have been trying to generate my dll (sysHook.dll) as I followed this topic http://forums.sun.com/thread.jspa?threadID=632369 (by Jbgohlke ) by putting this command:
    cl -I"C:\Program Files\Java\jdk1.6.07\include" -I"C:\Program Files\Java\jdk1.6.07\include\win32" sysHook.cpp -FesysHook.dll Then many errors are popped up as follows:
    sysHook.obj :error LNK2019: unresolved external symbol __imp__CallNextHookEx@16 referenced in function "long__stdcall HookKeyboardProc(int,unsigned int,long)" (?HookKeyboardProc@@YGHIJ@Z)
    sysHook.obj :error LNK2019: unresolved external symbol __imp__SetWindowsHookExA@16 referenced in function " void__cdecl Init(void)" (?Init@@YAXXZ)
    sysHook.obj :error LNK2019: unresolved external symbol __imp__UnHookWindowsHookEx@4 referenced in function "void__Cleanup(void)" (?Cleanup@@YAXXZ)
    sysHook.dll : fatal error LNK1120: 3 unresolved externals
    If anyone of you know this PLEASE!! point me out!!
    [email protected]
    Thanks in advance

    Specify the appropriate library when linking.
    This is not a JNI question. It is a Windows/C/C++ programming question.
    Locking this thread.

  • My wastepaper file (or what ever you call it in English; I use the German version) has got lost.

    I have created a new one but it doesn't work, i.e. the erase button doesn't work, so I have to shift the mails into it manually. Also, the file is not deleted when I press the erase waste paper button in the file tab. Does the waste paper box have some further attributes I would have to set? Or what else can I do?

    Danke Georg Genau so hats funktioniert! War eine prefekte Hilfe
    Gruß Bernd

  • Advice needed... should I write it using JNI?

    Hi all - I'm experienced with both Java & c++. I've got a set of libraries written in c++, and I need to write a test harness. It's been suggested that I write it using JNI. I've no experience with JNI, only gone through the tutorials.
    The library & test harness will be used on a multitude of platforms (Windows, Sun, Linux, Netware, AIX, oh many more...).
    Based on my very limited understanding of JNI, I'd basically have to write a harness in c++ (I can't touch the libraries themselves) using JNI-friendly methods and then access it with a pure Java app. Various reasons as to why this might be a good idea have been suggested, but I'd like some more experienced input.
    Is this a worthy use of JNI? I'm quite happy to learn it & do it, but is this the type of situation where I'd want to? And am I totally off on what I'd have to do?
    Thanks in advance,
    Suzanne

    Hi,
    I had been working on JNI as well. It was a nice experience trying to communicate from java through c and finally to fortran libraries built long ago. Since rewriting the code was tedious Job we came out with this idea of JNI. During my reserach on JNI I came across with javah -stubs option. To my understanding if you could generate the stubs based header files. You can talk to c programs with minimum changes in interface. If this is just a test program then you can also communicate through sockets and built a interface between these two high level languages, where all the returned output will be redirected to ports where in finally you extract it from Java side and vice versa. I haven't tried the second idea but would be interesting to try though. Do let me know what u finally decide to do on forum.
    Thanks,
    Regards,
    RaviKiran.

  • 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

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

  • How to use a C# dll with JNI

    After a ton of issues, I finally got this working properly. I've come across a lot of forum posts about the various problems and VERY few answers so I thought I would post my solution here.
    To do this, you need to create a managed C++ layer in between C# and java. The JNI functions in C++ dll can make calls to the C# dll directly, and your java program can make calls directly to the native JNI functions. Some important notes on using C# classes in C++ are:
    -gcroot<CSClass ^> should be used on any objects that are instances of some C# class.
    -the symbol ^ should be used with all C# references (its the symbol for references)
    -gcnew should be used to allocate C# objects
    -in visual studio, add the C# dll as a reference rather than using #using <CsDLL.dll>
    -do not use #using <CsDLL.dll>
    The next issue is loading the libraries. By adding the folder your C++ dll is located in to the Djava.library.path VM argument, you can load your C++ library with System.LoadLibrary("Cppdll.dll"). You DO NOT need to load the C# dll in your java program. In fact, it will ignore you if you try. The problem with loading this dll is with how the CLR searches for referenced assemblies. The CLR First searches the DEVPATH environment variable (if the machine.config file has developer mode set to on), then it searches the GAC, then it searches the codebases, then it searchs the current executable's directory along with a list of definable subdirectories (probes).
    DEVPATH is a decent option, but it requires modifying the machine.config file to be in developer mode. Once that is done, it acts just like the PATH environment variable.
    If your C# dlls are strongly named, I would recommend adding them to the GAC or using codebases. However I have not done this and am not sure how.

    Hi,
    i have to use a c# dll in my java program .by following this link http://www.codeproject.com/KB/cross-platform/javacsharp.aspx i done that.but it is working for only one c# program.if i am trying to use a dll it is throwing error
    # An unexpected error has been detected by Java Runtime Environment:
    # Internal Error (0xe0434f4d), pid=3988, tid=3704
    # Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode, sharing windows-x86)
    # Problematic frame:
    # C [kernel32.dll+0x442eb]
    # An error report file with more information is saved as:
    # D:\Work\EclipseWorkspace\HelloInflux\hs_err_pid3988.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    Please help me out. i want a few steps to invoke a c# dll by using jni

  • To read a DLL from java using JNI

    Hi,
    I had some DLL files (VB 5.0) which are providing interfaces. Is there any chance of accessing that using java (JNI). Also is there any De - Compiler available so that I can get the source code of the DLL file.
    Regards,
    Hari.

    Hola Hari
    To make a dll loadable through JNI, the interface
    inside
    the dll must be implemented the JNI way. Also a COM
    interface does not help.
    I would reccomend a certain product to automatise the
    JNI interfacing process, but that would
    require that you have the sourcecode of the dll
    available.
    But one thing you can do is to write a wrapper that
    contains the dll classes and is implemented the JNI
    way.
    More precisely you write an interface wrapper in c/c++
    that matches the methods of the dll and does use JNI
    methods. Now inside that c++ wrapper you load the dll
    and forward the calls from java to c++ vice versa.
    Download the demo version of CENTRO.java here:
    www.ablon.de
    Bye, nilsHi Nils,
    Thank you for your suggestion. Im new to JNI.
    That dll's are in Visual Basic. I don't have the source code of the dll file. I got the interfaces available in the dll file from a Visual Basic program which make use of the dll file(which we are talking about). As I know only the method signatures in the interfaces(dll file), I request you to kindly provide me some help to wrap it in C/C++ program.
    Thanks in advance.
    Regards,
    Hari.

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

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

  • Executing DLLs from Java using JNI vs Runtime.exec()

    I am trying to understand the best way to execute a dll using java. The dll I am testing with takes a few input parameter. If I use JNI with System.loadLibrary("dll"); what do I need to do to pass the arguements in as well? Can I just add the arguements in the java code like private int xyz = "value"; and expect that the dll will accept them or is there special definitions I have to set up in the dll to make it work?
    Alternatively I was looking at using Runtime to execute the dll by using Runtime.exec("dll param1 param2",env,filePath); Does anyone know if there are drawback to doing it this way vs. using JNI or is this just as efficient? Any help would be appreciated.

    You seem to be confused...
    "execute a dll using java"
    Unless I'm mistaken, a dll is not executable. A dll is a library of code. This code has (hopefully) some well-defined entry points (declared in a header file somewhere) which you must call in a C/C++ file. The arguments you pass to the dll will come from java through JNI.
    As far as your understanding of this entire process, it is obviously confused beyond the scope of a simple reply. I recommend you read the examples and ALL of the documentation available here:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    When you get the/an example running (or just set up to run) then post your code and comments here for more help.
    Ian

Maybe you are looking for

  • How to connect one database in two threads?

    Dear All, If anyone can tell me how to connect one database concurrently? I tried the following idea: 1.create a Hashtable to keep database objects(those databases have been opened) 2.Before openning(connecting) a database:first step is to check the

  • Photoshop Can't Open .png Files

    Hey, I'm having a bit of trouble here with Photoshop CS5. When I drag & drop/open a .png picture in Photoshop, it gives me the following error: I can open .jpeg files all good, and I'm not too sure about.gif or any others, cause I only use Photoshop

  • Is there a way to attach request/response handlers in BEA Weblogic Workshop similar to Axis?

    Apache Axis allows developers to attach Request/Response handlers to do stuff like logging, authorization check etc. Something like... public class MyHandler extends org.apache.axis.handlers.BasicHandler { public void invoke(org.apache.axis.MessageCo

  • ENHANCEMENT-POINT in reprot RM06EPS0

    HI ALL, I want to change report 'RM06EPS0' that is price comparson list, i think of copying this into a z report and then make changes. But when i open the source code it contains statements like this. [code]ENHANCEMENT-POINT RM06EPS0_G4 SPOTS ES_RM0

  • RSA3 Extract checker.

    Hi, I am running delta load and repair full request into BW with one hour gap. I have "X" number of reocrds in setup tables and "Y" number of records in Delta Queu(RSA7), now if i want to check the records then i will execute RSA3, Now can you tell m