如何以最佳方式将字节数组从 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,我不确定字节 ->无符号字符,但我怀疑也是。
C#
byte[] array;
SomeWinRTFunction(array);
C++
void SomeWinRTFunction(IVector<unsigned char> bytes)
{
IVector<unsigned char> something using the bytes given from managed land;
}
本白皮书可能会提供更多的启示。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 在c++中获取大文件的大小