Question

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();
Was it helpful?

Solution

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.

OTHER TIPS

well, just do something like this in you "main" :

string myString = getOEMVersion();
if(myString == "86.09.0009")
{//Whatever you're willing to do
}

If I understood your question, you should do this:

oem someOem = new oem();
if (oem.getOEMVersion() == "86.09.0009") {
     // ok
} else {
     // fail
}

I am not sure what you mean but if I understand you question you want to use the result of the GetOEMVersion method in an ifstatement.

string OEMVersion = getOEMVersion();
if(OEMVersion == "86.09.0009")
{
   // Do something
}
else
{
   // fail
}

You are missing :

[DllImport("CAD.dll")]
public static extern int CAD_GetOemBuildNumber(ref uint lpdwBuild);


int build = CAD_GetOemBuildNumber(ref nBuild);

to get the build.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top