Transition to MIDL 3.0 from classic MIDLRT(从经典 MIDLRT 转换到 MIDL 3.0)

MIDLRT 也称为 MIDL 2.0。 请参阅 MIDL 1.0、2.0 和 3.0

MIDL 3.0 可以与经典 MIDLRT 共存于同一源文件中;无需同时转换 IDL 文件。 无需新的编译器选项来表示你使用的是 MIDL 3.0。 现有选项 /winrt 同时启用经典 MIDLRT 和 MIDL 3.0。

可以将 MIDL 3.0 内容添加到现有的 MIDLRT 类型。 具体而言,可以使用 MIDL 3.0 定义添加到 MIDLRT 中创作的运行时类定义的接口。 这允许使用新技术,同时不需要完全转换类型或文件。 下面是一个示例。

// Existing RTIDL interface definition.
[contract(FooContract, 1), exclusiveto(SampleClass), uuid(...)]
interface ISampleClass : IInspectable
{
    HRESULT Method1([in] boolean something, [in] HSTRING other);
}

// New MIDL 3.0 interface added; needs exclusiveto(), but not uuid().
[contract(FooContract, 2), exclusiveto(SampleClass)]
interface ISampleClass2
{
    Windows.Foundation.IAsyncOperation<String> TransformAsync(UInt32 count);
    String NameProperty { get; };
}

[contract(FooContract, 1)]
runtimeclass SampleClass
{
    [default] interface ISampleClass;
    // Reference to MIDL 3.0-defined interface.
    [contract(FooContract, 2)] interface ISampleClass2;
}

将 MIDL 3.0 构造添加到现有 MIDLRT 运行时类定义会产生类似这样的错误。

1>midl : error MIDL9008 : internal compiler problem - See documentation for suggestions on how to find a workaround.
errors in directory t:\compdev1\src\mincore\coreui\published\idl
t:\compdev1\src\midl : error MIDL9008 : internal compiler problem - See documentation for suggestions on how to find a workaround.
1>midl: Assertion failed: pN->NodeKind() == NODE_INTERFACE_GROUP_MEMBER, file com\rpc\midl\midlrt\front\nodeskl.cxx, line 1403
1>NMAKE : fatal error U1077: 't:\compdev1\src\tools\x86\midl.EXE' : return code '0x2330'

修复此问题的方法有:将完整类转换为 MIDL 3.0,或者使用上述方法添加新接口并添加到 类。