Sign in to follow this  

[java] An easier JNI question

This topic is 4744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It looks like there isn't a lot of resources for using JNI from C++ to access Java methods. However, I could still make my program work in calling C++ code from Java PROVIDED that it is possible to call methods with void return types. My problem is I don't know how to do this as all resources I've seen for Java calling C++ functions use a non-void return type. Are there any resources on this?

Share this post


Link to post
Share on other sites
Sorry, this whole thing is just frustrating, particularly since I have had no experience with the JNI before this. I have the JNI book which, oddly enough, didn't have the information that its online version had from what I could tell.

Anyway, my problem now is that I tried to run the whole C++ program from Java. However, this program uses OpenGL. Before I thought I was getting runtime DLL linker errors running the C++ code from Java because I thought Java was expecting something to be returned when the C++ code was busy with my glutmainloop. I did compile the C++ code to a DLL and put it in the right folder, so I thought it was odd. However, it now looks like the JNI's looking through my C++ code as I run through it (I don't know the fundamental mechanics of the JNI) and it doesn't understand any of the C++ implementation of OpenGL. So I'm stumped.

At this point I think it would be best if I just wrote the networking code directly into C++. The only problem with that is that the example code I download doesn't compile. Otherwise, after I've worked out all my compile/build errors, it will compile and build but won't run, such as the code here:

http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/

using the code for:

PracticalSocket.h
PracticalSocket.cpp
TCPEchoClient.cpp



Sorry about all this mess...

Share this post


Link to post
Share on other sites
Why didn't you used OpenGL directly from Java?
I hope all this didn't mean you forgot to pass a Window handle to OpenGL, or something like that.
Just to be sure. Have you looked at all executables in the Java bin directory? IIRC it's called javah.exe on windoze. When you run that little launcher on a .java file with native methods you'd get the right names for C++ and assembly.
JNI_package_clazzName_methodName onePointer, otherPointer, yourVariables.
This is all what is neccessary to know to crate JNI assembler libraries.
Calling Java from C++ is of course possible, you just need to inicialise a JVM, get pointer on JVM, get pointer on method you'd like to call, and you are nearly set. Be warned however, it's faster and easily controlable to call a few Dll/so/drivermethods from Java, than calling Java and making unnecessary hard day to yourself from other language.
Quote:
I've seen for Java calling C++ functions use a non-void return type. Are there any resources on this?

Yes EAX. There would be return value. A hint... std call.
Well I hope you compiled C++ in a way Java could access it. Right?

Practical socket? Java has very nice network capabilities. Why have network code as a statically compiled files?

A sidenote It seems you are on a university. So if are doing a programming on that school, go to the teacher ask him a lot of questions, and ask him if he thinks he is less qualified than high school dropout. If not he should work more on your education, especially on basics of programming.

I hope I wasn't too harsh, but I expect from university stuents a certain level of xxx, xxx and ability to read a book. Herbert? Or something better? It would improve your ability to express yourself.

Share this post


Link to post
Share on other sites

This topic is 4744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this