7

您可以使用程序Process Explorer查看正在运行的应用程序有多少句柄。Delphi代码有没有办法得到这个数字?我有兴趣跟踪应用程序本身的号码;不要像 Process Explorer 那样查找其他应用程序使用的句柄数。

我的目的是让应用程序跟踪/检测可能的资源泄漏。

4

1 回答 1

13

使用该GetProcessHandleCount功能。这个 API 函数在最新版本的 Delphi 中由Winapi.Windows单元导入(所以你可以省略给出的那个):

function GetProcessHandleCount(hProcess: THandle; var pdwHandleCount: DWORD): BOOL; stdcall;
  external 'kernel32.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
  HandleCount: DWORD;
begin
  if GetProcessHandleCount(GetCurrentProcess, HandleCount) then
    ShowMessage('Handle count: ' + IntToStr(HandleCount));
end;
于 2012-01-26T13:47:03.553 回答