问题
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