Get SystemMediaTransportControls for other window

岁酱吖の 提交于 2020-07-10 10:32:10

问题


I'm interesting in ISystemMediaTransportControlsInterop::GetForWindow method. The documentation is outdated for it. But I have found files SystemMediaTransportControlsInterop.h and SystemMediaTransportControlsInterop.idl in folder C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um of Windows SDK. They are describing GetForWindow method. So, how can I get an instance of ISystemMediaTransportControlsInterop and call this method?

WinRT contains only method SystemMediaTransportControls.GetForCurrentView, but I want to get an instance of SystemMediaTransportControls for other program from my application.

Thank you


回答1:


So, I have found, that WinRT is based on COM technology. And we can get ActivationFactory to call method from interop interface. For example, on C#:

[Guid("ddb0472d-c911-4a1f-86d9-dc3d71a95f5a")]
[InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
public interface ISystemMediaTransportControlsInterop
{
    SystemMediaTransportControls GetForWindow(IntPtr Window, [In] ref Guid riid);
}

var smtcInterop = (ISystemMediaTransportControlsInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(SystemMediaTransportControls));
var guid = typeof(SystemMediaTransportControls).GUID;
var smtc = smtcInterop.GetForWindow(hwnd, ref guid);

But the problem is, that I receive access denied exception if I try SMTC instance of other window.



来源:https://stackoverflow.com/questions/62222833/get-systemmediatransportcontrols-for-other-window

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