Thema: Delphi Api's von VB auf Delphi

Einzelnen Beitrag anzeigen

magicshadow

Registriert seit: 28. Apr 2003
85 Beiträge
 
#3
  Alt 2. Mai 2003, 20:52
nein, die Deklarationen sind da!
ich poste mal die volständigen quellcodes:
VB:
Code:
Private Declare Function RasGetConnectionStatistics Lib _
        "RasApi32.DLL" (ByVal hRasConn As Long, lpStatistics _
        As RASSTATS2000) As Long
           
Private Declare Function RasEnumConnections Lib "RasApi32.DLL" _
        Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As _
        Long, lpcConnections As Long) As Long
       


Private Type RASSTATS2000
  dwSize As Long
  dwBytesXmited As Long
  dwBytesRcved As Long
  dwFramesXmited As Long
  dwFramesRcved As Long
  dwCrcErr As Long
  dwTimeoutErr As Long
  dwAlignmentErr As Long
  dwHardwareOverrunErr As Long
  dwFramingErr As Long
  dwBufferOverrunErr As Long
  dwCompressionRatioIn As Long
  dwCompressionRatioOut As Long
  dwBps As Long
  dwConnectDuration As Long
End Type

Const RAS_MaxEntryName = 256
Const RAS_MaxDeviceType = 16
Const RAS_MaxDeviceName = 32

Private Type RASType
  dwSize As Long
  hRasCon As Long
  szEntryName(RAS_MaxEntryName) As Byte
  szDeviceType(RAS_MaxDeviceType) As Byte
  szDeviceName(RAS_MaxDeviceName) As Byte
End Type

Private Type RASStatusType
  dwSize As Long
  RasConnState As Long
  dwError As Long
  szDeviceType(RAS_MaxDeviceType) As Byte
  szDeviceName(RAS_MaxDeviceName) As Byte
  szInBytes As Double
  syOutbytes As Double
End Type

Private Sub Timer1_Timer()
  Call ActiveConnection
End Sub

Private Function ActiveConnection() As Boolean
  Dim RAS(255) As RASType, RASStatus As RASStatusType
  Dim lg&, lpcon&, Result&
  Dim myStats As RASSTATS2000
  Dim rtn As Long
    RAS(0).dwSize = 412
    lg = 256 * RAS(0).dwSize
    Result = RasEnumConnections(RAS(0), lg, lpcon)
    myStats.dwSize = LenB(myStats)
    rtn = RasGetConnectionStatistics(RAS(0).hRasCon, myStats)
    ActiveConnection = True
        Form1.Text1 = myStats.dwBytesRcved - Label2.Caption
        Form1.Label2.Caption = myStats.dwBytesRcved
        Form1.Label1.Caption = myStats.dwBytesXmited
End Function
Delphi:
Code:
type
RASSTATS2000 = record
  dwSize:Longint;
  dwBytesXmited:Longint;
  dwBytesRcved:Longint;
  dwFramesXmited:Longint;
  dwFramesRcved:Longint;
  dwCrcErr:Longint;
  dwTimeoutErr:Longint;
  dwAlignmentErr:Longint;
  dwHardwareOverrunErr:Longint;
  dwFramingErr:Longint;
  dwBufferOverrunErr:Longint;
  dwCompressionRatioIn:Longint;
  dwCompressionRatioOut:Longint;
  dwBps:Longint;
  dwConnectDuration:Longint;
End;

RASType = record
  dwSize:Longint;
  hRasCon:Longint;
  szEntryName:array[0..256] of Byte;
  szDeviceType:array[0..16] of Byte;
  szDeviceName:array[0..32] of Byte;
End;

RASStatusType = record
  dwSize:Longint;
  RasConnState:Longint;
  dwError:Longint;
  szDeviceType:array[0..16] of byte;
  szDeviceName:array[0..32] of Byte;
  szInBytes:Double;
  syOutbytes:Double
End;

Const RAS_MaxEntryName = 256;
      RAS_MaxDeviceType = 16;
      RAS_MaxDeviceName = 32;

{$R *.DFM}
Function RasGetConnectionStatistics(hRasConn:Longint;
         var lpStatistics:RASSTATS2000):longint; stdcall; external 'RasApi32.DLL'

Function RasEnumConnectionsA(lpRasCon:RASType; lpcb:Longint;
         lpcConnections:Longint):longint; stdcall; external 'RasApi32.DLL'

procedure TForm1.Timer1Timer(Sender: TObject);
var RAS:array[0..255] of RASType;
    RASStatus:RASStatusType;
    lg,lpcon,Result:longint;
    myStats:RASSTATS2000;
    rtn:Longint;
    tmp:longint;
begin
     lpcon:=0;
     lg:=0;
     RAS[0].dwSize:= 412;
     lg:= 256 * RAS[0].dwSize;
     tmp:= RasEnumConnectionsA(RAS[0], lg, lpcon);
     showmessage(inttostr(lpcon));
     myStats.dwSize:= SizeOf(myStats);
     rtn:= RasGetConnectionStatistics(RAS[0].hRasCon, myStats);
     edit1.text:=inttostr(myStats.dwBytesXmited);
     edit2.text:=inttostr(mystats.dwBytesRcved);
end;
  Mit Zitat antworten Zitat