使用GlobalMemoryStatus获得物理内存大小时出错
[DllImport( "kernel32 ")]
public static extern void GlobalMemoryStatus(MEMORYSTATUS lpBuffer);
public struct MEMORYSTATUS
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
MEMORYSTATUS MemStat = new MEMORYSTATUS();
GlobalMemoryStatus(MemStat);
MessageBox.Show(MemStat.dwTotalPhys.ToString() + "\n ");
运行时得到异常信息 System.AccessViolationException:
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
请问这是怎么回事呢?
------解决方案--------------------这个东西肯定没干好事
PS:为啥你不用WMI查询呢楼主?