Accessing C++ native DLL (with namespaces) through JAVA - java

I have a c++ DLL where the functions are nested within namespaces.
I need to access these functions in java.. i'm not much of a java expert but i do know a little of its basics.
I found basic java codes to access methods in C++ native DLL using JNI but im not sure how to access the functions nested within namespaces.

You will probably need to get the mangled names of the C++ functions. You can use nm to do that on Unix or dumpbin /exports on Windows. The mangled name will have the namespace and function name, so it should be easy to find (unless there are several overloads with the same name that you need to distinguish). Are you sure the functions are normal C++ functions and not class methods?

Do yourself a favour : use BridJ for C++ interop, it should be able to deal with most namespace issues :-)
(disclaimer : I'm BridJ's author)

"Jeremiah Willcock" answer is right, in any case, you can always access a D.L.L. functions, inside classes or namespaces using "mangled names", its the weird, dirty way of doing things, but, its works, even if there are other ways.
You could do some tests, accesign those functions, and later, make your own wrapper.

Related

How do classes in the Java standard API interact with the OS?

I've been trying to find an answer to this for some time, but I think part of my problem is that I don't really know how to phrase my question. I understand the that JVM ultimately preforms all the system calls at run-time that the Java program needs to make, my confusion is about the underlying way that Java classes tell the JVM to do this.
Take for example, the File class in the standard Java library. As far as I know, this is considered the most fundamental API for opening/creating files in Java. But, File is just another class right? So in theory I should be able to write my own File class from scratch which doesn't utilize the pre-exisitng one, right? How would I do that? What is happening inside the File class that tells the VM to actually create the file? I looked at the source code for the File class, and it looks like it calls another class called VMFile, but I could find no explanation of what VMFile is. When I looked at the VMFile source code, it just had function declarations with no definitions.
Thank you for your help.
The Java Native Interface (JNI) is the glue between Java classes and the OS. Native methods have a 'native' attribute (look it up in the JLS).

call method from DLL in java7

From what I understood dll are not standardized. thus one cannot just call something in a dll.
However I found this :http://johannburkard.de/software/nativecall/
This library allow you to call any method from a dll in java, so it seems that you can call any method in a dll.
but it was done for 32 bit system, thus I cannot use it.
I have this dll, autohotkey.dll, I know there is the method "ahkExec" inside which take a String as parameter.
Is this really not possible to run it from java without using some kind of c++ magic?
Thanks.
ps : here is how it is done with nativeCall : https://gist.github.com/brigand/1526712
You've been able to call DLLs in Java since version 1.0 using Java Native Interface (JNI).
There is no magic in invoking external methods but you have to follow some rules based on what JNI provides .
If you need to use one function from library you could write a specific Wrapper-class like in this tutorial
For more tricky things better to work with SWIG

using python class methods inside java

I have three different classes written in python. They contain several methods which I want to use them inside my java program (creating objects from these python classes and use these objects to call the methods). Actually my level in java might be intermediate. However, i am absolutely new in python. I have read that it is possible to use Python class methods inside java but there is no clear way that is well explained. So, please help me with a script or a tutorial or any advice that can help understanding using python classes methods in java.
Jython is the way to go. If you have a couple of hours I would recommend you go over the tutorial for it.
If you are curious to see how jython can be used inside java skip to:
http://wiki.python.org/jython/LearningJython#integrating-jython-python-into-java

How can I get Emacs cc-mode functions that refer to functions to work with Java methods?

As noted in cc-mode's documentation, functions like c-indent-defun and c-mark-function "can't be used to reindent a nested brace construct, such as a nested class or function, or a Java method." The same goes for c-beginning-of-defun and its ilk.
Does anyone have a solution to get these functions working with Java methods, or maybe Java-specific replacements?
I don't use Java, but Emacs has a Java Development Environment. JDEE Jalopy claims to do beautifying work. That should help you get the functions you mention.

Can Netbeans(MinGW compiler for c/c++) call on arbitrary C/C++ DLLs(compiled in VS'05)?

AS above, i encountered a "undefined reference error imp_ZN12classNameC1Ev" when using JNI to call upon class functions in arbitrary provided DLL. I am wondering if name mangling incompatibilty for the 2 different compilers is the source of error?
To be exact, can a code compiled by MinGW(gcc/g++) call another code's class function compiled by visualStudio?
Compiling is not exactly the problem. The problem is at linking. If you have C++ interfaces then name mangling will definitively make you trouble. Each compiler has its own name mangling scheme. Too bad, they should have standardized maybe this too in the C++ standard...
One way to workaround the problem is to create a small C wrapper API around the C++ Dll you have (which must be compiled with MSVC) and use this C API from Netbeans. (Eventually making some C++ header-only wrapper for the classes in the c++ dll to make it appear like the original Api. That's two level of wrapping but I have no idea if this can be solved in an easier way.

Categories