🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: callbacks in java?

#20057
From: Lyle Thompson
Date: Fri, 07 Nov 1997 00:00
44 lines
2217 bytes
PS Custom Computer Applications, Inc. wrote:
> 
> Hi,
>  I'm pretty new to java and I was wondering if it is possible to pass
> a java function to a windows API call.  A callback.
> 
> Like doing a Windows message loop implemented entirely in java.
> Is this possible?  If so, are there any examples?
> 
> Thanks for any help.

Well, you asked, so without questioning why...

What you have to do is write some JNI (Java Native Interface) code. 
You would define an object that had the method you wished to invoke 
through the callback (and one more which you would call to
initialize the C code). Then in the implementation DLL, you would 
write a C function which would invoke the java method. 

The trick is that to invoke the Java method you have to go through 
a function table that is passed in from a call from Java into C
(which contains pointers to utility functions to dynamically invoke
the java method, NOT the method pointer itself). So, anyway, before 
the callback was made, the Java code would have to invoke the
initialization method on the JNI object in order to pass a pointer 
to that function table (which you would then save somewhere so it 
would be available from the asynchronous windows callback). Saving 
the pointer is allowed, but there are a few restricitions (which
are getting fuzzy right now, so you'll have to read up on them).

This is pretty hard to explain quickly, so sorry if its not
real clear. In any event, you'll need to familiarize yourself 
with the JNI.

Regards,

Lyle

-- 
Lyle Thompson             Email:  lyle@heliosoft.com
HelioSoft, Inc.           Phone: (510) 278-5249 
664 Paseo Grande          Fax:  (510) 278-5249
San Lorenzo, CA 94580     Web: http://www.heliosoft.com
Technical Details
Message-ID: <3463BB3E.A0B4A30B@heliosoft.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <346225a5.16450664@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,8a9005f7f390ab3
X-Google-Attributes: gidf74b3,public
From: Lyle Thompson <lylet@heliosoft.com>
Subject: Re: callbacks in java?
Date: 1997/11/07
Message-ID: <3463BB3E.A0B4A30B@heliosoft.com>
X-Deja-AN: 287801116
References: <346225a5.16450664@forums.borland.com>
Reply-To: lyle@heliosoft.com
Organization: HelioSoft, Inc.
Newsgroups: borland.public.jbuilder.java.language