Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 

CPU Frequenz ermitteln mit CallNTPowerInformation

  Alt 15. Feb 2006, 21:50
Delphi-Quellcode:
{
  Author  : Michael Puff - [url]http://www.michael-puff.de[/url]
  Date    : 2006-02-15
  License : PUBLIC DOMAIN
}


type
  PROCESSOR_POWER_INFORMATION = packed record
    Number: Cardinal;
    MaxMhz: Cardinal;
    CurrentMhz: Cardinal;
    MhzLimit: Cardinal;
    MaxIdleState: Cardinal;
    CurrentIdleState: Cardinal;
  end;
  PPROCESSOR_POWER_INFORMATION = ^PROCESSOR_POWER_INFORMATION;

  TCPUFrequency = packed record
    CurrentMhz: Cardinal;
    MaxMhz: Cardinal;
  end;

function CallNtPowerInformation(InformationLevel: DWORD; InPutBuffer: Pointer; InputBufferSize: ULONG; OutPutBuffer:
  Pointer; OutPutBufferSize: ULONG): DWORD; stdcall; external 'PowrProf.dll';

function GetCPUFrequency(var CPUFrequency: TCPUFrequency): DWORD;
var
  ppi: PROCESSOR_POWER_INFORMATION;
  err: DWORD;
begin
  ZeroMemory(@ppi, sizeof(PROCESSOR_POWER_INFORMATION));
  err := CallNTPowerInformation(11, nil, 0, @ppi, sizeof(PROCESSOR_POWER_INFORMATION));
  if err = 0 then
  begin
    CPUFrequency.CurrentMhz := ppi.CurrentMhz;
    CPUFrequency.MaxMhz := ppi.MaxMhz;
  end;
  result := err;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  CPUFrequency: TCPUFrequency;
  err: DWORD;
  s: String;
begin
  ZeroMemory(@CPUFrequency, sizeof(TCPUFrequency));
  err := GetCPUFrequency(CPUFrequency);
  if err = 0 then
  begin
    s := 'Current frequency: '+IntToStr(CPUFrequency.CurrentMhz)+' MHz'+#13#10;
    s := s + 'Max frequency: '+IntToStr(CPUFrequency.MaxMhz)+' MHz';
    ShowMessage(s);
  end
  else
    ShowMessage(SysErrorMessage(err));
end;
Stichworte: CPU Frequenz, Taktfrequenz

[edit=Chakotay1308]Klassifizierung angepasst/hinzugefügt. Mfg, Chakotay1308[/edit]
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat