Calling a C++ dll from Java

S

Samagna

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
 
C

Chris Uppal

Samagna said:
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
 
T

Tor Iver Wilhelmsen

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....

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top