Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can use the Windows CE GetVersionEx function and the Windows CE OSVERSIONINFO structure to implement runtime platform version checking.
Example
// Define the (arbitrary) device type identifiers.
#define DESKTOPID 500
#define SMARTPHONE2003ID 403
#define SMARTPHONE2002ID 402
#define POCKETPC2003ID 303
#define POCKETPC2002ID 302
#define POCKETPC2000ID 300
#define OTHERWINCEID 100
#define UNKNOWNID 0
BOOL rb;
int rc;
int iDevice = 0; // Describe the device type.
OSVERSIONINFO osvi;
TCHAR szPlatform[MAX_PATH];
osvi.dwOSVersionInfoSize = sizeof(osvi);
rb = GetVersionEx(&osvi);
if (rb == FALSE) // GetVersionEx failed.
{
rc = MessageBox(NULL, _T("Could not create main window."),
_T("Error"), MB_OK);
if (rc == 0) // Not enough memory to create MessageBox.
return E_OUTOFMEMORY;
return E_FAIL; // Replace with specific error handling.
}
switch (osvi.dwPlatformId)
{
// A Windows CE platform.
case VER_PLATFORM_WIN32_CE:
// Get platform string.
rb = SystemParametersInfo(SPI_GETPLATFORMTYPE,
MAX_PATH, szPlatform, 0);
if (rb == FALSE) // SystemParametersInfo failed.
{
rc = MessageBox(NULL, _T("Could not create main window."),
_T("Error"), MB_OK);
if (rc == 0) // Not enough memory to create MessageBox.
return E_OUTOFMEMORY;
return E_FAIL; // Replace with specific error handling.
}
else // SystemParametersInfo succeeded.
{
if (0 == lstrcmpi(szPlatform, TEXT("Smartphone")))
{ // Smartphone devices.
if (osvi.dwMajorVersion == 3)
iDevice = SMARTPHONE2002ID;
else if (osvi.dwMajorVersion == 4)
iDevice = SMARTPHONE2003ID;
else // Unknown device.
iDevice = UNKNOWNID;
}
else if (0 == lstrcmp(szPlatform, TEXT("PocketPC")))
{ // Pocket PC devices.
if (osvi.dwMajorVersion == 3)
if (osvi.dwMinorVersion == 0)
iDevice = POCKETPC2000ID;
else if (osvi.dwMinorVersion == 1)
iDevice = POCKETPC2002ID;
else // Unknown device.
iDevice = UNKNOWNID;
else if (osvi.dwMajorVersion == 4)
iDevice = POCKETPC2003ID;
else // Unknown device.
iDevice = UNKNOWNID;
}
else
{ // Some other Windows CE–based device.
iDevice = OTHERWINCEID;
}
} // SystemParametersInfo succeeded.
break;
// A desktop Windows platform.
default:
iDevice = DESKTOPID;
break;
}
Remarks
The OSVERSIONINFO::dwPlatformId structure member identifies the operating system version, which enables you to provide different paths of execution for each version.
See Also
Writing Code for Multiple Devices and Versions | Conditional Compilation | Runtime Platform and Version Checking
Send Feedback on this topic to the authors