如何获取操作系统版本?(白拣分)(50分)

  • 主题发起人 主题发起人 cafegowild
  • 开始时间 开始时间
C

cafegowild

Unregistered / Unconfirmed
GUEST, unregistred user!
我通过GetVersionEx()获取系统版本信息,但编译时提示未声明GetVersionEx()。<br>请问在uses子句中加入什么单元即可。<br>不知如下程序是否可行?<br>unit OSVer;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs,单元名;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; OS:TOSVersionInfo;<br><br>implementation<br><br>{$R *.dfm}<br><br>&nbsp;GetVersionEx(OS);<br>&nbsp;ShowMessage(IntToStr(dwOSVersionInfoSize));<br><br>end.
 
在Windows单元,或者用Windows.GetVersionEx,如果还是不行的话自己声明吧:<br>function GetVersionEx; external kernel32 name 'GetVersionExA';
 
有错!但不缺少饮用单元.<br>应为:<br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS);<br>&nbsp; GetVersionEx(OS);<br>&nbsp; ShowMessage(IntToStr(OS.dwOSVersionInfoSize));
 
gyh75:<br>还是不行,编译错误如下:<br>[Error] OSVer.pas(27): Declaration expected but identifier 'OS' found
 
Delphi7.0 下运行通过<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; &nbsp; OS:TOSVersionInfo;<br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; OS.dwOSVersionInfoSize := SizeOf(OS);<br>&nbsp; GetVersionEx(OS);<br>&nbsp; ShowMessage(IntToStr(OS.dwOSVersionInfoSize));<br>end;<br><br>end.<br><br>windows单元<br>&nbsp; _OSVERSIONINFOA = record<br>&nbsp; &nbsp; dwOSVersionInfoSize: DWORD;<br>&nbsp; &nbsp; dwMajorVersion: DWORD;<br>&nbsp; &nbsp; dwMinorVersion: DWORD;<br>&nbsp; &nbsp; dwBuildNumber: DWORD;<br>&nbsp; &nbsp; dwPlatformId: DWORD;<br>&nbsp; &nbsp; szCSDVersion: array[0..127] of AnsiChar; { Maintenance string for PSS usage }<br>&nbsp; end;<br>&nbsp; TOSVersionInfoA = _OSVERSIONINFOA;<br>&nbsp; TOSVersionInfo = TOSVersionInfoA;<br><br>function GetVersionEx; external kernel32 name 'GetVersionExA';
 
后退
顶部