Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here I have a C# metro app with a C++ WinRT component. I need to do something in WinRT, like assign a photo's name/path, and retrieve photo's thumbnail.

First, I write a value struct and retrieve struct array function in WinRT C++ as below.

public value struct Item
{
    String^ strName;
    String^ strPath;
};
public ref class CTestWinRT sealed
{
public:
    CTestWinRT();
    void TestOutStructArray(Platform::WriteOnlyArray<Item>^ intOutArray)
    {
        intOutArray->Data[0].strName = ref new String(L"test1.jpg");
        intOutArray->Data[0].strPath = ref new String(L"c:\\temp");
        intOutArray->Data[1].strName = ref new String(L"test2.jpg");
        intOutArray->Data[1].strPath = ref new String(L"c:\\temp");
    }
};

Then I use TestOutStructArray function in C# button click as below.

    CTestWinRT myNative = new CTestWinRT();
    private void btnTestClick(object sender, RoutedEventArgs e)
    {
        Item[] items = new Item[2];
        myNative.TestOutStructArray(items);
    }

The function is working ok and the items array can see the values are correct by debug window.

Now, I want to add a byte array in value struct as below.

public value struct Item
{
    String^ strName;
    String^ strPath;
    uint8 byteThumbnail[8096];
};

This will cause compiler error below:

error C3987: 'byteThumbnail': signature of public member contains native type 'unsigned char [8096]'

error C3992: 'byteThumbnail': signature of public member contains invalid type 'unsigned char [8096]'

I look into MSDN about value struct, it said value struct cannot have a ref class or struct as a member, so I think I cannot write the code like above.

http://msdn.microsoft.com/en-us/library/windows/apps/hh699861.aspx

Does anyone know how to use another way to replace value struct? I need the array to have "byte array" inside.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The following array types can be passed across the ABI:

  1. const Platform::Array^,
  2. Platform::Array^*,
  3. Platform::WriteOnlyArray,
  4. return value of Platform::Array^.

A value struct or value class can contain as fields only fundamental numeric types, enum classes, or Platform::String^.

So you cannot use a value struct with arrays. And you cannot use arrays of uint8[] type.

You should pass arrays and structs separately or by using a ref class.

share|improve this answer
    
Hi maxim, thanks –  yr_deng Jan 30 '13 at 2:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.