在Applet中加载ActiveX对象
我有一个 Web 应用程序,用于处理从专用麦克风接收到的事件和音频。 音频由在网页中运行的 Java 小程序处理,但其他事件(麦克风连接、麦克风断开、按下麦克风按钮)由 ActiveX 对象处理。
ActiveX 对象捕获这些事件并调用 JavaScript 代码来处理它们。
<!-- 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>
当然,这种方法的一个问题是它完全依赖于 IE。 我更喜欢在小程序中加载 ActiveX 对象,捕获其中的事件并在小程序中或从小程序调用的 JavaScript 代码中处理事件。 这将使我能够在任何支持小程序的浏览器中运行该应用程序。
我不完全确定如何实施我上面提出的解决方案,有什么建议吗?
更新:我意识到我上面提出的解决方案仍然依赖于 IE,这很好。 我的近期目标是支持 Windows 上的所有浏览器。
有人建议我可以使用 JNI(或 JNA)来访问 ActiveX 对象底层的 DLL,而不是使用 ActiveX。 然而,我实际上不想调用DLL中的函数,我希望DLL调用我,即注册一个事件处理程序。
谢谢, 大学教师
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
除 IE 之外,其他浏览器不支持 ActiveX,因此您的应用程序无法支持所有浏览器,即使仅在 Windows 上也是如此。
尝试(插件)在 Firefox 1 下移植 ActiveX,但据我所知并没有真正有用,目前还没有针对您的问题的“模拟”解决方案。
对不起...
(请参阅此处了解 Mozilla 评论)
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)
JACOB 应该让您从 Java 调用 COM。 看起来它也支持事件。
JACOB is supposed to let you call COM from Java. It looks like it supports events too.
你可以直接访问activeX组件中的dll,
所以你可以编写一个调用本机函数的 jni 包装器,
然后构建一个签名的小程序,可以获得使用jni的权限。
检查这个:
http://www.raditha.com/java/jni/
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/
啊。 您可以随心所欲,但可能必须避开 Javascript,而使用 VBScript。 它是关于在两个组件之间发送“事件”的能力。
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.
您可以使用JavaScript直接调用小程序中的公共方法或访问公共变量。 JavaScript 将嵌入的小程序视为一个对象。 在小程序标签中为小程序指定一个名称 id。
考虑下面的示例,其中小程序有一个方法 public void myMethodInMyApplet();
HTML 页面看起来像这样:
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 :
考虑到 Java 小程序是在客户端执行的,那不是仍然依赖于 Windows 甚至 IE 吗? 就是想...
Wouldn't that still be Windows- or even IE-dependent, given that Java applets are executed on the client side? Just wondering...
如果您希望事件最终出现在 JavaScript 中,显然您必须传递事件两次。
SWT 有一个版本可以在小程序中使用并且可以嵌入ActiveX 控件。 还有像 Coroutine 这样的商业库也可以做到这一点(并且 jar 大小更小)。 有人在这里提到了雅各布,这将是另一种选择。
因此,请使用这些组件中的任何一个来包装您的 ActiveX 控件。 当注册事件发生时,这些库将调用 Java 方法。
要将事件从 Java 传递到 JavaScript,您可以使用所有主流浏览器都支持的 netscape.javascript.JSObject 类。
如果您有 COM 组件的源代码,那么重写它以使用 JNI 可能是个好主意,因为 COM 包装器会消耗大量资源(这在小程序中尤其重要),而且很可能还会产生一些开销用于 COM 互操作的 COM 组件内部。
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.
activexobjects 是否总是访问 aivex 网站,例如 activex.microsoft.com
is activexobjects always hitting the acivex sites like activex.microsoft.com