作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 this question 中被告知我首选的解决方案是不可能的后,我现在正在尝试实现一种解决方法。我没有在 C++/CX 中声明从 IClosable 继承的接口(interface),而是在原始 IDL 中声明它。但这似乎也不起作用。
我创建了一个 IDL 文件 FooSpace.idl
包含
import "inspectable.idl";
import "Windows.Foundation.idl";
namespace FooSpace
{
[uuid(01234567-89AB-CDEF-FEDC-BA9876543210)]
[version(42)]
interface Foo : IInspectable requires Windows.Foundation.IClosable
{
}
}
midlrt /nomidl /metadata_dir "C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral" FooSpace.idl
FooSpace.winmd
反汇编生成的
ildasm
时,它看起来还不错——特别是,
Foo
似乎是从
IClosable
继承的,就像
IInputStream
在系统提供的
Windows.winmd
中所做的一样。
void works(Windows::Storage::Streams::IInputStream^ istream) {
Platform::IDisposable^ local = istream ;
}
void doesnt(FooSpace::Foo^ foo) {
Platform::IDisposable^ local = foo ;
}
Foo
产生错误,但不会为
IInputStream
产生错误:
C:\cygwin\tmp>cl /nologo /c /ZW /FU FooSpace.winmd testit.cpp
testit.cpp
testit.cpp(5) : error C2440: 'initializing' : cannot convert from 'FooSpace::Foo ^' to 'Platform::IDisposable ^'
No user-defined-conversion operator available, or
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
public class Whatever {
public static void Works(Windows.Storage.Streams.IInputStream istream) {
System.IDisposable local = istream ;
}
public static void AlsoWorks(FooSpace.Foo foo) {
System.IDisposable local = foo ;
}
}
最佳答案
如果您在 cmds 中添加对 mdmerge 的调用,它应该可以工作:
midlrt /nomidl /metadata_dir "C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral" FooSpace.idl
mdmerge -metadata_dir "C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral" -i "." -o "merged" -v -partial
cl /nologo /c /ZW /FU merged\FooSpace.winmd /EHsc testit.cpp
namespace ClosableTest
{
ref class Test sealed
: FooSpace::Foo
{
public:
virtual ~Test()
{
FooSpace::Foo^ f = nullptr;
Platform::IDisposable^ d = f;
}
};
}
关于windows-runtime - 如何声明继承自 IClosable/IDisposable 的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14653250/
在 this question 中被告知我首选的解决方案是不可能的后,我现在正在尝试实现一种解决方法。我没有在 C++/CX 中声明从 IClosable 继承的接口(interface),而是在原始
我是一名优秀的程序员,十分优秀!