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.
Joined: Jan 07, 2002
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.
Joined: Jul 01, 2002
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 ]
Joined: Jan 06, 2002
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.