是否可以在我自己的运行时类上从 Windows 类型实现 [exclusiveto] 接口?

Is it possible to implement an [exclusiveto] interface from a Windows type on my own runtimeclass?

我目前正在试验 Holographic Remoting 并发现通常由 Windows 实现的全息 API 的各个部分来自其他地方。
例如,我的 HolographicSpace 来自 Microsoft.Perception.Simulation.dll,这是上面链接的库。

我很想知道这是如何完成的,所以我创建了一个新的 C++/WinRT 组件并尝试从我的 .idl 文件中的 Windows.Graphics.Holographic.IHolographicSpace 派生,但 MIDL 编译器会给我这个错误信息: error MIDL5051: [msg]use of the [exclusiveto] interface is not valid, use the runtimeclass for which this interface is exclusiveto instead.

说得对,不然[exclusiveto]有什么用?

但是,问题仍然存在:外部组件如何假装它实现了 Windows 命名空间中的类型?我的意思是理论上我可以使用 implements<> 结构模板并在我的类型上实现所有必需的 COM 接口,但这不能很好地与整个 MIDL 工具链一起使用,因为我的代码部分是从中生成的。

C++/WinRT 不限制您可以实现的接口。因此,您可以实现独占接口。这对于实现 WinRT class 或仅用于测试或模拟某些东西可能很方便。当然,这对于其他语言或工具(如 MIDL)是不可见的,因为它只是 C++ 中的一个实现细节。