加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何最好地将C#中的字节数组转换为C WinRT组件

发布时间:2020-12-15 08:27:43 所属栏目:百科 来源:网络整理
导读:我们有一个带有业务逻辑的WinRT组件,内部按摩C unsigned char缓冲区.我们现在想从C#byte []中提供该缓冲区.完美的边界会是什么样的,即下面的SomeWinRTFunction函数的签名是什么? void SomeWinRTFunction(something containing bytes from managed land){ IV
我们有一个带有业务逻辑的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); 

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读