下面是我写的得到CPU占用率的动态链接库, 用的是系统注册表的方法,
要得到网络数据是一样的, 你可以读一下HKEY_DYN_DATA中相应的键值.
library Cpuusg;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Windows,
Registry,
Classes;
function _Cpu: integer;
var
Reg: TRegistry;
usage: integer;
begin
Reg := TRegistry.Create;
Reg.RootKey:= HKEY_DYN_DATA;
Reg.OpenKey('PerfStats/StatData', false);
Reg.ReadBinaryData('KERNEL/CPUUsage', usage, sizeof(usage));
Reg.CloseKey;
Reg.Free;
Result := usage;
end;
procedure _BeginMonite;
var
Reg: TRegistry;
usage: integer;
begin
Reg := TRegistry.Create;
Reg.RootKey:= HKEY_DYN_DATA;
Reg.OpenKey('PerfStats/StartStat', false);
Reg.ReadBinaryData('KERNEL/CPUUsage', usage, sizeof(usage));
Reg.CloseKey;
Reg.Free;
end;
procedure _EndMonite;
var
Reg: TRegistry;
usage: integer;
begin
Reg := TRegistry.Create;
Reg.RootKey:= HKEY_DYN_DATA;
Reg.OpenKey('PerfStats/StopStat', false);
Reg.ReadBinaryData('KERNEL/CPUUsage', usage, sizeof(usage));
Reg.CloseKey;
Reg.Free;
end;
exports
_Cpu index 1,
_BeginMonite index 2,
_EndMonite index 3;
begin
end.