在Silverlight中编组非托管代码 [英] Marshalling unmanaged code in silverlight

查看:88
本文介绍了在Silverlight中编组非托管代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了这个小型Web应用程序.它有一个activex控件,该控件通过javascript将非托管代码返回到silverlight应用程序.在Silverlight中,我对返回的值执行封送处理操作.当我仅执行GetSize()的简单操作时,我会遇到愚蠢的错误.这使我想到了一个问题:是否可以在Silverlight中执行编组操作?

解决方案

Silverlight的安全模型和沙箱不允许透明"(用户代码和应用程​​序)执行p/调用,可信操作或任何此类操作. /p>

如果您已经安装了ActiveX控件并且可用于网页,则需要使用Silverlight的HTML互操作性功能自行整理数据.有一篇有关HTML桥的 MSDN文章专门针对Silverlight 2,但是在新版本的Silverlight中也会发现它.

这假定您的ActiveX控件已经可以通过浏览脚本/JavaScript进行访问.

尽管一些数字编组和其他一些原语在平台上运行良好,但您最终可能会通过使用字符串将所有数据从ActiveX控件中移出,然后再将其解析回Silverlight客户端上.

这至少可以启用您的方案.

I've got this small web application I've built. It's got an activex control returning unmanaged code through javascript into a silverlight application. In silverlight I perform a marshaling operation on the returned value. When I only perform the simple operation of GetSize() I get struck with a stupefing error. This brings me to my question: Is it possible to perform a marhsalling operation in silverlight, if so how?

解决方案

Silverlight's security model and sandbox do not allow "transparent" (user code and applications) to perform p/invokes, trusted operations, or anything of that sort.

If you already have an ActiveX control installed and available to the web page, you'll need to use the HTML Interoperability features of Silverlight to marshall the data yourself. There's an MSDN article about the HTML bridge that's specific to Silverlight 2, but you'll find it the same in newer releases of Silverlight as well.

This assumes that your ActiveX control is accessible through browsing scripting / JavaScript already.

Though some marshalling of numbers and some other primitives works well in the platform, you'll likely end up moving all your data from your ActiveX control through the use of strings, then parsing it back on the Silverlight client.

This might at least enable your scenario.

这篇关于在Silverlight中编组非托管代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆