c# 两个intPtr之间内存拷贝
来源:互联网 发布:js字符串格式化0在前面 编辑:程序博客网 时间:2024/05/21 09:29
c#中的March 提供了intPtr数组与intPtr之间的转换,但intPtr之间的却没有,尝试过引入window的copymemory但是拷贝出来的是错的,经多次尝试发现借助byte[]是可以完成的。
下面直接上代码:
public struct SCENE
{
public uint dwSize;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 40, ArraySubType = System.Runtime.InteropServices.UnmanagedType.I1)]
public byte[] Name;
}
int tempSize=Marshal.SizeOf(typeof(SCENE));
int tempTolSize= Marshal.SizeOf(typeof(uint))+tempSize*10;
intPtr pTotal=Marshal.AllocHGlobal(tempTolSize);
//过程处理获得pTotal的数据
//获取有效个数
byte[] tempbyte = new byte[Marshal.SizeOf(typeof(uint))];
Marshal.Copy(pstruWinWallParam, tempbyte, 0, Marshal.SizeOf(typeof(uint)));
uint count = System.BitConverter.ToUInt32(tempbyte,0);
//获取详细信息
byte[] tempbyte1 = new byte[tempSize];
for (int i = 0; i < count; i++)
{
Marshal.Copy(pstruWinWallParam + uintSize + dwsize * i, tempbyte1, 0, dwsize);
SCENE scene = (SCENE)BytesToStruct(tempbyte1, typeof(SCENE));
}
//BytesToStruct方法
public static object BytesToStruct(byte[] bytes, Type strcutType)
{
int size = Marshal.SizeOf(strcutType);
IntPtr buffer = Marshal.AllocHGlobal(size);
try
{
Marshal.Copy(bytes, 0, buffer, size);
return Marshal.PtrToStructure(buffer, strcutType);
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
- c# 两个intPtr之间内存拷贝
- 两个集群之间拷贝数据
- Navicate 两个数据库之间拷贝
- C#中的IntPtr使用
- C#中的IntPtr类型
- C#中的IntPtr类型
- C#中的IntPtr类型
- C#中的IntPtr使用
- C#中的IntPtr使用
- C#中的IntPtr类型
- C#中的IntPtr类型
- C#中的IntPtr类型
- C# IntPtr互转String
- C# 数组转Intptr
- C# 的内存拷贝
- C# 的内存拷贝
- 完成内存之间的拷贝
- 两个ubuntu系统之间的文件拷贝
- 怎么给笔记本重装系统图文教程
- Cognos11中ActiveReport在移动端的应用
- Win10系统80端口被系统进程占用
- 成为JavaGC专家(1)—深入浅出Java垃圾回收机制
- Hadoop datanode服务无法启动
- c# 两个intPtr之间内存拷贝
- Echart-折线图
- Linux qtcreator编程实现动态加载动态链接库
- 关于如何下载spring tool Suite指定版本的安装包
- 6/26作业:抽象
- [题解]codeforces 718c Sasha and Array
- Python selenium.common.exceptions.WebDriverException
- 【c++】vector.clear()的内存泄露问题
- 面向对象的三大特征之一封装