0

I'm creating a winrt component for uwp with C++/WinRT. And I defined a runtimeclass like blew,

namespace TagLibUWP
{
    [bindable]
    [default_interface]
    runtimeclass Picture 
    {
        Picture();
        UInt8[] Data{ get; set; };
    }
}

Then the cppwinrt compiler generates the code like this,

struct Picture : PictureT<Picture>
    {
        Picture() = default;

        com_array<uint8_t> Data();
        void Data(array_view<uint8_t const> value);
    };

The winrt component was compiled, but when another UWP app (written with C++/WinRT) reference to the component, the app failure to compile.

The error is like blew,

Error   C2664    'auto winrt::impl::consume_TagLibUWP_IPicture<winrt::TagLibUWP::IPicture>::Data(winrt::array_view<const uint8_t>) const': 
cannot convert argument 1 from 'winrt::com_ptr<To>' to 'winrt::array_view<const uint8_t>'
        with
        [
            To=uint8_t []
        ]   BlankApp1   C:\Users\Cool-\source\repos\Test\TagLib\BlankApp1\Generated Files\XamlTypeInfo.g.cpp    88  

What makes me confused is that a uwp app (written with C#) can be compiled.

In short, I just want a replacement of Array in C++/CX. I have found this, which is not I want. Waht I want to know is how to define a property of byte array in MIDL 3.0. I have tried like above but it seems that I can't do it like above.
So can somebody help me with this problem?

Cool
  • 23
  • 5
  • Can you show the code that is calling the property setter? With data types. – Raymond Chen Sep 11 '19 at 02:50
  • template void SetReferenceTypeMember_Data( ::winrt::Windows::Foundation::IInspectable const& instance, ::winrt::Windows::Foundation::IInspectable const& value) { instance.as().Data(value.as()); } – Cool Sep 11 '19 at 03:02
  • it seems that if I remove the [bindable] attributes, it will work well. – Cool Sep 11 '19 at 03:12
  • That line of code is still not sufficient to diagnose the problem. What is `TValue`? Are you assigning to Data via binding? What is your XAML? – Raymond Chen Sep 11 '19 at 18:23
  • I don't need to assign to Data via binding. And when I remove the [bindable], it works, that is I want. The "Data" is just a simple property that can be get and set. – Cool Sep 16 '19 at 14:39
  • You need to show the part of your code that is causing the XAML code generator to emit the `SetReferenceTypeMember_Data` method. Also, the error message is incomplete; it doesn't specify what `TDeclaringType` and `TValue` are, or who is instantiating `SetReferenceTypeMember_Data` with that `TValue`. It looks like somebody is trying to assign a single `uint8_t` instead of an array. – Raymond Chen Sep 16 '19 at 18:01
  • Okay, I pasted the above into a test project and found the error. Trying to figure out what's going on. Instantiation is `SetReferenceTypeMember_Data`. – Raymond Chen Sep 16 '19 at 19:00
  • Okay, this looks like a codegen bug in the XAML compiler. It appears to be mishandling conformant array properties. One workaround is to remove `[bindable]` like you did. Another workaround is to change the property type to a non-array. For example, you could use an `IBuffer`. – Raymond Chen Sep 16 '19 at 19:32

0 Answers0