[java] Using DLL

Started by
3 comments, last by Jnz86 17 years, 10 months ago
Hi. I have to write a program that uses a DLL written in C. I looked up the google, and everything i found is to use Java Native Interface, but if i understood correctry, first you write program in Java, then code the DLL in C/C++. Well, that's not what i need. I already have a DLL (it was coded by other person, i cant change it), and i need to use it, how do i do that ? Also, one function in the DLL has parameter of HBITMAP, how do i convert my Java image to this one? (Sorry for my poor English)
Advertisement
Hi.

To load a dll, look at the methods System.load and System.loadLibrary.

You'll need to create a JNI wrappers to call the methods in the dll properly.

As for the HBitmap, (I dont know what it specifically contains), - you'll probably have to reconstruct it. I've done this with other structs/classes. You have to do some research, find out exactly how HBitmap is constructed, and then replicate it in java. Make sure you consider unsigned vs signed values etc. Then you can use your replicated class as input/output in both your jni methods, and your basic java methods.
Development blog, The Omega Sector -- http://www.omegasector.org
Quote:Original post by Addictman
To load a dll, look at the methods System.load and System.loadLibrary.

Yes, i have done that.

Quote:Original post by Addictman
You'll need to create a JNI wrappers to call the methods in the dll properly.

Sh*t, i was afraid of this, is there another way?
(If i understood correctly, you mean to write methods in java with "native" keywords, then using javah make headers, and write code in C/C++ that actually loads the DLL and calls it functions?)

Quote:Original post by Addictman
As for the HBitmap, (I dont know what it specifically contains), - you'll probably have to reconstruct it.

Again, sh*t :)

So, there's no way to load DLL without a wrapper?
How does, for example, JLWGL uses OpenGL32.dll ? Does it use a wrapper DLL to "talk" to OpenGL32.dll ?
Quote:Original post by Jnz86
Quote:Original post by Addictman
You'll need to create a JNI wrappers to call the methods in the dll properly.

Sh*t, i was afraid of this, is there another way?
(If i understood correctly, you mean to write methods in java with "native" keywords, then using javah make headers, and write code in C/C++ that actually loads the DLL and calls it functions?)

Quote:Original post by Addictman
As for the HBitmap, (I dont know what it specifically contains), - you'll probably have to reconstruct it.

Again, sh*t :)

So, there's no way to load DLL without a wrapper?
How does, for example, JLWGL uses OpenGL32.dll ? Does it use a wrapper DLL to "talk" to OpenGL32.dll ?


If you want to use JNI, you have to create wrappers. However, you don't have to create them manually. Write the class with the native methods, then compile the class with javac. Then, when you have your .class file, run that through javah. This will create your header files. Its up to you to create the .c files to accompany them.
www.aidanwalsh(.net)(.info)
Quote:Original post by aidan_walsh
Quote:Original post by Jnz86
Quote:Original post by Addictman
You'll need to create a JNI wrappers to call the methods in the dll properly.

Sh*t, i was afraid of this, is there another way?
(If i understood correctly, you mean to write methods in java with "native" keywords, then using javah make headers, and write code in C/C++ that actually loads the DLL and calls it functions?)

Quote:Original post by Addictman
As for the HBitmap, (I dont know what it specifically contains), - you'll probably have to reconstruct it.

Again, sh*t :)

So, there's no way to load DLL without a wrapper?
How does, for example, JLWGL uses OpenGL32.dll ? Does it use a wrapper DLL to "talk" to OpenGL32.dll ?


If you want to use JNI, you have to create wrappers. However, you don't have to create them manually. Write the class with the native methods, then compile the class with javac. Then, when you have your .class file, run that through javah. This will create your header files. Its up to you to create the .c files to accompany them.


Yes, i know that.
Well, thanks.

This topic is closed to new replies.

Advertisement