我正在从 Windows 移动智能设备检索 OEM 编号,并试图弄清楚如何在if
语句中使用返回值。
下面是我用来返回值的代码。我想确保 OEM 编号始终为 86.09.0008,如果不是,我希望它告诉我。
class oem
{
const string OEM_VERSION = "OEMVersion";
private const int SPI_GETOEMINFO = 258;
private const int MAX_OEM_NAME_LENGTH = 128;
private const int WCHAR_SIZE = 2;
[DllImport("coreDLL.dll")]
public static extern int SystemParametersInfo(int uiAction, int uiParam, string pBuf, int fWinIni);
[DllImport("CAD.dll")]
public static extern int CAD_GetOemVersionNumber(ref System.UInt16 lpwMajor, ref System.UInt16 lpwMinor);
public string getOEMVersion()
{
System.UInt16 nMajor = 0;
System.UInt16 nMinor = 0;
uint nBuild = 0;
int status = CAD_GetOemVersionNumber(ref nMajor, ref nMinor);
if (((System.Convert.ToBoolean(status))))
{
string sMajor = String.Format("{0:00}", nMajor); //in 2-digits
string sMinor = String.Format("{0:00}", nMinor); //in 2-digits
string sBuild = String.Format("{0:0000}", nBuild); //in 4-digits
return (sMajor + "." + sMinor + "." + sBuild);
}
else // failed
{
return ("00.00.0000");
}
我从我的主要表单中调用它,如下所示:
label1.Text = oemver.getOEMVersion();