これはC++ソリューションではありませんが、C#で機能するようです。ただし、重要なポイントはAPI構造SYSTEM_INFOとAPI GetNativeSystemInfo()
にあるため、C++に簡単に変換する必要があります。
まず、情報を取得するAPIへの参照
[DllImport("kernel32.dll")]
public static extern void GetNativeSystemInfo
([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);
次に、構造SYSTEM_INFOと_PROCESSOR_INFO_UNION
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal _PROCESSOR_INFO_UNION uProcessorInfo;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public IntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort dwProcessorLevel;
public ushort dwProcessorRevision;
}
[StructLayout(LayoutKind.Explicit)]
public struct _PROCESSOR_INFO_UNION
{
[FieldOffset(0)]
internal uint dwOemId;
[FieldOffset(0)]
internal ushort wProcessorArchitecture;
[FieldOffset(2)]
internal ushort wReserved;
}
ここで、ネイティブAPIを呼び出すコードとメソッドを簡略化する列挙型
public enum ProcessorArchitecture
{
Unknown = 0,
Bit32 = 1,
Bit64 = 2,
Itanium64 = 3
}
static public ProcessorArchitecture ProcessorBits
{
get
{
ProcessorArchitecture pbits = ProcessorArchitecture.Unknown;
SYSTEM_INFO l_System_Info = new SYSTEM_INFO();
GetNativeSystemInfo(ref l_System_Info);
switch (l_System_Info.uProcessorInfo.wProcessorArchitecture)
{
case 9: // PROCESSOR_ARCHITECTURE_AMD64
pbits = ProcessorArchitecture.Bit64;
break;
case 6: // PROCESSOR_ARCHITECTURE_IA64
pbits = ProcessorArchitecture.Itanium64;
break;
case 0: // PROCESSOR_ARCHITECTURE_INTEL
pbits = ProcessorArchitecture.Bit32;
break;
default: // PROCESSOR_ARCHITECTURE_UNKNOWN
pbits = ProcessorArchitecture.Unknown;
break;
}
return pbits;
}
}