簡體   English   中英

如何最好地將C#中的字節數組轉換為C ++ WinRT組件

[英]How to best get a byte array from C# to a C++ WinRT component

我們有一個帶有業務邏輯的WinRT組件,可以在內部按摩C ++ unsigned char緩沖區。 我們現在想從C# byte[]提供該緩沖區。 完美的邊界會是什么樣的, 下面的SomeWinRTFunction函數的簽名是什么?

void SomeWinRTFunction(something containing bytes from managed land)
{
    IVector<unsigned char> something using the bytes given from managed land;
}

對於搜索引擎來說,這類問題看起來似乎太新了......

在C ++部分,該方法應該接受uint8的平台數組(相當於C#字節)。

public ref class Class1 sealed
{
public:
    Class1();
    //readonly array
    void TestArray(const Platform::Array<uint8>^ intArray)
    {

    }
    //writeonly array
    void TestOutArray(Platform::WriteOnlyArray<uint8>^ intOutArray)
    {

    }

};

在C#部分傳遞字節數組:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        Byte[] b = new Byte[2];
        b[0] = 1;
        var c = new Class1();
        c.TestArray(b);
        c.TestOutArray(b); 

    }

在WinRT中,IVector被預測為IList,我不確定byte - > unsigned char,但我懷疑也是如此。

C#

byte[] array;
SomeWinRTFunction(array);

C ++

void SomeWinRTFunction(IVector<unsigned char> bytes) 
{ 
    IVector<unsigned char> something using the bytes given from managed land; 
} 

白皮書可能會有更多的亮點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM