高手请关注,一个简单的问题!(100分)

  • 主题发起人 主题发起人 hbgywx
  • 开始时间 开始时间
H

hbgywx

Unregistered / Unconfirmed
GUEST, unregistred user!
在win98中,用ras拨号方式拨号成功后,用什么函数得到 :接受字节数、发送字节数、和当时
的bps速率?怎样实现?
 
难道没人回答么?
 
直接读注册表
// Keys and names for Win9x performance statistics under HKEY_DYN_DATA
const AnsiString Reg_PerfStatStart = "PerfStats//StartStat";
const AnsiString Reg_PerfStatData = "PerfStats//StatData";
const AnsiString Reg_PerfStatStop = "PerfStats//StopStat";
const AnsiString Reg_PerfAdap = "Dial-Up Adapter";
const AnsiString Reg_PerfXmit = "TotalBytesXmit";
const AnsiString Reg_PerfRecv = "TotalBytesRecvd";
const AnsiString Reg_PerfConn = "ConnectSpeed";

说来话长,有一个控件RasComp32.pas对这个问题进行详细的说明,并提供代码。可
以找来看看。
 
请问各位高手:用RasGetEntryProperties(API)函数怎么样?但是参数很多,参数总是配不对
总出现:87(参数无效)或1784类的信息.
 
TO:BCB_FANS
我回去是了一下,用modem拨号成功后,注册表中数据确实在变化,我用reg.ReadBinaryData()
函数得到的值怎能转换成十进制数据,成功后定给分.
 
DWORD FBytesXmitTot;

bool Result = GetData(TempKey,FKeyDUNXmitStr, &FBytesXmitTot) ;

------------

// W9X only
//GetData
bool __fastcall GetData(HKEY TempKey,AnsiString ValueName,unsigned long* Info)
{
DWORD Ret;
DWORD dwType,dwSize;

ValueName=FKeyDUNAdapStr + "//" + ValueName ;

//Data is four bytes of binary, aka a DWORD
dwSize=4;
Ret=RegQueryValueEx(TempKey, AnsiString(ValueName).c_str(), NULL,
&dwType, (unsigned char*)Info, &dwSize);
if(Ret!=ERROR_SUCCESS)
{
FLastStatus = SysErrorMessage(Ret);
return false;
}
return true;
}

 
TO:BCB_FANS
我写了下面代码总是调用不成功,麻烦看看那错了:
procedure TForm1.Button2Click(Sender: TObject);
var
Ret,dwType,dwSize: DWORD ;
ldata:Dword;
begin
dwSize:=4;
ret:= RegQueryValueEx(HKEY_DYN_DATA,AnsiString('PerfStats/StatData/Dial-Up Adapter/TotalBytesRecvd'),nil,@dwtyPe,@ldata,@dwSize);
if ret=ERROR_SUCCESS then
showmessage('SUCCESSED');
end;
 
看看API帮助。
LONG RegQueryValue(......)
hKey

Identifies a currently open key or any of the following predefined reserved
handle values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS

预置键值列表没有HKEY_DYN_DATA,所以看来只能先用RegOpenKey打开它,再读取。
------------------------------------------------------------------------
干脆我把全部代码都贴给你吧。

bool __fastcall GetStat()
{
DWORD Ret;
HKEY TempKey=0;

if(FOSVersion==OS_W9X) // Win95/Win98
{
Ret=RegOpenKeyEx(HKEY_DYN_DATA, Reg_PerfStatData.c_str(),0, KEY_READ, &TempKey);
if(Ret!=ERROR_SUCCESS)
{
RegCloseKey(TempKey);
FLastStatus=SysErrorMessage(Ret);
return false;
}
bool Result=GetData(TempKey,FKeyDUNXmitStr, &FBytesXmitTot) ;
if(Result) Result=GetData(TempKey,FKeyDUNRecvStr, &FBytesRecvTot) ;

if(Result)
{
FBytesXmitCur=FBytesXmitTot - FBytesXmitCon ;
FBytesRecvCur=FBytesRecvTot - FBytesRecvCon ;
}
else return false;
}
else if(FOSVersion==OS_NT4) // Windows NT4.0
{
// Get Xmit and Recv bytes by reading registry.
PERF_DATA_BLOCK* DataBlock=NULL;
PERF_OBJECT_TYPE* ObjType;
PERF_COUNTER_DEFINITION* CounterDef,CurCounterDef;
PERF_INSTANCE_DEFINITION* InstDef;
PERF_COUNTER_BLOCK* CounterBlock;
PERF_COUNTER_DEFINITION **CounterDefArray=NULL;
PBYTE ObjOffset,CounterDefOffset,CounterBlockOffset;
unsigned long* DataValue;
DWORD BufSize=TOTALBYTES;

DataBlock=(PERF_DATA_BLOCK*)malloc(BufSize);
while(RegQueryValueEx(HKEY_PERFORMANCE_DATA,PData_Ras_Total.c_str(),
NULL,NULL,(PBYTE)DataBlock,&BufSize)==ERROR_MORE_DATA)
{
BufSize+=BYTEINCREMENT;
free(DataBlock);
DataBlock=(PERF_DATA_BLOCK*)malloc(BufSize);
}
if(DataBlock->NumObjectTypes==0) return false;

// Process all objects
ObjOffset=(PBYTE)DataBlock + DataBlock->HeaderLength;
for(DWORD NumObj=0; NumObj < DataBlock->NumObjectTypes ; NumObj++)
{
Application->ProcessMessages();

ObjType=(PERF_OBJECT_TYPE*)ObjOffset;
CounterDefOffset=ObjOffset+ObjType->HeaderLength;

if(ObjType->NumCounters > 0)
{
CounterDefArray=new PERF_COUNTER_DEFINITION*[ObjType->NumCounters];

for(DWORD NumCounter=0; NumCounter < ObjType->NumCounters; NumCounter++)
{
Application->ProcessMessages();

CounterDefArray[NumCounter]=(PERF_COUNTER_DEFINITION*)CounterDefOffset;
CounterDefOffset+=CounterDefArray[NumCounter]->ByteLength;
}
bool LoopFlag=true;
int NumInst=1;

while(LoopFlag)
{
if(ObjType->NumInstances > 0)
{
InstDef=(PERF_INSTANCE_DEFINITION*)CounterDefOffset;
CounterDefOffset+=InstDef->ByteLength;
}

CounterBlockOffset=CounterDefOffset;
CounterBlock=(PERF_COUNTER_BLOCK*)CounterBlockOffset;

for(DWORD NumCounter=0; NumCounter < ObjType->NumCounters; NumCounter++)
{
if(CounterDefArray[NumCounter]->CounterNameTitleIndex==PData_Bytes_Xmit)
{
DataValue=(unsigned long*)(CounterBlockOffset+CounterDefArray[NumCounter]->CounterOffset);
if(*DataValue>FBytesXmitCur) FBytesXmitCur=*DataValue;
}
if(CounterDefArray[NumCounter]->CounterNameTitleIndex==PData_Bytes_Recv)
{
DataValue=(unsigned long*)(CounterBlockOffset+CounterDefArray[NumCounter]->CounterOffset);
if(*DataValue>FBytesRecvCur) FBytesRecvCur=*DataValue;
}
}

CounterDefOffset+=CounterBlock->ByteLength;
// Check for more instances of these counters
if(ObjType->NumInstances>0)
{
NumInst++;
if(NumInst>ObjType->NumInstances) LoopFlag=false;
}
else LoopFlag=false;
}
delete[] CounterDefArray;
}
// Process next object type
ObjOffset=ObjOffset+ObjType->TotalByteLength;
}
free(DataBlock);
}
else if(FOSVersion==OS_W2K) // Windows 2000( NT5.0 )
{
if(FCurRasConn==NULL) goto ERROR_RES;
if(RasGetConnectionStatisticsProc==NULL) goto ERROR_RES;

// Get current connections statistics data
DWORD Ret;
RAS_STATS RasStats;

RasStats.dwSize=sizeof(RAS_STATS);
Ret=RasGetConnectionStatisticsProc(FCurRasConn,&RasStats);
if(Ret!=0)
{
char ErrBuf[256];

RasGetErrorString(Ret,ErrBuf,256);
FLastStatus=AnsiString(ErrBuf);
goto ERROR_RES;
}
FBytesXmitCur=RasStats.dwBytesXmited;
FBytesRecvCur=RasStats.dwBytesRcved;
//FConnectSpeed=RasStats.dwBps*1000; // Old unit is Kbps, convert it to bps.
return true;

ERROR_RES:
FBytesXmitCur=MAXINT;
FBytesRecvCur=MAXINT;
return false;
}

return true;
}
//---------------------------------------------------------------------------

 
这个问题我已经解了,多谢了!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部