GetSystemInfo总是从Win Service上的Win7上的dwAllocationGranularity返回0

1 .net c# pinvoke winapi windows-7

我试图从Windows 7上的C#3.5 Windows服务应用程序使用GetSystemInfo()获取分配粒度大小.但是当从调用返回时,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;
}
Run Code Online (Sandbox Code Playgroud)

对GetSystemInfo的extern调用是这样的:

[DllImport("kernel32")]
public static extern void GetSystemInfo(ref SYSTEM_INFO SystemInfo); 
Run Code Online (Sandbox Code Playgroud)

调用代码是这样的:

SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetSystemInfo(ref sysInfo);
Run Code Online (Sandbox Code Playgroud)

运行代码后的输出SYS_INFO结构是:

dwActiveProcessorMask        4294901759
dwAllocationGranularity      0
dwNumberOfProcessors         2047
dwPageSize                   4096
dwProcessorType              15
lpMaximumApplicationAddress  0
lpMinimumApplicationAddress  65536
wProcessorArchitecture       9
wProcessorLevel              4
wProcessorRevision           0
wReserved                    0
Run Code Online (Sandbox Code Playgroud)

任何想法我缺少什么或建议其他方式获取此信息(我不想硬编码到64Kb JIC它在某些时候改变)?谢谢.

Han*_*ant 7

你也没有2047处理器:)声明是错误的,它将在64位模式下失败.lpMin/MaxApplicationAddress和dwActiveProcessorMask是IntPtr.