Sagewire Logo

Calling a C++ dll from JAVA

6 Message(s) by 6 Author(s) originally posted in java misc


From: samagna Date:   Tuesday, September 07, 2004
I need to call a function that is there in a C++ dll. The arguments to
the function are STRUCT and string. The return type is void. Also I
donot have any rights to change the dll and I've to use as it is....
So here goes my questions: 1. How to pass a struct variable from JAVA
to a function in DLL . 2. The function returns void and the second
argument is the output variable which I need to use. So is there
anyway, that call by reference can be used from JAVA? 3. Where should
I place my dll to compile it?

Quick reply'd be appreicated.
Thanks in advance.
Samagna


From: Chris Uppal Date:   Tuesday, September 07, 2004
wrote in message :

I need to call a function that is there in a C++ dll. The arguments to
the function are STRUCT and string.



You can not, I'm afraid. JAVA doesn't have the ability to call arbitrary code
from an arbitrary DLL, nor does it understand 'structs'.

So you've to be a bit more indirect. What you'll have to do is write your
own C or C++ code which follows the JNI conventions, and which therefore /can/
be called from JAVA, and then call the other DLL from that.

The Sun JNI tutorial at:

http://JAVA.sun.com/docs/books/tutorial/native1.1/index.html

should get you started on JNI programming. It's not difficult if you keep it
simple, and it does not sound as if you need to do anything very complicated for
these purposes.

-- chris


From: Tor Iver Wilhelmsen Date:   Tuesday, September 07, 2004
samagna@xxxxxxxxxxx (Samagna) writes:

I need to call a function that is there in a C++ dll. The arguments to
the function are STRUCT and string. The return type is void. Also I
donot have any rights to change the dll and I've to use as it is....



You need to make an intermediate layer in JNI that convert JAVA
arguments into the necessary C++ arguments. Since JAVA doesn't have
"out" parameters, you need to use a return value of some sort from
your JAVA native method.


From: Stian Bakken Date:   Wednesday, September 08, 2004
There are commercial software that will wrap .dll's for you. Here are two:
http://www.excelsior-usa.com/xfunction.html
http://www.jniwrapper.com/index.jsp

Disclaimer: I haven't tried any of these, but they might suit your needs.

Good luck,
Stian

I need to call a function that is there in a C++ dll. The arguments to
the function are STRUCT and string. The return type is void. Also I
donot have any rights to change the dll and I've to use as it is....
So here goes my questions: 1. How to pass a struct variable from JAVA
to a function in DLL. 2. The function returns void and the second
argument is the output variable which I need to use. So is there
anyway, that call by reference can be used from JAVA? 3. Where should
I place my dll to compile it?
Quick reply'd be appreicated.
Thanks in advance.


> Samagna


From: Robert kebernet Cooper Date:   Sunday, December 19, 2004
Depending on what you are trying to do, the IBM JAVA-COM bridge can be
a MUCH MUCH easier way of moving data between the two than hand
building JNI stuff. I've used this with Microsoft MapPoint and some
other MS-ish API's quite successfully.
http://www-106.ibm.com/developerworks/library/j-intbridge/


From: Tilman Bohn Date:   Monday, December 20, 2004
[f'up2 cljp]

In message <1103499319.457151.242540@xxxxxxxxxxx>,
wrote in message on 19 Dec 2004 15:35:19 -0800:

[...]
http://www-106.ibm.com/developerworks/library/j-intbridge/



This looks very interesting, I had not known about that! Could come in
very handy indeed in an upcoming project, so thanks from me for that
pointer!

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright



Next Message: Is there a Secure FTP (SFTP) class?


Blogs related to Calling a C++ dll from JAVA

Finding Memory Leaks in Java : Using HeapSummary
One of the Java questions I like to ask at interviews is: Can you have a memory leak ... number of instances and total memory used for each class - I call HeapSummary. ... -Wl,--add-stdcall-alias -shared -o heapsummary.dll heapsummary.c ...

How to call DLL generated in Matlab from Java
How to call DLL generated in Matlab from Java. Date: 28 Jun 2006 Replies: 2 Most Recent Poster: verm25 Views: 9.

RE: JVM and Java settings
ClassNotFoundException: > D:\CFusion\cfx\CFX_CHECK_EMAIL.DLL. Java exception occurred in call to > method. > > I also tried the settings as described in WROX CF5 pro book and googled > myself to death. > > Can someone please help? ...

Hijackthis - Spyware, Viruses, Worms, Trojans Oh My! :: RE: Never ...
O8 - Extra context menu item: &AOL Toolbar search - res://C:\Program Files\AOL Toolbar\toolbar.dll/SEARCH.HTML O9 - Extra button: (no name) - {08B0E5C0-4FCB-11CF-AAA5-00401C608501} - C:\Program Files\Java\jre1.5.0_08\bin\ssv.dll ...

How to call DLL generated in Matlab from Java
How to call DLL generated in Matlab from Java. Date: 30 Jun 2006 Replies: 7 Most Recent Poster: monarc Views: 53.

Breaking Changes
Runtime.dll still exposes a bunch of public types, but you should not use any of these, ... getResource() will be able to search the calling assembly first, ... Ported stub class generator from C# to Java and incorporated it into IKVM. ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional