Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Feb : Vista issue

www.cryer.info
Managed Newsgroup Archive

Vista issue

Subject:Vista issue
Posted by:"Lance R" (lance @nospam)
Date:Mon, 5 Feb 2007 23:04:26

I'm adding some logic to get particular version of OS.

I am trying to use the new API to get at the edition of Vista.

Below is a modified unit.

When I run in XP or whatever, it works fine.

When I run in Vista, the app crashes.

It must be something to how I'm calling the DLL.

Suggestions??

Lance


========================

unit VistaDetails;

interface

uses
   Windows,ShlObj, SysUtils;

const
   PRODUCT_BUSINESS = $00000006;
   PRODUCT_HOME_BASIC = $00000002;
   PRODUCT_HOME_PREMIUM = $00000003;
   PRODUCT_STARTER = $0000000B;
   PRODUCT_UNDEFINED = $00000000;
   PRODUCT_ULTIMATE = $00000001;
   PRODUCT_UNLICENSED = $ABCDABCD;

var
   _GetProductInfo:   Pointer;

procedure WhichVista;


implementation

procedure GetTheProcedureAddress(var P: Pointer; const ModuleName,
ProcName: string);
var
   ModuleHandle: HMODULE;
begin
   if not Assigned(P) then
   begin
     ModuleHandle := GetModuleHandle(PChar(ModuleName));
     if ModuleHandle = 0 then
     begin
       ModuleHandle := LoadLibrary(PChar(ModuleName));
     end;
     P := Pointer(GetProcAddress(ModuleHandle, PChar(ProcName)));
   end;
end;

function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion,
dwSpMajorVersion, dwSpMinorVersion: DWord;
                           var pdwReturnedProductType: Dword): BOOL;
begin
   GetTheProcedureAddress(_GetProductInfo, 'kernel32.dll',
'GetProductInfo');
   asm
     mov esp, ebp
     pop ebp
     jmp [_GetProductInfo]
   end;
end;

procedure WhichVista;
var
   kOSVersion: TOSVersionInfo;
   dwProduct: Cardinal;
   ProductEdition: Integer;
   MajorPack: word;
   Minorpack: word;
begin
   FillChar(kOSVersion, SizeOf(kOSVersion), 0);
   kOSVersion.dwOSVersionInfoSize := SizeOf(kOSVersion);
   GetVersionEx(kOSVersion);
   if kOSVersion.dwPlatformId = VER_PLATFORM_WIN32_NT then begin
      if (kOSVersion.dwMajorVersion = 6) and (kOSVersion.dwMinorVersion
= 0) then begin
         GetProductInfo(kOSVersion.dwMajorVersion,
kOSVersion.dwMinorVersion, MajorPack{kOSVersion.wServicePackMajor},
Minorpack{kOSVersion.wServicePackMinor}, dwProduct);
         OutputDebugString(pchar('ProductVer' + inttostr(dwProduct)+
CHR(10)));
      end;
   end;
end;

end.

Replies:

www.cryer.info
Managed Newsgroup Archive