I searched for almost 2 hours for any example with complete code, but could not find anything that works. The issue is this: I have a C++ COM DLL that can comunicate with old MSJava, and I need to replace the MSJava with Sun/Oracle Java. Since the MSJava does not use JNI, the DLL is not JNI prepared. I plan to make another C++ DLL that implements JNI and from this call the old DLL. It's doable? Any advices? Examples? Thanks everyone. (If this is a duplicate please send me the link from the article)
Related
I am working on a project where I have some sensors and I want them to connect to a PC via USB. now they write there is a windows lib written in c and all functions are using the cdecl call convention of c and I have to be sure that if I programm in an other language (java!) that the call convention is given.
So I researched a bit and found a few tutorials to bind dlls in java and or use JNA. but this are all new things for me and I want to be sure, that it is possible (and maybe an example) - the device isn't that cheap and I want to know that before I buy it.
You can call C code from Java - there are no issues here.
Then, if you have something very specific in your C routines, you can always go via wrapper.
Take a look here.
http://jnicookbook.owsiak.org/recipe-No-018/
In this sample, you are calling C code that - in turn - calls another library.
You can also do it by linking your JNI code with some other library. Like here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo023
There are plenty of options. When it comes to JNI vs. JNA. Make sure that JNA will be efficient enough. In general, JNA tends to be slower. Take a look here:
https://github.com/mkopsnc/keplerhacks/tree/master/jnijna
Hope this helps.
I don't post codes here - all the samples in JNI Cookbook are available from github.
Is it possible to use JNI (Java Native Interface) in Applets, has anyone has tried?
You can use JNI from an applet, just remember that the applet is running on the client so JNI will be accessing the client for the "NI" part.
I'm not quite good in JNI but I googled link which can help you. It contains info about accessing DLL with JNI. Take a look:
Calling a DLL from an Applet via JNI
I need to reference a C++ dll from my Java project. The method that I need to expose is actually written in Visual Basic. Is there any way to access the Visual Basic code in C++, so that it can eventually be accessed in the Java project?
You can use OS native DLLs from your Java project using Java Native Interface (JNI):
jmac posted the original question on my behalf. I needed to find a way to call VB DLL function from a C++ DLL.
I've given up on the VB DLL and opted for a C# DLL. The following link provides a downloadable Visual Studio solution that provides a project called DLLExporter that exports C# functions thus making them available to C++. The VS solution was written in a version earlier than 2010 but the VS 2010 migrator had no problem importing it.
http://www.codeproject.com/KB/dotnet/DllExporter.aspx
It solved my problem.
For the record, I tried to wrap my VB DLL inside the C# DLL but it didn't work. So I just migrated my VB code to C#.
Assuming this is VB 6.0 and not VB.NET, you need to create an MFC DLL wrapper for your VB ActiveX DLL.
Here's more information on Exporting VB DLL Functions.
You have to use JNI (Java Native Interface) technology.
I highly recommend the Java JNI Tutorial.
as per Andriy Sholokh ,u need to use JNI to communicate with c or c++ from your java project. You have to use native method inside your java code. hope it will help you.
I have some dll files(not custom and not written by me) and I need to use the functions, that are c/c++ written, in these files in my java project. I googled and read many examples about JNI but they were all about writing your own program and dll and then reaching them. Also I don't think dllexport exists in these dlls, so dllimport/dllexport method is not available I guess.
How can I reach these functions?
Thanks in advance..
I'm sure, you looked at the JNI Tutorial at oracle already. I had a quick look at the part, where a native function is implemented and a dll is compiled and I don't think, that special conditions have to be met.
I'd give it a try with a single, easy function from that dll:
Write a simple class with just main method that uses one of the native methods (with easy parameters to have an easy start)
Generate the header file and
run the test application
If the dll is not 'jni compliant' (whatever that means), you'll know by then and then you probably know that you have to recompile the native code.
I'm trying to make a program like AutoHotKey, but with a graphical interface.
I'm using java.awt.Robot
Now I want to make the code for checking the state from a key (In AHK: getKeyState)
Of course somthing like a KeyListener without having focus.
I read already something with JNI and C++, but....
I can't find some information.
Can somebody help me??
There are lot of good JNI resources for starting out with JNI Programming like the Sun JNI Tutorial. Almost all Tutorials assume a good knowledge of C/C++ because the Java Native Interface (JNI) is the bridge between native C/C++ code, the Java Virtual Machine and everything running in there (meaning your Java Bytecode).
What you may want to do first is to find a key capturing library for your operating system of choice (you didn't mention anything specific here) in C++ and try that out as well as checking if there are already some Java bindings (libraries that use JNI and offer Java classes) to interact with. I didn't find any promising on a quick search unfortunately.
works perfect for windows 32/64 Bit. It's not necessary to integrate the dll files into the (eclipse)workspace / deployment process. Amazing Lib:
Hot stuff!
http://ksquared.de/blog/2011/07/java-global-system-hook/