刚才看了下MSDN,上面说Marshal类支持的平台有那么多: Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360这里面包含你要的手机的吧。
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360这里面包含你要的手机的吧。
还需要Marshal.Copy()从内存中拷贝到byte[] lz最好贴出具体错误
这个方法在手机里不支持(msdn上面写了),所以求教还有别的方法吗?
Marshal.StructureToPtr
这两个方法 转换结构体
//创建byte数组
byte[] bytes = new byte[size];
//分配结构体大小的内存空间
IntPtr structPtr = Marshal.AllocHGlobal(size);
//将结构体拷到分配好的内存空间
Marshal.StructureToPtr(structObj, structPtr, false);
//从内存空间拷到byte数组
Marshal.Copy(structPtr, bytes, 0, size);
//释放内存空间
Marshal.FreeHGlobal(structPtr);
手机里面不支持(红色标记的)那个方法,该怎么解决?
_Bytes.a=100;
_Bytes.b=200; int _StructSize =Marshal.SizeOf(_Bytes);
IntPtr _StructIntPtr = Marshal.AllocCoTaskMem(_StructSize);
Marshal.StructureToPtr(_Bytes, _StructIntPtr, false);
byte[] _ValueBytes = new byte[_StructSize];
Marshal.Copy(_StructIntPtr, _ValueBytes, 0, _StructSize);
IntPtr _ObjectIntPtr = Marshal.AllocCoTaskMem(_StructSize);
Marshal.Copy(_ValueBytes, 0, _ObjectIntPtr, _StructSize);
SendBytes _Object = (SendBytes)Marshal.PtrToStructure(_ObjectIntPtr, typeof(SendBytes));
public struct SendBytes
{
public int a; public ushort b;
}