读取内存中的值,怎么读取float?

planet 2012-10-30 08:42:24



//读取内存中的整数
public int ReadMemoryValue(int address, int processId)
{
try
{
byte[] buffer = new byte[4];

IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); //获取缓冲区地址
IntPtr hProcess = OpenProcess(0x1F0FFF, false, processId);
ReadProcessMemory(hProcess, (IntPtr)address, byteAddress, 4, IntPtr.Zero); //将制定内存中的值读入缓冲区
CloseHandle(hProcess);
Console.WriteLine(Marshal.ReadIntPtr(byteAddress));
return Marshal.ReadInt32(byteAddress);

}
catch
{
return 0;
}
}


这个是整数的,怎么读取浮点类型的值?如果有 Marshal.ReadFloat() 就好了...



...全文
321 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2012-10-30
  • 打赏
  • 举报
回复
使用BitConverter类。

110,536

社区成员

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

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

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