I am retrieving the OEM number from a Windows mobile smart device, and am trying to figure out how to use a returned value in an if
statement.
Below is the code I use to return the value. I would like to make sure the OEM number is always 86.09.0008 and if it is not i would like it to let me know.
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");
}
I'm calling this from my main form like so:
label1.Text = oemver.getOEMVersion();
if statements require a bool value. In your case you should compare the value you require with the value you obtained
if(status == 86.09.0009)//...
Note the double '==' which is an operator that checks for equality. Contrast this with the single '=' which performs an assignment.
Also note that int
does not allow for decimals. Considering that this number has two decimals I believe you need to get this as a string.