【问题标题】:C++/WinRT: MIDL 3.0 type: Char - compile of generated code returns 'T must be WinRT type'. Is there a support usage?C++/WinRT:MIDL 3.0 类型:Char - 编译生成的代码返回“T 必须是 WinRT 类型”。有支持用法吗?
【发布时间】:2020-11-05 15:22:33
【问题描述】:

使用包含 MIDL 3.0 简单类型 Char 的 idl 源:

namespace BrokenMIDL_Char
{
    [default_interface]
    runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
    {
        MainPage();
        Int32 MyProperty;
        Char MyStationLetter_1;
        //Char MyStationLetter_2;
        //Char MyStationLetter_3;
    }
}

及配套功能

    wchar_t MyStationLetter_1()
    {
        throw hresult_not_implemented();
    }

    void MyStationLetter_1(wchar_t /*value*/)
    {
        throw hresult_not_implemented();
    }

     char16_t MyStationLetter_2()
    {
        throw hresult_not_implemented();
    }

    void MyStationLetter_2(char16_t /*value*/)
    {
        throw hresult_not_implemented();
    }


    char MyStationLetter_3()
    {
        throw hresult_not_implemented();
    }

    void MyStationLetter_3(char /*value*/)
    {
        throw hresult_not_implemented();
    }

导致错误

T 必须是 WinRT 类型

我的理解是 MIDL 3.0 类型是 WinRT 类型的定义。

MIDL 编译器发出:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
template<typename TDeclaringType, typename TValue>
void SetValueTypeMember_MyStationLetter_1(
    ::winrt::Windows::Foundation::IInspectable const& instance,
    ::winrt::Windows::Foundation::IInspectable const& value)
{
    instance.as<TDeclaringType>().MyStationLetter_1(::winrt::unbox_value<TValue>(value));
}

【问题讨论】:

  • 在这种情况下T 是什么?显示的代码中没有T
  • T 是 MIDL 编译器生成的文件代码(由其定义)的一部分。
  • 你能显示那个代码吗?
  • MIDL 编译器发出 ``` 模板 void SetValueTypeMember_MyStationLetter_1( ::winrt::Windows::Foundation::IInspectable const& instance, ::winrt::Windows::Foundation ::IInspectable const& value) { instance.as().MyStationLetter_1(::winrt::unbox_value(value)); } ```
  • 这应该被编辑到你的问题中,而不是在 cmets 中发布。这次我已经为您完成了,下次请务必发布所有相关详细信息。话虽如此,我在这段代码中仍然没有看到任何T,那么它到底在抱怨哪个T?假设TDeclaringTypeTValue,它们在模板的实例化中实际设置为什么?

标签: c++-winrt


【解决方案1】:

在测试过程中,我有一个解决方案你可以试试。

您可以打开 属性 标签 > 属性 > 配置属性 > C/C++ > 语言,找到Treat Wchar_t As Built in Type属性并选择No(/Zc:wchar_t-)选项。然后,尝试构建您的项目。

【讨论】:

  • 是的,这行得通。我可能会提到,这不是 CppWinRT vsix 安装的项目模板中使用的默认设置。
猜你喜欢
  • 2012-08-13
  • 2015-05-16
  • 2019-07-11
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
相关资源
最近更新 更多