
GetVersionEX call fails from VB5
Quote:
>PS. Can anyone help me with this code, it is not giving the expected
>results. I want the version string to say "Win98 4.10.1650" but instead I
>get some *REALLY* long number (see code/picture for details).
>== Begin code ==
>Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef
>lpVersionInformation As OSVERSIONINFO) As Long
>Dim rc as long
>Dim lpVersionInfo as OSVERSIONINFO
>lpVersionInfo.dwOSVersionSize=Len(lpVersionInfo)
>rc=GetVersionEx(lpVersionInfo)
>lblPlatform.Caption = lpVersionInfo.dwMajorVersion & "." &
>lpVersionInfo.dwMinorVersion & "." & lpVersionInfo.dwBuildNumber
>The version no. as you would see is 4.10.[some long number]. The 4.10 part
>is understandable as I'm running Win98 but I only want to display the
>version of Windows the person is running. How can I do this???
>OK, I seem to have gotten a workaround by using szCSDVersion instead of
>dwBuildNumber. But it may change in the future...
I think the documentation for OSVERSIONINFO would help explain what
happened here and how to fix it. Note the description of dwBuildNumber
for Win95, which undoubtedly applies to Win98 also.
Oh, not to be too nitpicky <g>, but from the point of view of a
Windows C/C++ programmer, the variable name "lpVersionInfo" is a bit
confusing. Traditionally, the "lp" prefix is used to indicate that the
variable is a pointer to the data, not the data itself. So a C/C++
Windows programmer coding in VB would probably name the variable like
this:
Dim VersionInfo as OSVERSIONINFO
i.e. without the "lp" prefix. Or maybe just:
Dim vi as OSVERSIONINFO
to save some typing. Anything but that "lp" prefix... <g>
Anyway, it's your code, not mine, so feel free to disregard this
unrequested advice... <g>
And now for the OSVERSIONINFO documentation:
OSVERSIONINFO
The OSVERSIONINFO data structure contains operating system version
information. The information includes major and minor version numbers,
a build number, a platform identifier, and descriptive text about the
operating system. This structure is used with the GetVersionEx
function.
typedef struct _OSVERSIONINFO{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
Quote:
} OSVERSIONINFO;
Members
dwOSVersionInfoSize
Specifies the size, in bytes, of this data structure. Set this member
to sizeof(OSVERSIONINFO) before calling the GetVersionEx function.
dwMajorVersion
Identifies the major version number of the operating system. For
example, for Windows NT version 3.51, the major version number is 3;
and for Windows NT version 4.0, the major version number is 4.
dwMinorVersion
Identifies the minor version number of the operating system. For
example, for Windows NT version 3.51, the minor version number is 51;
and for Windows NT version 4.0, the minor version number is 0.
dwBuildNumber
Windows NT: Identifies the build number of the operating system.
Windows 95: Identifies the build number of the operating system in the
low-order word. The high-order word contains the major and minor
version numbers.
dwPlatformId
Identifies the operating system platform. This member can be one of
the following values: Value Platform
VER_PLATFORM_WIN32s Win32s on Windows 3.1.
VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95 or Windows 98.
For Windows 95, dwMinorVersion is 0.
For Windows 98, dwMinorVersion is 10.
VER_PLATFORM_WIN32_NT Win32 on Windows NT.
szCSDVersion
Windows NT: Contains a null-terminated string, such as "Service Pack
3", that indicates the latest Service Pack installed on the system. If
no Service Pack has been installed, the string is empty.
Windows 95: Contains a null-terminated string that provides arbitrary
additional information about the operating system.
QuickInfo
Windows NT: Requires version 3.5 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
Unicode: Defined as Unicode and ANSI structures.
See Also
System Information Overview, System Information Structures,
GetVersionEx
-Mike
To reach me by email, either use the link in my Web site at
www.geary.com, or delete "bitbucket." from my email address.
My apologies for the inconvenience provoked by our friends
the spammers. <sigh>