#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 是否锁定和应用程序签署的证书。