将字节数组转换为字节指针 [英] Convert byte array to byte pointer

查看:248
本文介绍了将字节数组转换为字节指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个C ++ CLR类方法,它将System :: Byte * b作为参数参数。我希望CSharp调用者将一个字节*传递给这个函数。

但是在CSharp prorgram中,我只设法创建一个字节数组(byte [])。


谁能告诉我如何在CSharp中将字节数组转换为字节指针?


请给我一个关于如何操作的简单示例。


感谢您的帮助

编辑/删除消息

解决方案

@MrVS

在使用指针之前需要使用unsafe关键字... 不安全

示例代码

展开 | 选择 | Wrap | 行号


@DeepBlue


我无法将其转换为字符串,arr在我的代码中是一个可序列化的对象,在C#中设置为Class类型。我使用以下代码将此类型对象转换为可序列化的字节数组:

展开 | 选择 | Wrap | 行号


对象。


例如,如果您在C ++中有此签名:

展开 < span class =codeDivider> | 选择 | Wrap | Line编号

Hi,

I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function.
But in the CSharp prorgram, I only managed to create a byte array (byte[]).

Can anyone tell me how to convert byte array to byte pointer in CSharp?

Please show me an simple example about how to do it.

Thank you for your help
Edit/Delete Message

解决方案

@MrVS
You need to use unsafe keyword before using pointers... unsafe
sample code

Expand|Select|Wrap|Line Numbers


@DeepBlue
I can''t convert it to string, the "arr" in my code is a serializable object, setup as Class type in C#. I used the following codes to convert this Class type object into serializable byte array:

Expand|Select|Wrap|Line Numbers


[EDIT:] Ooops, I just realized you were talking about C++/CLR. In that case, you are not calling a unmanaged dll.

Anyway, this part covers unmanaged interop.

You have to tell .Net that you want to marshal the unmanaged array to a managed byte[] object.

For example, if you have this signature in C++:

Expand|Select|Wrap|Line Numbers


这篇关于将字节数组转换为字节指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆