获取其他 window 的 SystemMediaTransportControls
Get SystemMediaTransportControls for other window
我对 ISystemMediaTransportControlsInterop::GetForWindow 方法很感兴趣。该文档已过时。但是我在文件夹 C:\Program Files (x86 )\Windows Kits\Include.0.19041.0\um Windows SDK。他们正在描述 GetForWindow
方法。那么,如何获取 ISystemMediaTransportControlsInterop
的实例并调用此方法?
WinRT 仅包含方法 SystemMediaTransportControls.GetForCurrentView,但我想从我的应用程序中为其他程序获取 SystemMediaTransportControls
的实例。
谢谢
所以,我发现 WinRT 基于 COM 技术。我们可以得到 ActivationFactory
从互操作接口调用方法。
例如,在 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);
但问题是,如果我尝试其他 window.
的 SMTC 实例,我会收到访问被拒绝的异常
我对 ISystemMediaTransportControlsInterop::GetForWindow 方法很感兴趣。该文档已过时。但是我在文件夹 C:\Program Files (x86 )\Windows Kits\Include.0.19041.0\um Windows SDK。他们正在描述 GetForWindow
方法。那么,如何获取 ISystemMediaTransportControlsInterop
的实例并调用此方法?
WinRT 仅包含方法 SystemMediaTransportControls.GetForCurrentView,但我想从我的应用程序中为其他程序获取 SystemMediaTransportControls
的实例。
谢谢
所以,我发现 WinRT 基于 COM 技术。我们可以得到 ActivationFactory
从互操作接口调用方法。
例如,在 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);
但问题是,如果我尝试其他 window.
的 SMTC 实例,我会收到访问被拒绝的异常