如何获取属于某个进程的打开句柄的计数?

发布于 2024-12-29 03:49:27 字数 244 浏览 6 评论 0原文

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

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

You can use the program Process Explorer to see how many handles running applications have. Is there a way with Delphi code to get this number? I am interested in tracking the number for the application itself; not to find the number of handles used by other applications as Process Explorer is doing.

My intention is for the application to track/detect possible resource leaks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2025-01-05 03:49:27

使用 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;

Use the GetProcessHandleCount function. This API function is in recent versions of Delphi imported by the Winapi.Windows unit (so you can omit the presented one):

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文