my dog learned polymorphism*
The moose likes Other JSE/JEE APIs and the fly likes A JNI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "A JNI question" Watch "A JNI question" New topic
Author

A JNI question

Abdullah Javid
Greenhorn

Joined: Jan 06, 2002
Posts: 12
Hello.
This is Abdullah. I have been programming in Java for an year but I have not used Java JNI API uptill now. Now I need to call some Windows API(native) from withing Java code. Someone please tell me how can I do this. I think this could be done with JNI. I tried to make my hands dirty with JNI but I think it could only call methods from C/C++ classes which we have written. Will anybody please tell me how to call Windows APIs which Microsoft has implemented using Visual C++(or C++). Thanks in advance. I am humbly looking for your replies.
Sincerely,
Abdullah.
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
If you can call your own native methods from Java then you probably know all you need to make this work already. The native method you want to call has to be available to the java code, and you do this with the loadLibrary() method, just as you do with your own library. In this case, you'd be passing the name of the windows DLL that has the API you are trying to call.
I'm not familiar with all the MFC DLLs so I don't know their names, but if you do Windows programming you probably have a way of finding out which DLL contains the methods you want to call. Then you just load that DLL with the loadLibrary() method, and you should be able to call the methods within it from your java app.


Rob
SCJP 1.4
Stu Glassman
Ranch Hand

Joined: Jul 01, 2002
Posts: 91
Rob, I just want to double-check on what you're saying. Can you actually call any native method (stored in a library) from Java, or can you only call methods that have been explicitly declared as Java callable?
-Stu
edited - Sorry, there is no JNI section
[ July 19, 2002: Message edited by: Stu Glassman ]
Abdullah Javid
Greenhorn

Joined: Jan 06, 2002
Posts: 12
Thanks Rob.
I am not fully satisfied with your reply. I think Java can only call those native mathods which are explicitly defined as they are callable by Java. Please tell me if I am wrong. I am looking forward for your reply. If anyone knows something in this regard, please tell.
Thanking,
Abdullah.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A JNI question
 
Similar Threads
what is JNI and what are the advantages of JNI?
Can I call Win32 API from within Java code?
A JNI question
Please anyone reply my questions
plz answer