如何检测WinCE运行平台(转)

#define POCKETPCV1        1
#define SMARTPHONEV1      2
#define POCKETPCV2        3
#define SMARTPHONEV2      4

int MyDeviceType()
{
    TCHAR szPlatform[MAX_STRING_BUFFER];
    int iDeviceType=0;
    OSVERSIONINFO osVer;
    GetVersionEx(&osVer);
    if (osVer.dwMajorVersion==3)
    { 
        if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(szPlatform), szPlatform, 0)!=0)
        {
            if (lstrcmp(szPlatform,TEXT("PocketPC"))==0)
                iDeviceType= POCKETPCV1; // runs on Pocket PC 2000 and 2002
            else if (lstrcmp(szPlatform,TEXT("Smartphone"))==0)
                iDeviceType= SMARTPHONEV1; // runs on Smartphone 2002
        }    
        else
        { 
            if (GetLastError()==ERROR_ACCESS_DENIED)    //(5)
                iDeviceType= SMARTPHONEV1;       // is a smartphone:
            // Smartphone creates an access denied error on
            // SystemParametersInfo() 
        }
    }
    else
    {
        if (osVer.dwMajorVersion==4)
        { 
            if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(szPlatform), szPlatform,0)!=0)
            {
                if (lstrcmp(szPlatform,TEXT("PocketPC"))==0)
                    iDeviceType= POCKETPCV2;       // runs on Pocket PC 2003
                else if (lstrcmp(szPlatform,TEXT("Smartphone"))==0)
                    iDeviceType= SMARTPHONEV2;       // runs on Smartphone 2003
            }    
            else
            { 
                if (GetLastError()==ERROR_ACCESS_DENIED) //(5)
                    iDeviceType= SMARTPHONEV2;          // is a smartphone:
                // Smartphone creates an access denied error on
                // SystemParametersInfo() 
            }
        }
    }
    return iDeviceType;
}
在 Smartphone 上,调用“SystemParametersInfo()”可能会因“Access Denied”而失败,这取决于 Smartphone 是否锁定和应用程序签署的证书。因为只有这种平台才会因 Access Denied 而调用失败,所以您也可以用它作为 Smartphone 的标记。
posted @ 2010-01-15 10:56  木瓜脑袋  阅读(518)  评论(0编辑  收藏  举报