Einzelnen Beitrag anzeigen

Benutzerbild von Dani
Dani

Registriert seit: 19. Jan 2003
732 Beiträge
 
Turbo Delphi für Win32
 
#1

Gesendete / Empfangene Bytes einer RAS-PPP Verbindung

  Alt 27. Jul 2003, 15:06
Hi,

Also jeder kennt ja die Anzeige der gesendeten/empfangenen Bytes seiner Internetverbindung:


http://visetoolbox.de.vu/images/konnektschn.jpeg


Weiß jemand, woher dieser Dialog die Werte für die Anzahl der gesendeten/empfangenen Bytes nimmt?

(Speicheradresse? Registry? PPP Treiber? TCP/IP Treiber?)


Herzlichen Dank schonmal fürs lesen!

Ciao,
Dani




Bemerkung:

Bisher habe ich die TDialUP Komponente benutzt um an die gesendeten/empfangenen Bytes zu kommen, den Code verstehe ich aber leider nicht so ganz
Ich häng ihn mal dran...


Das Problem damit ist, dass die Zahlen in Integers gespeichert werden, aber die sind ja relativ begrenzt und den Minusbereich braucht man auch nicht wirklich. Am besten fände ich einen unsigned 64bit Integer, falls es sowas gibt
Leider hilft es nichts, wenn ich innerhalb der Komponente einfach den Variablentyp ändere, der Bereich wird dann schlicht nicht ausgenutzt...

--------

Hier mal der "alte" Code:

Delphi-Quellcode:
....

    property BytesXmit : DWord
      read FStatsXmit;
    property BytesRecv : DWord
      read FStatsRecv;


......



function TDialUp.GetPerfStats : Boolean;
var TempKey : HKey;
    dwType,dwSize,ConnSpd : DWORD ;
    PerfData : PPERF_DATA_BLOCK ;
    PerfObj : PPERF_OBJECT_TYPE ;
    PerfCDef : PPERF_COUNTER_DEFINITION ;
    PerfmCDef : array [1..50] of PPERF_COUNTER_DEFINITION ;
    PerfInst : PPERF_INSTANCE_DEFINITION ;
    PerfCBlk : PPERF_COUNTER_BLOCK ;
    RegBuff,ObjPtr,DefPtr,CountPtr : PChar ;
    ActualSize,DataType : Integer;
    ObjNr,InstNr,CountNr : Integer ;
    DatValue : ^Integer ;
    LoopFlag : Boolean ;

function GetData (ValueName: string; var Info: DWORD): boolean ;
begin
  ValueName:=FDUNAKey+'\'+ValueName ;
  dwSize:=4; // data is four bytes of binary, aka a DWORD
  Result:=RegQueryValueEx(TempKey,PChar(ValueName),nil,@dwType,@Info,@dwSize)=ERROR_SUCCESS;
end;

begin
  Result:=False;
  if Win32Platform=VER_PLATFORM_WIN32s then exit;
  if Win32Platform=VER_PLATFORM_WIN32_WINDOWS then // Win95/98
  begin //
    TempKey:=0;
    Result:=RegOpenKeyEx(HKEY_DYN_DATA,PChar(Reg_PerfStatData),0,KEY_READ,TempKey)=ERROR_SUCCESS;
    if Result then
    begin //
      Result:=GetData(Reg_PerfXmit,fStatsXmitTot);
      if Result then Result:=GetData(Reg_PerfRecv,FStatsRecvTot);
      if Result then Result:=GetData(Reg_PerfConn,ConnSpd);
      RegCloseKey(TempKey);
      if Result then
      begin //
        if FStatsXmitTot<FStatsXmitCon then ResetPerfStats;
        if FStatsRecvTot<FStatsRecvCon then ResetPerfStats;
        FStatsConnSpeed:=ConnSpd;
        FStatsXmit:=FStatsXmitTot-FStatsXmitCon;
        FStatsRecv:=FStatsRecvTot-FStatsRecvCon;
      end;
    end;
  end else
  begin // Win NT
    DataType:=REG_NONE; // Windows NT performance data
    try
      // start with small buffer, it will be increased in size if necessary the
      // first time, to that required for the returned performance data
      if DataSize=0 then DataSize:=TOTALBYTES;
      GetMem(RegBuff,DataSize);
      ActualSize:=DataSize;
      while RegQueryValueEx(HKEY_PERFORMANCE_DATA,PChar(PData_RAS_Total),nil,@DataType,PByte(RegBuff),@ActualSize)=ERROR_MORE_DATA do
      begin //
        FreeMem(RegBuff);
        Inc(DataSize,BYTEINCREMENT); // increase buffers size by 1K
        GetMem(RegBuff,DataSize);
        ActualSize:=DataSize;
      end; //
      // get performance data block
      if ActualSize<100 then Exit; // forget it
      Pointer(PerfData):=RegBuff; // PERF_DATA_BLOCK
      // get performance object type blocks
      if PerfData.NumObjectTypes=0 then Exit; // no objects to process
      ObjPtr:=RegBuff+PerfData.HeaderLength;
      for ObjNr:=1 to PerfData.NumObjectTypes do
      begin
        Application.ProcessMessages;
        Pointer(PerfObj):=ObjPtr; // PERF_OBJECT_TYPE
        // perfobj.ObjectNameTitleIndex // not needed
        DefPtr:=ObjPtr+PerfObj.HeaderLength;
        // get performance counter definitions
        if PerfObj.NumCounters>0 then
        begin
          // read through definitions, really looking for length
          for Countnr:=1 to PerfObj.NumCounters do
          begin //
            Pointer(PerfmcDef[Countnr]):=DefPtr; // keep each definitition
            Pointer(PerfcDef):=DefPtr; // PERF_COUNTER_DEFINITION
            Inc(DefPtr, PerfcDef.ByteLength);
            if CountNr>50 then exit;
            Application.ProcessMessages;
          end;
            // now get counter data, perhaps from multiple instances
            LoopFlag:=True;
            InstNr:=1;
            while LoopFlag do
            begin
              if PerfObj.NumInstances>=1 then
              begin
                Pointer(PerfInst):=DefPtr; // PERF_INSTANCE_DEFINITON
                // Instance Name:=WideCharToString
                //   (PWideChar(defptr+perfinst.nameoffset)));
                Inc(DefPtr,PerfInst.ByteLength);
              end;
              // get counter block, then read actual data values
              Countptr:=DefPtr; // after reading through blocks
              Pointer(PerfCBlk):=CountPtr; // PERF_COUNTER_BLOCK
              // get counter data, currently only doublewords
              for CountNr:=1 to PerfObj.NumCounters do
              begin
                if PerfMCDef[CountNr].CounterNameTitleIndex=Pdata_Bytes_Xmit then
                begin
                  Pointer(DatValue):=CountPtr+PerfMCDef[Countnr].CounterOffset;
                  if DatValue^>FStatsXmit then
                    FStatsXmit:=Datvalue^;
                end;
                if PerfMCDef[CountNr].CounterNameTitleIndex=Pdata_Bytes_Recv then
                begin
                  Pointer(datvalue):=CountPtr +
                  PerfMCDef[Countnr].CounterOffset;
                  if Datvalue^>FStatsRecv then
                    FStatsRecv:=Datvalue^;
                end;
              end;
              Inc(DefPtr, PerfCBlk.ByteLength);
              // check for more instances of these counters
              if PerfObj.NumInstances>=1 then
              begin
                Inc(InstNr);
                if InstNr>PerfObj.NumInstances then LoopFlag:=False;
              end else
              LoopFlag:=False;
            end;
          end;
          ObjPtr:=ObjPtr+PerfObj.TotalByteLength;
        end;
        Result:=True;
      finally
      if RegBuff<>nil then Freemem(RegBuff);
    end;
  end;
end;

procedure TDialUp.ResetPerfStats;
begin
  FStatsXmitCon:=FStatsXmitTot; // tot counters are from IPL
  FStatsRecvCon:=FStatsRecvTot;
  FStatsXmit:=0; // current connection
  FStatsRecv:=0;
end;
Dani H.
At Least I Can Say I Tried
  Mit Zitat antworten Zitat