c++-cli - 如何将 array<unsigned char> 转换为 unsigned char[]?

标签 c++-cli clr

在 CLR 项目中,我将 AesManaged 类的输出作为 16 字节数组

array<unsigned char>^ result = msEncrypt->ToArray();

但是我需要将其转换为像这样定义的 unsigned char 类型的数组

unsigned char buff[16];

编辑:我确实尝试过这个,但它给出了错误(没有带有这些参数的方法签名,尽管有一个)

System::Runtime::InteropServices::Marshal::Copy(result, 0, buff, 16);

还有这个

buff = reinterpret_cast<unsigned char>(&result);

但错误是表达式必须是可修改的左值

最佳答案

根据这个MSDN documentation我用过这个,看起来很有效

pin_ptr<unsigned char>buff = &result[0];

关于c++-cli - 如何将 array<unsigned char> 转换为 unsigned char[]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32938866/

相关文章:

c# - 从 C++CLR 调用 C# 类

dll - 如何使用 Marshal 类编译 C++ DLL

c++ - 信号功能错误

c# - native 类是否可以使用 .NET 事件?

metadata - 如何读取.net 程序集的元数据表

c# - 如何找到所有包含匹配模式的类型/成员的程序集?

debugging - 查找所有继承自基类的实例

.net - .NET4 中的命令链接

c# - 检索 JIT 输出

c++-cli - C++/CLI-问题 : Is there an equivalent to the C# "is" keyword or do I have to use reflection?