Windows version with getVersionEx and OSVersionEX (WinAPI)

N

Norman Chong

Hi group,

I want to get some information about the Windows version and
ServicePack. I used the WinAPI but got the following problem:
When I try to pass my OSVERSIONINFOEX structure ByRef to the
getVersionEx API-function, the structure remains empty. Shouldn't this
contain the values after the call?? Does anybody know what's wrong in
my code (Or maybe in my way of thinking)??


Private Structure OSVERSIONINFOEX
Dim dwOSVersionInfoSize As Integer
Dim dwMajorVersion As Integer
Dim dwMinorVersion As Integer
Dim dwBuildNumber As Integer
Dim dwPlatformId As Integer
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.By­ValTStr,

SizeConst:=128)> _
Dim szCSDVersion As String
Dim wServicePackMajor As Short
Dim wServicePackMinor As Short
Dim wSuiteMask As Short
Dim wProductType As Byte
Dim wReserved As Byte
End Structure

Private Declare Function GetVersionEx Lib "kernel32" Alias
"GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFOEX) As Long


Private Sub LoadVersionStructure()
Dim test As New OSVERSIONINFOEX
Dim lngResult As Long
test.dwOSVersionInfoSize = Len(test)
lngResult = GetVersionEx(test)
If lngResult = 0 Then
MessageBox.Show("Failed to load version structure.")
End If
End Sub

I don't get an error and getVersionEx doesn't return 0, but like I
wrote, no data in OSVersionEx...
Unfortunately I can't use Environment.OSVersion to get what I need,
because I also need additional information (e.g. Whether it's Home
Edition or not, etc)

Thanx...
 
N

Norman Chong

Ok, someone from another group gave me a good example so I could solve
my problem. Here's the solution / the error in my code (Just in case
that someone has the same problem):

test.dwOSVersionInfoSize = Len(test) must be
test.dwOSVersionInfoSize = Marshal.SizeOf(test)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top