Search code examples
c++-winrt

C++/WinRT: MIDL 3.0 type: Char - compile of generated code returns 'T must be WinRT type'. Is there a support usage?


Using the idl source containing the MIDL 3.0 simple type Char:

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

And the supporting functions

    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();
    }

Results in an error

T must be a WinRT type

My understanding was that the MIDL 3.0 types are the definition the WinRT types.

The MIDL compiler emits:

//------------------------------------------------------------------------------
// <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));
}

Solution

  • During testing, I have a solution you could make a try.

    You could open the Property tab > Properties > Configuration Properties > C/C++ > Language, find Treat Wchar_t As Built in Type property and select the No(/Zc:wchar_t-) option. Then, try to build your project.