Java call C Dll

來源:互聯網
上載者:User

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

 
Samagna

09-07-2004, 12:55 PM   #2
Chris Uppal  Posts: n/a

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

 

Chris Uppal

09-07-2004, 04:19 PM   #3
Tor Iver Wilhelmsen  Posts: n/a

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

 

Tor Iver Wilhelmsen

09-08-2004, 01:23 PM   #4
Stian Bakken  Posts: n/a

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

 

Stian Bakken

12-19-2004, 11:35 PM   #5
Robert kebernet Cooper  Posts: n/a

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

 

Robert kebernet Cooper

12-20-2004, 11:48 PM   #6
Tilman Bohn  Posts: n/a

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.