Java call C Dll

http://www.velocityreviews.com/forums/t136663-calling-a-c-dll-from-java.html

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


Samagna
  Reply With Quote

Old 09-07-2004, 12:55 PM   #2
Chris Uppal
 
Posts: n/a
Default Re: Calling a C++ dll from Java
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/tutor...1.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





Chris Uppal
  Reply With Quote

Old 09-07-2004, 04:19 PM   #3
Tor Iver Wilhelmsen
 
Posts: n/a
Default Re: Calling a C++ dll from Java
(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 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.


Tor Iver Wilhelmsen
  Reply With Quote

Old 09-08-2004, 01:23 PM   #4
Stian Bakken
 
Posts: n/a
Default Re: Calling a C++ dll from Java
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 have not tried any of these, but they might suit your needs.

Good luck,
Stian

"Samagna" <> wrote in message
news: om...
> 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





Stian Bakken
  Reply With Quote

Old 12-19-2004, 11:35 PM   #5
Robert kebernet Cooper
 
Posts: n/a
Default Re: Calling a C++ dll from Java
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 have used this with Microsoft MapPoint and some
other MS-ish API's quite successfully.
http://www-106.ibm.com/developerwork...y/j-intbridge/



Robert kebernet Cooper
  Reply With Quote

Old 12-20-2004, 11:48 PM   #6
Tilman Bohn
 
Posts: n/a
Default Re: Calling a C++ dll from Java
[f'up2 cljp]

In message < .com>,
Robert kebernet Cooper wrote on 19 Dec 2004 15:35:19 -0800:

[...]
> http://www-106.ibm.com/developerwork...y/j-intbridge/


This looks very interesting, I hadn't 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


Tilman Bohn
原文地址:https://www.cnblogs.com/cy163/p/1615736.html