jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Info on JNI and accessing dll methods. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Info on JNI and accessing dll methods." Watch "Info on JNI and accessing dll methods." New topic
Author

Info on JNI and accessing dll methods.

Bill Ross
Greenhorn

Joined: Dec 20, 2000
Posts: 4
Trying to get started here, looking for direction... or maybe confirm that I am looking the right way. :-)
I am just trying to explore a possible solution to a problem I have by using JNI. I need to call a method in a C++ dll, and I think/believe JNI might be what I need to use.
However, the dll is supplied by a vendor (MS SQL Server DMO) and is not likely to have a JNI.h header file included. If all I want is to call methods in the dll, and receive return values back, does the C++ program need to be modified to work with JNI? I have read that you need to compile the C++ code with a JNI.h header file, but am unsure if this is only if I want to be able to call or invoke Java methods from the C++ program.
The short of it is, I want to be able to list the visible SQL Servers on a network and connect to the one the user chooses. I know the SQL Server DMO C++ library provides this functionality.
I have not used JNI before, but if it works, I can learn. :-)
Which leads to one more question: any good books or places to start on this? Nothing too fancy to start, and just to say, I do know about the Java Tutorial... which is why I have this question. :-)
Any suggestions would be appreciated,
BillR
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The usual way to accomplish this is not to call the DLL directly from Java, but to write a very small C or C++ program which provides a JNI-accessible function which in turn calls the DLL. You call your "wrapper" function from Java using JNI, and use it to return the results you need.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Here's a nice Step-by-Step tutorial.
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step1.html
It doesn't get into return values but it's a stright forward primer.
Sean
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158

Please check out this page where http://www.geocities.com/sahirshah/JNI1.html
I have posted step by step instructions on how to integrate a
piece of legacy VB code with a java application. The same thing
can be applied for C++ dlls by skipping a few of the steps.
Rgds
Sahir


....
Shilpa Tendulkar
Ranch Hand

Joined: Jul 29, 2001
Posts: 75
Originally posted by Sahir Shah:

Please check out this page where http://www.geocities.com/sahirshah/JNI1.html
I have posted step by step instructions on how to integrate a
piece of legacy VB code with a java application. The same thing
can be applied for C++ dlls by skipping a few of the steps.
Rgds
Sahir


Hi Sahir,
I was trying to get some information regarding how to integrate VB with JNI. But the link which u have given is giving a message " the page not found". Hence can u mail me the site address where uve posted it. The steps about the same would be very helpful.
Thank you very much,
Regards
Shilpa
Sorry for the above.Ive now found the steps u have posted. But the url is
"http://www.geocities.com/sahirshah/javapapers/jni.html".
Hi,
I went thru the steps given by you. But ive got stuck at the last step, that is while giving the implementation of Test.h file. When i compile the file it throws the foll error:
"unexpected end of file while looking for the header directive"
Should i include this implementation in the VBToJava project or should it be kept seperate? Can u please elaborate the last steps again.
Thankyou.
[This message has been edited by shilpa (edited July 30, 2001).]


SCJP5
Kartik Shah
Greenhorn

Joined: Aug 09, 2001
Posts: 2
Hi Sahir,
This is Kartik from IIM-Ahmedabad. We are working on a multi-language Web Portal for GrassRoot Innovations. We are working with JSP/XML/SQL. My problem is to call the external DLL from the JSP file. I don't know how should i proceed , i understood the steps given at listed site but it is not much helpful foor my case.
I am stuck up at this point so...
Your help will be a great support
Thanks and Regards
Kartik Shah
Originally posted by Sahir Shah:

Please check out this page where http://www.geocities.com/sahirshah/JNI1.html
I have posted step by step instructions on how to integrate a
piece of legacy VB code with a java application. The same thing
can be applied for C++ dlls by skipping a few of the steps.
Rgds
Sahir


------------------
Kartik Shah
WebMaster/Database Administrator
KnowNet-Grin, Indian Institute of Management,
Ahmedabad - 380015, Gujarat, India.
Ph. +91 79 6324713
Direct +91 79 6307857
Fax: +91 79 6307341


Kartik Shah <br />Information Analyst<br />EDS-India Solution Center,Pune <br />kartik.shah@eds.com <br />Contact: +91-20-56069059 <br /><a href="http://www.eds.com" target="_blank" rel="nofollow">www.eds.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Info on JNI and accessing dll methods.