Board index » jbuilder » COM callbacks and Java Native Interface

COM callbacks and Java Native Interface


2005-02-03 11:04:54 PM
jbuilder24
Here's the problem: A COM server from a third-party has Advise and Unadvise
methods for hooking COM event handlers. I coded the COM event handlers and
put them in a DLL. Everything works fine when I test my DLL with a Win32 app
(written in Delphi). The COM event handlers get called, my code runs, the
whole thing is perfect.
Now, I have a Java Native Interface portion in my DLL so I can use this
third-party COM server from Java. Outgoing calls 1) from the JVM, 2) down
into the JNI layer, 3) out through COM to the 3rd-party COM server and 4)
back through the COM event handlers, 5) back into the JVM work fine. What
does not work with Java are *spontaneous* COM events originated in the
3rd-party COM server, ie 1) from the COM server, 2) to the COM event
handlers. They work fine in Win32, but not in Java.
It seems that the JVM is somehow blocking incoming COM calls. If the
3rd-party COM server issues a callback to a COM event handler, the event
only fires when the JVM "re-enters" COM by an outgoing call to the server.
Any help would be appreciated.
--
Richard Blouin
 
 

Re:COM callbacks and Java Native Interface

[follow-up set to borland.public.jbuilder.java.api -- crossposting
violates Borland Newsgroup Guidelines]
Richard Blouin wrote:
Quote
Any help would be appreciated.
I thought about this, and talked about it with one of my associates and
he and I both agreed that we're suprised it's worked as well as it as
for you up to this point. Obviously Sun has provided *some* level of
support for JNI-COM interoperability. For your problem I'd recommend
you write native code that intercepts the spontaneous COM event and
calls a routine in the Java library via JNI at that point. Sort of a
'bridge' if you will.
--
David Orriss Jr. *TeamB*
www.davenet.net/
* Please limit all responses to the newsgroups. Thanks! *
Got a JBuilder website? Join the JBuilder Netring! Check out
www.davenet.net/jbwebring/jbwebring.htm for more information!
My blog: mywebpages.comcast.net/daorriss/
Save yourself some time and check these sites:
Borland Newsgroup Search:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's Faq-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:COM callbacks and Java Native Interface

Thanks. I already have the COM-JNI code. It works well when the JVM is
originating the call out, but not when the call is spontaneously issued from
the COM server. Let me explain in detail:
The COM server implements interface IServer, which has (among other things)
methods Advise and Exit. You call Advise to give it your implementation of
interface IServerEvents, so that the server may call your event handler when
appropriate. IServerEvents has (among other things) method OnExiting.
OnExiting is called when the COM server is going away, ie. when the
3rd-party application in which the COM server lives exits.
Now, the following sequence works both in Win32 and under Java:
Client calls CoCreateInstance of the Server and obtains IServer
Client calls IServer.Advise(MyServerEvents)
... [client does processing, calls other IServer methods]
Client calls IServer.Exit
Server calls back MyServerEvents.OnExiting
[client OnExiting code runs and returns]
[call to IServer.Exit returns]
All of the above is working, normal and bug-free. No problem here.
The following sequence works in Win32, but NOT under Java:
Client calls CoCreateInstance of the Server and obtains IServer
Client calls IServer.Advise(MyServerEvents)
... [client app does processing, calls other IServer methods]
... [client app is idle, waiting for user input]
==>User manually exits the application that is hosting COM Server
Server calls back MyServerEvents.OnExiting
[client OnExiting code runs and returns]
What happens under Java:
==>User manually exits the application that is hosting COM Server
Server calls back MyServerEvents.OnExiting
[Server blocks until client issues another call on its IServer interface]
(!!)
[client OnExiting code runs and returns]
Initially, I thought it could have someting to do with the Swing thread, but
no. It looks like COM callbacks are blocked until the client re-enters the
Apartment. But why only under Java?
--
Richard Blouin
"David Orriss, Jr. [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
[follow-up set to borland.public.jbuilder.java.api -- crossposting
violates Borland Newsgroup Guidelines]

Richard Blouin wrote:

>Any help would be appreciated.

I thought about this, and talked about it with one of my associates and
he and I both agreed that we're suprised it's worked as well as it as
for you up to this point. Obviously Sun has provided *some* level of
support for JNI-COM interoperability. For your problem I'd recommend
you write native code that intercepts the spontaneous COM event and
calls a routine in the Java library via JNI at that point. Sort of a
'bridge' if you will.

--
David Orriss Jr. *TeamB*
www.davenet.net/
* Please limit all responses to the newsgroups. Thanks! *
Got a JBuilder website? Join the JBuilder Netring! Check out
www.davenet.net/jbwebring/jbwebring.htm for more information!

My blog: mywebpages.comcast.net/daorriss/

Save yourself some time and check these sites:

Borland Newsgroup Search:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's Faq-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

{smallsort}