If the use of C # to obtain systems related to the environment and properties, this is also a lot of questions on the Internet, but most of the questions are not answered, recently just want to do the relevant things, sorted out, provided to you, I hope to provide you with the reference points:
First you need to define several structures (struct) to facilitate dllimport to be invoked as a return parameter. Here's the code:
CpuInfo.cs
using System;
using System.Configuration;
using System.Runtime.InteropServices;
/**//**
* Layoutkind.automatic: Allows the running state to reorder type members for increased efficiency
* Note: Never use this option to invoke a dynamically linked library function that is not governed.
* layoutkind.explicit: Sorts type members by FieldOffset property for each field
* LayoutKind.Sequential: Sorts the members of a type that appear in the domain of the jurisdictional type definition where they are not governed.
*/
/**////<summary>
///defines the information structure of the CPU
///</summary>
[StructLayout (layoutkind.sequential)]
public struct CpuInfo
... {
/**////<summary>
///OEM ID
///</summary>
public UINT Dwoemid;
/**////<summary>
///Page Size
///</summary>
public UINT dwPageSize;
public UINT lpminimumapplicationaddress;
public UINT lpmaximumapplicationaddress;
public UINT Dwactiveprocessormask;
/**////<summary>
///CPU Number
///</summary>
public UINT Dwnumberofprocessors;
/**////<summary>
///CPU Type
///</summary>
public UINT dwProcessorType;
public UINT Dwallocationgranularity;
/**////<summary>
///CPU Level
///</summary>
public UINT Dwprocessorlevel;
public UINT Dwprocessorrevision;
}
MemoryInfo.cs
using System;
using System.Configuration;
using System.Runtime.InteropServices;
/**//**
* Layoutkind.automatic: Allows the running state to reorder type members for increased efficiency
* Note: Never use this option to invoke a dynamically linked library function that is not governed.
* layoutkind.explicit: Sorts type members by FieldOffset property for each field
* LayoutKind.Sequential: Sorts the members of a type that appear in the domain of the jurisdictional type definition where they are not governed.
*/
/**////<summary>
///defines the information structure of the memory
///</summary>
[StructLayout (layoutkind.sequential)]
public struct Memoryinfo
... {
/**////<summary>
///
///</summary>
public UINT Dwlength;
/**////<summary>
///already used memory
///</summary>
public UINT dwMemoryLoad;
/**////<summary>
///Total Physical memory size
///</summary>
public UINT dwTotalPhys;
/**////<summary>
Available Physical memory size
///</summary>
public UINT dwAvailPhys;
/**////<summary>
///Exchange File Total size
///</summary>
public UINT dwTotalPageFile;
/**////<summary>
///available swap file size
///</summary>
public UINT dwAvailPageFile;
/**////<summary>
///Total virtual memory size
///</summary>
public UINT dwTotalVirtual;
/**////<summary>
///available virtual memory size
///</summary>
public UINT dwAvailVirtual;
}
SystemTimeInfo.cs
using System;
using System.Configuration;
using System.Runtime.InteropServices;
/**//**
* Layoutkind.automatic: Allows the running state to reorder type members for increased efficiency
* Note: Never use this option to invoke a dynamically linked library function that is not governed.
* layoutkind.explicit: Sorts type members by FieldOffset property for each field
* LayoutKind.Sequential: Sorts the members of a type that appear in the domain of the jurisdictional type definition where they are not governed.
*/
/**////<summary>
///The information structure that defines the system time
///</summary>
[StructLayout (layoutkind.sequential)]
public struct Systemtimeinfo
... {
/**////<summary>
///Year
///</summary>
public ushort Wyear;
/**////<summary>
///Month
///</summary>
public ushort Wmonth;
/**////<summary>
///Week
///</summary>
public ushort Wdayofweek;
/**////<summary>
///Day
///</summary>
public ushort Wday;
/**////<summary>
///hours
///</summary>
public ushort Whour;
/**////<summary>
///minutes
///</summary>
public ushort Wminute;
/**////<summary>
///seconds
///</summary>
public ushort Wsecond;
/**////<summary>
///Millisecond
///</summary>
public ushort Wmilliseconds;
}