-1

我正在尝试按照GetProductInfo一位高级成员的建议,使用 Delphi XE2 中的功能显示 Vista 及以上操作系统的 Windows 版本和产品详细信息。我已经定义了以下代码,但我无法编译它。我的代码如下:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
type
TGetProductInfoAPI = function(dwOSMajorVersion, dwOSMinorVersion,
dwSpMajorVersion, dwSpMinorVersion: DWORD; pdwReturnedProductType:
PDWORD): BOOL stdcall;
begin
  Edit1.Text:=IntToStr(dwOSMajorVersion);
  Edit2.Text:=IntToStr(dwOSMinorVersion);
  Edit3.Text:=IntToStr(dwSpMajorVersion);
  Edit4.Text:=IntToStr(dwSpMinorVersion);
  Edit5.Text:=TGetProductInfoAPI.pdwReturnedProductType;
end;

end.

我想我在做一些错误,但我找不到它。请告诉我我在哪里犯错。

4

1 回答 1

2

使用这个函数的正确方法kernel32.dll是写

function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion,
  dwSpMinorVersion: DWORD; out pdwReturnedProductType: DWORD): BOOL stdcall;
  external kernel32 delayed;

在某个单元中(在任何过程、类型声明等之外)

例如,

function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion,
  dwSpMinorVersion: DWORD; out pdwReturnedProductType: DWORD): BOOL stdcall;
  external kernel32 delayed;

const
  PRODUCT_HOME_PREMIUM = $00000003;

procedure TForm1.Button1Click(Sender: TObject);
var
  rpt: cardinal;
begin
  if GetProductInfo(6, 1, 0, 0, rpt) then
    if rpt and PRODUCT_HOME_PREMIUM <> 0 then
      ShowMessage('Yeah, you''re running Home Premium.');
end;

如果您只想查看返回值,那么,只需显示它!

procedure TForm1.Button2Click(Sender: TObject);
var
  rpt: cardinal;
begin
  if GetProductInfo(6, 1, 0, 0, rpt) then
    ShowMessage(IntToStr(rpt));
end;

另外,为了清楚起见:这个函数的前四个参数(显然)是用于input,而不是用于output。如果您想获取操作系统的版本,您可以使用或简单地GetVersionEx查看.Win32MajorVersionSysUtils

于 2013-03-26T18:38:42.947 回答