类似的程序比较早的有金 山 游 侠。专门读取游*程序内存数据的。
当然你也可以创建一个内存 钩 子 来实时 监 听 某程序的启动然后去读取它调消汪雀用的内存空间。不过这种方法容易被杀毒软件误认为是威胁软件。
‘获取当前的程序内肆燃和存占用(生成exe后运行):Private Sub Timer1_Timer()
Dim myUsage As Double
myUsage = RamUsage
Label1.Caption = FormatUsage(myUsage) &"K (" &FormatUsage(myUsage / 1024) &" Mb)"
End Sub
Private Function RamUsage(Optional strProcess As String = "") As Double
If strProcess = "" Then strProcess = UCase(App.EXEName) &".EXE" 'Will count the current application as the process if no arguments given
Set objWMIService = GetObject("winmgmts:" &"{impersonationLevel=impersonate}!\裂盯\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='" &strProcess &"'")
For Each objProcess In colProcessList
RamUsage = objProcess.workingSetSize / 1024
Next
End Function
Private Function FormatUsage(tUsage As Double)
If Int(tUsage) = tUsage Then
If tUsage = 0 Then
FormatUsage = 0
Else
FormatUsage = Format(tUsage, "###,###")
End If
Else
FormatUsage = Format(tUsage, "段羡###,###.#")
End If
End Function
Windown Api:LoadLibrary
载入指拿缺定的动态链接库,并将它映射到当前进程使用的地址空间。一旦载入,即可访问库内保存的资源,成功则返回库模块的句柄,零表示失败
FreeLibrary
释放指定的动态链接库
用 LoadLibrary 载入 abc.dll
var
RasLib : THandle
Str:array[0..255] of Char
begin
RasLib := LoadLibrary (PChar(AppPath+'abc.dll'))
try
if RasLib <> 0 then begin
//资源类型为 Bitmap,资源 消枣辩ID 为 1
Bitmap1.Handle:=LoadBitmap(RasLib, MakeIntResource(1))
//资源类型为 icon,资源名称 为 MainIcon
icon1.Handle := LoadIcon(RasLib, 'MainIcon')
岩唯
//资源类型为 String,资源 ID 为 3
if LoadString(RasLib, 3, @Str, sizeof(Str)) <> 0 then
Label1.Caption := StrPas(Str)
//载入任意类型资源
with TResourceStream.Create(RasLib, 资源名称, 资源类型) do begin
try
SaveToFile('d:\.....')
....
SaveToStream(Stream)
finally
Free
end
end
finally
FreeLibrary(RasLib)
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)