Jump to content
  • Advertisement
Sign in to follow this  
Jnz86

[java] Using DLL

This topic is 4490 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

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!