How to Implement Runtime Platform and Version Checking
4/19/2010
You can use the Windows Embedded CE GetVersionEx function and the Windows Embedded 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
int iDevice = 0; // Describe the device type.
int rc;
BOOL rb;
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 Embedded 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")))
{ // Windows Mobile Connected 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")))
{ // Devices running Windows Mobile 6 Classic.
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 Embedded 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
Reference
Conditional Compilation
Runtime Platform and Version Checking