Silverlight 用户控件句柄

发布于 2024-10-13 03:02:55 字数 1416 浏览 3 评论 0原文

我有一个用 C++ 编写的 DLL (Player.dll),内部使用 Windows GDI。我有一个用 Windows 窗体编写的应用程序(基本上是视频播放器),它在内部调用来自 Player.dll 的 API,使用 p/invoke 在屏幕上呈现实际图形技术:

public class ProxyPlayer
{
    [DllImport("Player.dll", CharSet=CharSet.Unicode, EntryPoint="PlayVideo")]
    public static extern void Play(int playerHandle, out TWResult result);

    [DllImport("Player.dll", CharSet=CharSet.Unicode, EntryPoint="PauseVideo")]
    public static extern void Pause(int playerHandle);

    //other methods
}

正在发挥作用。

但现在,我想使用 Silverlight 4.0 编写相同的应用程序。如您所知,大多数 Windows GDI 都可以工作使用 HWND 在屏幕上渲染图形,这就是为什么我将 playerHandle 传递给 ProxPlayer 方法,正如您在上面看到的那样。 Window Forms的UserControl定义了一个名为Handle的公共属性,类型为IntPtr,它相当于HWND,所以我通过到 ProxyPlayer 方法。它解决了我的问题。但 Silverlight 的 UserControl 没有任何此类属性。

所以我的问题基本上是,我如何处理我的 silverlight 控件?因为没有它,我无法从 Player.dll 调用 API。但我必须从中调用 APS。我没有任何其他选择,因为 DLL 是实际的引擎,它确实可以执行与解释大量数据然后渲染它们相关的所有事情。所以请建议我适合我的要求的解决方案!

注意:假设我的 silverlight 应用程序将始终在 Microsoft Windows 上运行。所以我在 pinvoking Windows GDI 时没有问题。

I've a DLL (Player.dll) written in C++ that internally uses Windows GDI. I've an application (basically a video player) written in Windows Forms, that internally calls APIs from Player.dll to render the actual graphics on screen, using p/invoke technique:

public class ProxyPlayer
{
    [DllImport("Player.dll", CharSet=CharSet.Unicode, EntryPoint="PlayVideo")]
    public static extern void Play(int playerHandle, out TWResult result);

    [DllImport("Player.dll", CharSet=CharSet.Unicode, EntryPoint="PauseVideo")]
    public static extern void Pause(int playerHandle);

    //other methods
}

It's working.

But now, I want to write the same application using Silverlight 4.0. As you know most Windows GDI works with HWND to render graphics on screen, that is why I pass playerHandle to ProxPlayer methods, as you can see above yourself. Window Forms' UserControl defines a public property called Handle of type IntPtr which is equivalent to HWND, so I pass that to ProxyPlayer methods. It solved my problem. But Silverlight's UserControl doesn't have any such property.

So my question basically is, how would I get handle to my silverlight control? Because without it, I cannot call APIs from Player.dll. But I've to call APS from it. I don't have any other options, as the DLL is actual engine that does literally everything related to interpreting a huge amount of data and then rendering them. So please suggest me solution that fits in with my requirement!

Note: Assume that my silverlight application will always run on Microsoft Windows. So I don't have problem pinvoking Windows GDI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦归所梦 2024-10-20 03:02:55

我有一个用 C++ 编写的 DLL (Player.dll),内部使用 win32 API

您可以简单地忘记从 Silverlight 调用类似的 PInvoking。 Silverlight 旨在跨浏览器/平台运行。想象一下您在 MacOS 下的代码。因此,请将您的精力集中在搜索可以从 Silverlight 运行的此代码的托管等效项上,否则您只是在浪费时间。

I've a DLL (Player.dll) written in C++ that internally uses win32 API

You can simply forget about PInvoking into something like this from Silverlight. Silverlight was intended to run cross browser/platform. So imagine your code under MacOS. So concentrate your energy into searching a managed equivalent of this code that could run from Silverlight or you are simply wasting your time.

粉红×色少女 2024-10-20 03:02:55

如果您可以将本机 DLL 公开为实现 IDispatch 的 COM 服务器,并且您位于 Windows 上的浏览​​器外受信任应用程序中,则可以从 Silverlight 访问该 DLL(通过 AutomationFactory 类)。

我仍然建议(根据我对达林回答的评论)您仔细研究一下该平台,因为您的“PlayVideo”/“PauseVideo”示例表明您正在尝试做平台可能已经可以做的事情 - 甚至更好,该平台可以在 MacOS 和浏览器中执行此操作,而无需编写自己的 COM 服务器等丑陋操作。

If you can expose your native DLL as a COM Server that implements IDispatch, you can access that from Silverlight (via the AutomationFactory class) if you're in an Out of Browser Trusted Application on Windows.

I still recommend (per my comment to Darin's answer) that you take a good look at the platform, as your "PlayVideo"/"PauseVideo" example suggests you're trying to do things the platform can likely already do - and better yet, the platform can do it on MacOS, and in-browser, and without the ugliness of writing your own COM Server, and so on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文