如何从byte转换为intptr

putworld 2006-07-27 09:35:51
谢谢
...全文
819 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pclion 2006-07-28
  • 打赏
  • 举报
回复
Marshal.Copy:
public static void Copy(
byte[] source,
int startIndex,
IntPtr destination,
int length
);
Parameters
source
The one-dimensional array to copy from.
startIndex
The zero-based index into the array where Copy should start.
destination
The memory pointer to copy to.
length
The number of array elements to copy.


例子:
byte[] ba ={ 'a', 'b', 'c', 'd' };
IntPtr p = Marshal.AllocCoTaskMem(ba.Length);
Marshal.Copy(ba, 0, p, ba.Length);
真相重于对错 2006-07-28
  • 打赏
  • 举报
回复
System.IntPtr ptr = Marshal.AllocHGlobal(1);
Marshal.WriteByte(ptr, byte);
putworld 2006-07-28
  • 打赏
  • 举报
回复
是byte,不是byte[]
diandian82 2006-07-27
  • 打赏
  • 举报
回复
byte or byte[] ?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧