Handle to Silverlight UserControl

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 05:40:12

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4744522/handle-to-silverlight-usercontrol

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