Error con el api GetVersionEx

Agonzalez
07 de Septiembre del 2004
Tengo implementada la api GetVersionEx en delphi y me funciona sin problemas, pero en VB no me detecta el sistema operativo XP, ¿si es la misma api y la misma estructura de la funcion por que no funciona igual?, ¿Alguian sabe como detecto sistema operativo XP?

Gracias

Este es el codigo en VB

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

Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Enum TipoSO
cOsUnknown = 1
cOsWin95 = 2
cOsWin98 = 3
cOsWin98SE = 4
cOsWinME = 5
cOsWinNT = 6
cOsWin2000 = 7
cOsWinXP = 8
End Enum

Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type

Public Function SistemaOperativo() As String
Dim osVersion As OSVERSIONINFO
Dim Major As Integer
Dim Minor As Integer
Dim Version As Integer
osVersion.dwOSVersionInfoSize = MAX_LENGTH
If (GetVersionEx(osVersion)) Then
Major = osVersion.dwMajorVersion
Minor = osVersion.dwMinorVersion
Select Case osVersion.dwPlatformId
Case VER_PLATFORM_WIN32_NT 'Windows NT/2000/XP
If (Major <= 4) Then
Version = cOsWinNT
Else
If (Major = 5) And (Minor = 0) Then
Version = cOsWin2000
Else
If (Major = 5) And (Minor = 1) Then
Version = cOsWinXP
Else
Version = cOsUnknown
End If
End If
End If
Case VER_PLATFORM_WIN32_WINDOWS 'Windows 9x/ME
If (Major = 4) And (Minor = 0) Then
Version = cOsWin95
Else
If (Major = 4) And (Minor = 10) Then
If (Mid(osVersion.szCSDVersion, 1, 1) = "A") Then
Version = cOsWin98SE
Else
Version = cOsWin98
End If
Else
If (Major = 4) And (Minor = 90) Then
Version = cOsWinME
Else
Version = cOsUnknown
End If
End If
End If
Case Else
Version = cOsUnknown
End Select
Else
Version = cOsUnknown
End If

Select Case Version
Case cOsUnknown
SistemaOperativo = "(sistema no reconocido)"
Case cOsWin95
SistemaOperativo = "Microsoft Windows 95"
Case cOsWin98
SistemaOperativo = "Microsoft Windows 98"
Case cOsWin98SE
SistemaOperativo = "Microsoft Windows 98 Second Edition"
Case cOsWinME
SistemaOperativo = "Microsoft Windows Millennium Edition"
Case cOsWinNT
SistemaOperativo = "Microsoft Windows NT"
Case cOsWin2000
SistemaOperativo = "Microsoft Windows 2000"
Case cOsWinXP
SistemaOperativo = "Microsoft Windows XP"
Case Else
SistemaOperativo = "Microsoft Windows"
End Select
End Function

y este es mi codigo en delphi

function Tlog.FNombreSO:String;
const
cOsUnknown=1;
cOsWin95=2;
cOsWin98=3;
cOsWin98SE=4;
cOsWinME=5;
cOsWinNT=6;
cOsWin2000=7;
cOsWinXP=8;
var
LosVersion : TOSVersionInfo;
Lmajor,
Lminor,
LVersion: Integer;
begin
LosVersion.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );
if ( GetVersionEx( LosVersion ) ) then
begin
Lmajor := LosVersion.dwMajorVersion;
Lminor := LosVersion.dwMinorVersion;
case ( LosVersion.dwPlatformId ) of
VER_PLATFORM_WIN32_NT : { Windows NT/2000/XP }
begin
if (Lmajor<=4) then
LVersion:=cOsWinNT
else
if ((Lmajor=5) and (Lminor=0)) then
LVersion:=cOsWin2000
else
if ((Lmajor = 5) and (Lminor=1)) then
LVersion := cOsWinXP
else
LVersion:=cOsUnknown;
end;
VER_PLATFORM_WIN32_WINDOWS : { Windows 9x/ME }
begin
if ((Lmajor=4) and (Lminor=0)) then
LVersion:= cOsWin95
else
if ((Lmajor=4) and (Lminor=10)) then
begin
if (LosVersion.szCSDVersion[1]='A') then
lVersion:=cOsWin98SE
else
LVersion:=cOsWin98;
end
else
if ((Lmajor = 4) and (Lminor = 90)) then
LVersion := cOsWinME
else
LVersion := cOsUnknown;
end;
else//case
LVersion:=cOsUnknown;
end; // Final del Case
end
else
lVersion:=cOsUnknown; //Final del if

if ( lVersion=cOsUnknown ) then
Result := '(sistema no reconocido)'
else if ( lVersion = cOsWin95 ) then
Result := 'Microsoft Windows 95'
else if ( lVersion = cOsWin98 ) then
Result := 'Microsoft Windows 98'
else if ( lVersion = cOsWin98SE ) then
Result := 'Microsoft Windows 98 Second Edition'
else if ( lVersion = cOsWinME ) then
Result := 'Microsoft Windows Millennium Edition'
else if ( lVersion = cOsWinNT ) then
Result := 'Microsoft Windows NT'
else if ( lVersion = cOsWin2000 ) then
Result := 'Microsoft Windows 2000'
else if ( lVersion = cOsWinXP ) then
Result := 'Microsoft Windows XP'
else
Result := 'Microsoft Windows';
Result:= Result;
end;