load ActiveX object in Applet

◇◆丶佛笑我妖孽 提交于 2019-12-08 04:56:55

问题


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


回答1:


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)




回答2:


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




回答3:


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/




回答4:


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.




回答5:


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>



回答6:


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




回答7:


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.




回答8:


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



来源:https://stackoverflow.com/questions/752352/load-activex-object-in-applet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!