hi all, I am new to JNI. I have an existing C++ header file and a cpp file taht uses the header file. I need to write a Java wrapper for this.
Can you please help me by posting links where i can get actual code which can demo how to do this? or i would also very much appreciate help if anyone can give me actual code where say a C++ object instance is being created by calling Java methods or something similar!!!
Here is a link to the old Sun tutorial on the Java Native Interface. I don't know why they don't have it posted anymore as browseable HTML -- it's only available as this downloadable ZIP file. But it's an excellent step-by-step tutorial that will explain all you need to know.
You can leave your C++ code untouched only if you write more C++ code to "wrap" it with. To call C/C++ code from Java, there needs to be some C/C++ "glue" code. You can write this yourself, or pay for a commercial product which does it automatically for you.
[hijack]I've been wondering this lately. Is there a way we can make a JNI dll in VB? You can write a dll in VB, right? and all we need to do is make sure that the VB dll exports functions in the way Java likes it. That might make it easier on people who don't know C++ [/hijack]
author and iconoclast
Originally posted by Jayesh Lalwani: [hijack]I've been wondering this lately. Is there a way we can make a JNI dll in VB? You can write a dll in VB, right? and all we need to do is make sure that the VB dll exports functions in the way Java likes it. That might make it easier on people who don't know C++ [/hijack]
I imagine it might be possible, as long as (a) VB gives you control over the exact names of the symbols you export, and (b) the VB runtime (which nowadays I guess is the .NET CLI!) is amenable to being embedded in the same process with a JVM.
I suspect the second requirement is less likely than the first!
Joined: Nov 05, 2004
I admit I have been out of the Microsoft world for a long time now, so I might be off the mark, but I distinctly remember VB developers claiming that they can write DLL's just like C++ developers can. Basically, the claim was that VB can do anything that C++ can.
I don't think b) is an issue because you don't really need a VB "runtime" to use a VB dll. The compiler could either statically link all the VB functions into your DLL (creating a huge dll), or dynamically link your dlls to VB dlls that have to be shipped with your dll (which leads to DLL hell). I beleive, more recently, Microsoft has been claiming that all their languages have the same capabilities, but I haven't looked too much into it. I am curious whether you can still create dll's using any of the Microsoft languages
I think a) might be an issue, because there are so many ways you can export symbols out of DLLs, and Java prefers one way, but I don't know if VB compiler implements that.
Alternatively, we can get around a) by creating a COM object in VB and using JACOB to interface Java to VB COM dll. This would introduce too many layers, and would add a learning curve for COM.
Ideally, I would love to see a javah type of utility that takes a native class and creates a .bas file from it.