🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Native methods

#17491
From: Wayne Cole
Date: Wed, 04 Nov 1998 00:00
49 lines
2217 bytes
In article <70l2rm$icp1@forums.borland.com>, eyalhir@netvision.net.il 
says...
> Hi All,
>   Can someone post a code snippet exaplaining how to use methods declared in
> dlls
>     ( under windows platform ) using JBuilder. As far as I've found one
> should declare a
>     native procedure and load the dll using System.loadLibrary at startup.
> Is it true ?
>   How do I specify the types these functions expects - how to write the
> prototype of a
>    native procedure that maps into a procedure in a dll which awaits, for
> example, a
>    pChar variable, what about pointer and other types ??
> 
> TIA,
>   Eyal.
> 
> 
> 
There are three basic steps.

1) Write the Java code that contains the native methods.  (Note: these 
are similar to abstract methods in that they will be implemented later or 
elsewhere).  Compile the Java source into a class file.  Be sure you have 
included the System.loadLibrary call where it will ensure the lib is 
loaded before the native code is invoked.

2) Run the Javah utility on your class file to produce the .h file for 
your native C/C++ code.  

3) write the C/C++ code to implement the methods/functions prototyped in 
the .h file produced by javah. Compile and link the C/C++ code into a 
dynamically loadable library, and locate the library in the appropriate 
place for the target system.

Now you run your Java class as per usual, and the native code will be 
executed. 

If you are going to be doing a lot of this, you may want to pick up a 
copy of "Essential JNI Java Native Interface" by Rob Gordon, Prentice 
Hall, ISBN 0-13-679895-0.

Also look for Javah utility documentation on the javasoft web site.  
(Inprise didn't see fit to include this documentation in JBuilder).

---

wmc
Technical Details
Message-ID: <MPG.10a969c8cb51474698968b@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <70l2rm$icp1@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f87fa0152d0c0d0b
X-Google-Attributes: gidf74b3,public
From: wmcole@ihpweb.com (Wayne Cole)
Subject: Re: Native methods
Date: 1998/11/04
Message-ID: <MPG.10a969c8cb51474698968b@forums.inprise.com>
X-Deja-AN: 408238063
References: <70l2rm$icp1@forums.borland.com>
Organization: Infinity Heart Productions
Newsgroups: borland.public.jbuilder.java.language