🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16174

Re: Call a DLL from a java application ...

#16174
From: Hui Kwok Leong
Date: Wed, 24 Mar 1999 00:00
58 lines
2751 bytes
Hi,

For writing the second DLL, One need not has to remember what convention the JNI
uses.  After writing the java file which contains the native functions, compile
it first to get the .class file.

Then you can use the utility JAVAH which is a part of JDK.  This will give a .h
file which is having the exact C function declarations which the JAVA expects
from the DLL.

All we have to do in the DLL is just provide implementations for the functions
generated by JAVAH by including the generated header file.

Hope this helps

Lakshmanna N S

Jason Burton wrote:

> >I use the the method System.LoadLibrary("xxx") where xxx is the name of the
> >dll. The function that I want to call is declared public native in the java
> >file.
> >At runtime, I have the following exception : java.lang.UnsatisfiedLinkError
> >: yyy where yyy is the function that I call.
> >
> >Can you help me to fix this ? Do you know examples of DLL call from java
> >application ?
>
> When you declare a native function, such as:
>
> package MyPackage;
> ...
> public native void myFunc();
>
> the C header file would have the function Java_MyPackage_myFunc.  JNI calls
> use this naming convention, meaning that if the DLL has a function called
> myFunc, you can't call it directly - the DLL must have a function called
> Java_MyPackage_myFunc.
> The way around this that I have used is to create a second DLL as a wrapper
> for the original.  I doubt there is any way to create a DLL from within
> Java - I use C++ or Delphi.  The additional DLL would use the JNI naming
> conventions (Java_MyPackage_myFunc), and would do all necessary type
> conversions (these are a total pain), and then call the original DLL using
> the real naming (myFunc).
> If anybody knows of a better way to do this, PLEASE LET ME KNOW!!!  This is
> cumbersome at best, but it works.
>
> Hope this helps,
> Jason

--
-------------------------------------------------------------
Hui Kwok Leong
Manager, Java Resource Centre
DID: (65) 874-8019
Fax: (65) 779-6958
Email: klhui@krdl.org.sg
-------------------------------------------------------------
Technical Details
Message-ID: <36F84853.1C2E7BF7@krdl.org.sg>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7d8dnf$l4t20@forums.borland.com> <7d8jmb$lao25@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,5ea51dfa91fb275
X-Google-Attributes: gidf74b3,public
From: Hui Kwok Leong <klhui@krdl.org.sg>
Subject: Re: Call a DLL from a java application ...
Date: 1999/03/24
Message-ID: <36F84853.1C2E7BF7@krdl.org.sg>
X-Deja-AN: 458211269
Content-Transfer-Encoding: 7bit
References: <7d8dnf$l4t20@forums.borland.com> <7d8jmb$lao25@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Kent Ridge Digital Lab
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language