[英]How to get the array of struct with “byte array” from WinRT C++ to C# in Windows Store app?
在這里,我有一個帶有C ++ WinRT組件的C#metro app。 我需要在WinRT中做一些事情,比如分配照片的名稱/路徑,並檢索照片的縮略圖。
首先,我在WinRT C ++中編寫一個值struct並檢索struct array函數,如下所示。
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");
}
};
然后我在C#按鈕中使用TestOutStructArray函數點擊如下。
CTestWinRT myNative = new CTestWinRT();
private void btnTestClick(object sender, RoutedEventArgs e)
{
Item[] items = new Item[2];
myNative.TestOutStructArray(items);
}
該函數正常工作,items數組可以通過調試窗口查看值是否正確。
現在,我想在value struct中添加一個字節數組,如下所示。
public value struct Item
{
String^ strName;
String^ strPath;
uint8 byteThumbnail[8096];
};
這將導致下面的編譯器錯誤:
錯誤C3987:'byteThumbnail':公共成員的簽名包含本機類型'unsigned char [8096]'
錯誤C3992:'byteThumbnail':公共成員的簽名包含無效類型'unsigned char [8096]'
我查看關於value struct的MSDN,它說value struct不能有一個ref類或struct作為成員,所以我想我不能像上面那樣編寫代碼。
http://msdn.microsoft.com/en-us/library/windows/apps/hh699861.aspx
有誰知道如何使用另一種方式來替換值struct? 我需要數組里面有“字節數組”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.