Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling a C++ dll from Java

3 views
Skip to first unread message

Samagna

unread,
Sep 7, 2004, 6:32:56 AM9/7/04
to
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 have 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 would be appreicated.
Thanks in advance.
Samagna

Chris Uppal

unread,
Sep 7, 2004, 7:55:14 AM9/7/04
to
Samagna wrote:

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

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

So you have to be a bit more indirect. What you will 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 doesn't sound as if you need to do anything very complicated for
these purposes.

-- chris

0 new messages