Chapter 27: Using the Windows Application Programming Interface
955
dwPlatformID is a long integer representing the platform on which the application is running.
The dwPlatformID constants are declared as follows:
Const VER_PLATFORM_WIN32S = 0
Const VER_PLATFORM_WIN32_Windows = 1
Const VER_PLATFORM_WIN32_NT = 2
Chapter27.accdb on the CD-ROM uses the GetVersionEx function to display the current
version of Windows in the system information using the following two functions. One retrieves the
platform number, while the other gets the major and minor versions.
Function GetVersion() As Long
Dim RetVal As Long
Dim VersionNo As OSVERSIONINFO
Dim lngVer As Long
Dim Version As String
VersionNo.dwVersionInfo = 148
RetVal = apiGetVersion(VersionNo)
Version = VersionNo.dwMajorVersion & “.” _
& VersionNo.dwMinorVersion
lngVer = CLng(Version)
GetVersion= lngVer
End Function
The GetPlatform wrapper function calls the same API declaration but uses the values returned
in the OSVERSIONINFO structure to compose a string indicating that the Windows version
installed on the computer.
Function GetPlatform()
Dim RetVal As Long
Dim VersionNo As OSVERSIONINFO
Dim Platform As String
VersionNo.dwVersionInfo = 148
RetVal = apiGetVersion(VersionNo)
Select Case VersionNo.dwPlatformID
Case VER_PLATFORM_WIN32S
Platform = “Windows 3.x”
Case VER_PLATFORM_WIN32_Windows
Platform = “Windows 98 or Lower”
Case VER_PLATFORM_WIN32_NT
Platform = “Windows NT”
Case VER_PLATFORM_WIN32_NT_2
Platform = “Windows XP, Vista, or 7”
Case Else
Platform = “Unknown”
End Select
GetPlatform = Platform
End Function