微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C ++ / WinRT:MIDL 3.0类型:Char-生成的代码的编译返回“ T必须为WinRT类型”有支持用法吗?

如何解决C ++ / WinRT:MIDL 3.0类型:Char-生成的代码的编译返回“ T必须为WinRT类型”有支持用法吗?

使用包含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));
}

解决方法

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

您可以打开属性标签> 属性> 配置属性> C / C ++ > 语言,找到按内置类型处理Wchar_t 属性,然后选择否(/ Zc:wchar_t-)选项。然后,尝试构建您的项目。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。