windows-runtime - 是否可以在我自己的运行时类上实现 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 工具链不能很好地配合,因为我的代码部分是从中生成的。
解决方案
C++/WinRT 不限制可以实现的接口。因此,您可以实现专有接口。这对于实现 WinRT 类或仅用于测试或模拟某些东西非常方便。自然,这对于其他语言或 MIDL 等工具是不可见的,因为它只是 C++ 中的一个实现细节。
推荐阅读
- java - 如何根据语言环境从 String 中获取 Double?
- android - 夜间模式无法正常工作 - 为什么?
- javascript - 在提交时从给定的复选框中至少设置一个复选框
- python - 似乎 misfire_grace_time 不起作用
- java - java.lang.OutOfMemoryError:无法在 Spring Boot 中通过 Selenium 使用 ChromeDriver 和 Chrome 创建新的本机线程错误
- ssl - 本地 TCP 通信的加密机制
- apache-spark - Helm - Spark 运算符示例/spark-pi.yaml 不存在
- html - 尝试找到更好的方式来布局 4 张图片
- python - 从列表矩阵中删除列表 - Python
- java - 根据条件动态忽略 json 属性