I am writing code in java which calling delphi dll.
to invoke the delphi dll I am usig JNA and its work great.
My problem is when events are being called in the delphi and I need to invoke java code.
is this possible in JNA?
As discussed on the related thread (loading a delphi dll in java using jna), the flow is:
create dll in delphi
create a delphi or c++ app that can load the dll and successfully call the funcs in it
--- do not proceed until this is done!
now load dll from JNA
The interesting part for your project is that you want the delphi code to invoke java code.
I can think of only two ways to achieve the delphi --> java flow:
Implement a callback on the java side, so the delphi code can pump java code when needed (How to use JNA callback)
Have the delphi dll start a thread (that is bad, better: in java start a thread which loads a delphi dll func that runs) and use a different kind of IPC for the delphi code to pump java code (via a socket, shared memory, or other technique)
Related
I am new to native code programming in java. i have client dll where they have exposed apis and also given api document.I want to use them in java.
I have written some code to load native library using system.loadLibrary and declared few native methods and able to call them successfully.
But they have some callback methods as well and few data structures that needs to be passed. I have written simlar classes in Java seeing their api. But it is not working.
i am confused about JNI or JNa uses. do I need to use them and create any header files as I already native methods are implmented.
i suppose jni to be used only when we need to develop some part of code in other language like c c++.
Creating header files and then implementing and creating dll. But thats already with me.
Whats the way to easily write those typedef in java??
and is my understanding correct that i dont need jni or jna for this?
I have a C++ application that needs to interface with a Java library. I'd like to receive notifications from the Java side so it needs to call back into the C++ app. I've found numerous examples on invoking Java functions from C++ (this is the easy part) and calling C/C++ functions from Java that are exported from a DLL.
Everything I've found so far is how to invoke Java callbacks from an external C++ function within a Java app. I need the opposite.
With straight C++ this, is of course, easy. I'd simply pass a function pointer to the class which would in turn call as a callback when needed. How can I do this when I'm instead invoking a Java function?
In case there's a better way altogether than what I'm asking for here is the overall application:
My C++ application needs to access an external server which will stream data back to my app. The access API is a Java based API. My current plan is to build a Java wrapper that will handle all of the API calls. This wrapper will be invoked from my C++ app using JNI. When data is received, it will process it as much as possible and then notify my C++ app with the adjusted data.
To sum up how can I call a C++ function callback from a Java class which was in turn invoked via JNI from a C++ application. There is no DLL to load for Java to use. Although I can make one if needed if everything can interface properly.
Function Path: C++ application -> Java class library -> C++ callback function
I found it. There is a function in the environment class called "RegisterNatives". With this I can register C++ callbacks for any Java class at runtime. I tried it and it works exactly as expected.
I have a DLL file mostly written in vb.net
It will take 2 parameters.
I am suppose to make use of this DLL in my java code and pass required 2 parameters.
How should I go about it?
Use JNI, Load your dll and call native functions
See
Examples
In Java there's basically two good options for this: (in order of recommendation)
If your DLL has C function headers (rather than C++ decorations), you should use JNA. It has a simple, declarative syntax and only requires writing some Java.
Write JNI bindings for your DLL (there'll be some Java and some C++ code involved).
I am developing a Java application in which I need to call some C++ functions (from Google Talk library libjingle) . The objective is to run it all on Google App Engine (which only supports Python or Java).
How can I do this?
You need to define native methods in your java code for whatever you want to be implemented in C++ and directly access your native code. Then you run javah on your code and it will generate the C header files for you and you'll need to provide C++ implementations.
The native methods you can call from your Java code like any other methods and still they'll have their implementation written in C++ and talking to whatever other native library directly.
You then need to set the java.library.path system property to include the shared C/C++ libraries that you require: the google library and your own JNI implementation library would be required in this case.
If the library has C bindings through a DLL/SO, I usually prefer writing wrappers in Java using Java Native Access (JNA) rather than writing the bindings in C/C++ using the Java Native Interface (JNI). The former is easier to manipulate as the JNI access to Java objects is a real pain in the neck. However, it's not as obvious to wrap C++ classes using that API.
You might also want to look into the Simplified Wrapper and Interface Generator (SWIG) for automating part of this process!
You can't run native code on App Engine - only JRE code. If there's no avoiding the native code, you'll need to run this part of your app on another system, and call it from your App Engine app - or use the built-in XMPP API, in this case.
Is there a java api similar to RAPI? I want to be able to access files on the windows mobile device using a java desktop program.
Thanks.
You could use RAPI itself, and access it from Java using JNI or a wrapper like Swig
We were also looking for a similar API in Java but unfortunately none is available. I wrote my own RAPI wrapper using JNI and used that in my program.
The main problem with JNI is that any un-handled exceptions/faults cause the calling Java program to shutdown as well. Do keep that in mind when writing your wrapper. There are different approaches to safe guard these, the simplest and common approach is to write a standalone program written in .Net/C++ that communicates with the RAPI and your Java program communicates with that program using pipes/files etc. this way you also don't have to write a JNI wrapper :-)