【发布时间】:2011-09-23 17:07:49
【问题描述】:
我正在尝试使用 GetSystemInfo() 从 Windows 7 上的 C# 3.5 Windows 服务应用程序获取分配粒度大小。但是,当调用返回时,SYSTEM_INFO 结构在 dwAllocationGranularity 中始终为 0(其他字段已填充数据符合预期)
SYSTEM_INFO 结构如下所示,为简洁起见省略了 PROCESSOR_ARCHITECTURE 和 PROCESSOR_TYPE 枚举:
public struct SYSTEM_INFO
{
public PROCESSOR_ARCHITECTURE wProcessorArchitecture;
public ushort wReserved;
public uint dwPageSize;
public int lpMinimumApplicationAddress;
public int lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public PROCESSOR_TYPE dwProcessorType;
public uint dwAllocationGranularity;
public ushort wProcessorLevel;
public ushort wProcessorRevision;
}
对 GetSystemInfo 的外部调用是这样的:
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref SYSTEM_INFO SystemInfo);
调用代码是这样的:
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetSystemInfo(ref sysInfo);
运行代码后的输出 SYS_INFO 结构为:
dwActiveProcessorMask 4294901759
dwAllocationGranularity 0
dwNumberOfProcessors 2047
dwPageSize 4096
dwProcessorType 15
lpMaximumApplicationAddress 0
lpMinimumApplicationAddress 65536
wProcessorArchitecture 9
wProcessorLevel 4
wProcessorRevision 0
wReserved 0
有什么我缺少的想法或有关获取此信息的其他方法的建议(我不想将其硬编码为 64Kb JIC,它在某些时候会更改)?谢谢。
【问题讨论】:
标签: c# .net winapi windows-7 pinvoke