处理Silverlight UserControl [英] Handle to Silverlight UserControl
问题描述
我有一个用C ++编写的DLL(Player.dll),该DLL在内部使用
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
}
正在工作.
但是现在,我想使用Silverlight 4.0编写相同的应用程序.如您所知,大多数 Windows GDI 都可以使用HWND
在屏幕上渲染图形,这就是为什么我将playerHandle
传递给ProxPlayer
方法的原因,如您所见. Window Forms的UserControl
定义了类型为IntPtr
的称为Handle
的公共属性,它等效于HWND
,因此我将其传递给ProxyPlayer
方法.它解决了我的问题.但是Silverlight的UserControl
没有任何此类属性.
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.
所以我的问题基本上是,我将如何处理Silverlight控件?因为没有它,我无法从Player.dll
调用API.但是我必须从中调用APS.我没有其他选择,因为DLL是真正的引擎,它实际上处理与解释大量数据然后呈现它们有关的所有事情.因此,请提出适合我要求的解决方案!
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!
注意:假定我的silverlight应用程序将始终在Microsoft Windows上运行.因此,在使用Windows GDI时我没有问题.
Note: Assume that my silverlight application will always run on Microsoft Windows. So I don't have problem pinvoking Windows GDI.
推荐答案
如果您可以将本机DLL公开为实现IDispatch的COM服务器,则可以从Silverlight(通过AutomationFactory
类)访问它. Windows中的浏览器外信任应用程序"中.
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.
我仍然建议(根据对达林回答的评论),您应该很好地看待该平台,因为您的"PlayVideo"/"PauseVideo"示例表明您正在尝试做该平台可能已经可以做的事情-以及更好的是,该平台可以在MacOS和浏览器中实现,而不必编写自己的COM Server,等等.
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.
这篇关于处理Silverlight UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!