interface DLL with java application, how to? - java

I wrote a Java application for my company which works great. Now I am asked to interface my application with an API of a piece of hardware.
The API is implemented in a Windows dynamic link library (DLL). The samples that come with the API were written in Visual C++ 6.0
and Visual Basic 5.0 (seems very old).
There is no Java API available. I am wondering if there is a way to use the DLLs with my Java application I wrote? Should I rewrite the application
in VB.NET or... (Would these APIs even work with VB.NET)?
This is the piece of hardware whose API I need to use:
http://www.sealevel.com/store/8004e-pci-express-16-reed-relay-output-16-isolated-input-digital-interface-3-13v.html
Any suggestions or ideas are appreciated.
Thank you

The API should work with VB .NET.
If the API is Open-Source you could try to add JNI support, so that you can use it in Java.
Otherwise you could try to write the Application in C++. The difference to Java is not that big.

1) Use JNI, try using some java-c++ bridge which will make your life easy - see this https://code.google.com/p/javacpp/
2) Yes you can call native api's in vb.net

Related

Binding Qt with java

How can I bind Qt with java by java java native interface?
I want to make an java app but for UI i want to use Qt, for some reason I can not use qt-jambi so I need to bind Qt with java.
Is it possible to create an Qt app in Qt creator and bind this component to java through java native interface?
If some one knows How qt-jambi works, please tell me, so help!
In fact my general question is that how (if its possible) to make a java app that some of its component like UI is written in c++? I do not want to use only one c++ method or library, I want to use I complete c++ qt app.
Thank you!
sorry for bad english.
When you want to have a hybrid Qt/Java application in which you use Qt API in Java code, definitely the best option is to use Qt Jambi. JNI only lets you to call some Java function from C++ world or vice-versa.
Qt Jambi enables you to to write software in Java in the speed of natively executable code and with native look and feel on different supported platforms. Actually it is a Java binding to Qt, so you can easily use Qt API in Java. There are some documentations on the web about it like this or that.

How to use .NET dll in JAVA?

My company uses .NET for all development, and we integrate with an ERP made in .NET.
The ERP API is a collection of interops that we simply reference from our .NET project and we are ready to do whatever we want with it.
Recently we are thinking in JAVA development, but we have one concern, the integration with the .NET products we sell.
I've googled a bit and found JNA and JNI.
My questions are:
What is the best solution to "use" a .NET dll in JAVA?
Do they have limitations in functionality or performance?
Thank you.
I prefer JNA over JNI. JNI is more error prone. Boilerplate code you need to write makes it ugly. Also JNI is more C-ish than JNA. I haven't used JNI lately but JNA is hosted at Github, making it more reliable for me. I'm not sure whether JNI will be supported in future. You can see JNA#Github here.
In both you need to be get used to type mappings.

C++ integration with Java in one project. Is it possible and how to do it?

So... I will have a project which will be tested on Win 7 and some Linux server. It will be a web service that will use HSQLDB, Hibernate, Spring, Blaze DS and Flash (Flex RIA) as front end. I need to implement into it some image filtering\editing functionality which will be implemented in cross-platform C++ code (It will use Open-CV) wrapped in Java.
I need some kind of tutorial how to create cross-platform Java projects that use C/C++ libs *(most of all I am intrested in crossplatform compiling issue and what IDEs support such things)
It sounds like you'll benefit from the Java Native Interface. If you've got existing C and C++ code that you'd like to use from Java you may want to seriously consider something like GlueGen. It will save you a lot of time generating the code to access your C code.
You can have a look at the official Java JNI Examples here
Something along these lines?
http://www.javaworld.com/javatips/jw-javatip17.html?page=1
You're going to need to use JNI. The Java will be totally cross-platform and can be one project. For C++, you will need to create the JNI callable interface, and build as a dynamic library. The code should be pretty cross platform, but the actual build will be different.
On Linux, you need to build as a .so and you will probably use gcc. On Windows, you will probably use Visual Studio and build a .dll. The build will be different.

Can you use Java libraries in a VB.net program?

I'm wondering if a Java library can be called from a VB.net application.
(A Google search turns up lots of shady answers, but nothing definitive)
No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:
IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.
So it's not the real deal.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like
http://www.jnbridge.com/
Other way is to wrap your API with java webservices.
check this also http://www.devx.com/interop/Article/19945
Nothing out of the box.
Most java/.net interop that I know uses web services.
If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.
If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.
If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.
In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.
If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).
An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.
It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.
You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.
This article in java world has a quick tutorial on how to use Java from C++ and viceversa.
http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
If you have the source, Visual Studio will let you convert Java code into c#.

Java I/O using inpout32.dll

I am trying to control some LEDs wired to the parallel port on Windows XP. The easiest solution would be Inpout32.dll from Logix4u.net. I have found many source code samples in various languages (C++, Visual Basic, C#) but nothing using Java.
Do you know any tutorials about calling DLL functions from Java ? (what I have found so far on Google are not so advanced).
Environment: Java 1.6.0, Windows XP
The generic way to access native code from Java is JNI.
However, there are frameworks like JNA and/or JInvoke hiding all complexity of JNI and providing interface similar to VBasic and C#.
BTW, there are JNI library and samples for your specific DLL here
There is also JNIWrapper

Categories

Resources