Dónal
Dónal

Reputation: 187529

load ActiveX object in Applet

I have a web application that processes events and audio received from a specialised microphone. The audio is processed by a Java applet that runs in the web page, but other events (microphone connected, microphone disconnected, microphone button pressed) are handled by an ActiveX object.

The ActiveX object traps these events and calls JavaScript code to handle them

<!-- Load the ActiveX control -->
<object id="PhilipsSpeechMikeCtrl" width="0" height="0" tabindex="-1"
    classid="CLSID:AAA44754-CC81-4692-91AF-7064E58EB22A"
    standby="Loading Philips SpeechMike component..."
    type="application/x-oleobject">
</object>

<script type="text/javascript">
    // This is Microsofts javascript way of trapping ActiveX object events.

    function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
        // Call JavaScript code to handle the microphone connected event
    }

    function PhilipsSpeechMikeCtrl::SPMEventDeviceDisconnected(deviceID) {
        // Call JavaScript code to handle the microphone disconnected event
    }

    function PhilipsSpeechMikeCtrl::SPMEventButton(deviceID, eventId) {
        // Call JavaScript code to handle the microphone button pressed event
    }
</script>

Of course a problem with this approach is that it's completely IE dependent. I would prefer to load the ActiveX object within the applet, trap the events there and handle the events either within the applet, or JavaScript code called from the applet. This should then enable me to run the app in any browser that supports applets.

I'm not entirely sure how to go about implementing the solution I've proposed above, any suggestions?

Update: I realise the solution I've proposed above would still be IE dependent, that's fine. My immediate goal is to support all browsers on Windows.

It has been suggested that instead of using ActiveX, I could use JNI (or JNA) to access the DLLs underlying the ActiveX object. However, I don't actually want to call the functions in the DLLs, I want the DLLs to call me, i.e. register an event handler.

Thanks, Don

Upvotes: 1

Views: 4900

Answers (8)

shuchi
shuchi

Reputation:

is activexobjects always hitting the acivex sites like activex.microsoft.com

Upvotes: 0

mihi
mihi

Reputation: 6735

You will obviously have to pass the events twice if you want them to end up in JavaScript.

There is a version of SWT that can be used in applets and can embed ActiveX controls. There are also commercial libraries like Coroutine who can do this as well (and are smaller in jar size). Someone else mentioned JACOB here, which would be another choice.

So, use any of these components to wrap your ActiveX control. These libraries will call a Java method when a registered event occurs.

To pass events from Java to JavaScript, you can use the netscape.javascript.JSObject class which is supported by all major browsers.

If you have the source code for the COM component, it might be a good idea to rewrite it to use JNI, as COM wrappers use up a lot of resources (which is especially important in applets), and most probably there is also some overhead inside the COM component for COM interop.

Upvotes: 0

Sarel Botha
Sarel Botha

Reputation: 12700

JACOB is supposed to let you call COM from Java. It looks like it supports events too.

Upvotes: 3

Paul Whelan
Paul Whelan

Reputation: 16809

You can use use JavaScript to directly call public methods in the applet or access public variables. JavaScript treats the embedded applet as an object. In the applet tag give the applet a name id.

Consider the example below where the applet has a method public void myMethodInMyApplet();

The HTML page would look something like :

<APPLET CODE="MyApplet.class" 
   width=200 height=200 
   name=counter ID=counter>
</APPLET>

<script type="text/javascript">
    // This is Microsofts javascript way of trapping ActiveX object events.

    function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
document.applets[0].myMethodInMyApplet();   
 }
 </script>

Upvotes: 1

McGovernTheory
McGovernTheory

Reputation: 6664

Ahh. You can do want you desire, but may have to eschew Javascript and instead leverage VBScript. It is about the ability to send "events" between two components.

Upvotes: 1

KarlP
KarlP

Reputation: 5181

You can probably access the dlls in the activeX component directly, so you can write a jni wrapper that calls the native functions, and then build a signed applet that can get permission to use jni.

Check this:

http://www.raditha.com/java/jni/

Upvotes: 2

Olivier
Olivier

Reputation: 3495

ActiveX are not supported by an another browser than IE, so there is no way for your application to support all browsers, even on Windows only. An attempt (plugin) to port ActiveX under Firefox 1 was made, but wasn't really useful so as far as I know, there is today no "emulation" solution to your question. Sorry... (see here for Mozilla comments)

Upvotes: 5

Lucas Jones
Lucas Jones

Reputation: 20193

Wouldn't that still be Windows- or even IE-dependent, given that Java applets are executed on the client side? Just wondering...

Upvotes: 0

Related Questions