Java call C DLL

Source: Internet
Author: User
Tags call by reference

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
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 shocould
I place my DLL to compile it?

Quick Reply wocould be appreicated.
Thanks in advance.
Samagna

Samagna

Samagna

#2
Chris Uppal posts: N/

Re: calling a C ++ DLL from Java

Samagna wrote:

> I need to call a function that is there in a C ++ DLL. The arguments
> The function is 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's s '.

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.

TheSunJNI tutorial:

Http://java.sun.com/docs/books/tutor...1.1/index.html

Shocould get you started on JNIProgramming. It's not difficult if you keep it
Simple, And it doesn' t sound as if you need to do anything very complicated
These purposes.

-- Chris

Chris Uppal

Chris Uppal

, 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, PM #4
Stian Bakken posts: N/

Re: calling a C ++ DLL from Java

There are using cial software that will wrap. DLL's for you. Here are two:
Http://www.excelsior-usa.com/xfunction.html
Http://www.jniwrapper.com/index.jsp

Disclause: 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
> 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 shocould
> I place my DLL to compile it?
>
> Quick reply wocould be appreicated.
> Thanks in advance.
> Samagna

Stian Bakken

Stian Bakken

12-19-2004, PM #5
Robert kebernet Cooper posts: N/

Re: calling a C ++ DLL from Java

Depending on what you are trying to do, IBM

JAVA-com bridge can be
a 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-ishAPI'sQuite successfully.
Http://www-106.ibm.com/developerwork...y/j-intbridge/

Robert kebernet Cooper

Robert kebernet Cooper

12-20-2004, 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! Cocould 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.