首页 > 解决方案 > 是否可以在我自己的运行时类上实现 Windows 类型的 [exclusiveto] 接口?

问题描述

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

我很想知道这是如何完成的,所以我创建了一个新的 C++/WinRT 组件并尝试从Windows.Graphics.Holographic.IHolographicSpace我的.idl文件中派生,但 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 工具链不能很好地配合,因为我的代码部分是从中生成的。

标签: windows-runtimec++-winrt

解决方案


C++/WinRT 不限制可以实现的接口。因此,您可以实现专有接口。这对于实现 WinRT 类或仅用于测试或模拟某些东西非常方便。自然,这对于其他语言或 MIDL 等工具是不可见的,因为它只是 C++ 中的一个实现细节。


推荐阅读