delphi - 为什么 EnumProcesses 中的参数 aProcesses 设置为 1024?

标签 delphi process window

我使用 EnumProcesses 来获取进程,我只是发现所有示例设置 aProcesses 等于 1024 或 1024*2

[delphi]代码如下:

uses PsAPI;

var
  cbNeeded : DWORD;
  aProcesses : array[0..1024] of DWORD;
begin

  EnumProcesses(@aProcesses, sizeof(aProcesses), &cbNeeded);
  //use PID do something

end;

所以我的问题是为什么将 aProcesses 设置为 1024,1024 是最大进程数?

最佳答案

假设 PsAPI 使用同名的 Win32 方法(MSDN 中的 EnumProcesses),1024 是尝试使用大于机器上一次运行的进程数的数字。如果您查看链接函数的注释,您会看到它说:

To determine how many processes were enumerated, divide the pBytesReturned value by sizeof(DWORD). There is no indication given when the buffer is too small to store all process identifiers. Therefore, if pBytesReturned equals cb, consider retrying the call with a larger array.

关于delphi - 为什么 EnumProcesses 中的参数 aProcesses 设置为 1024?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13874298/

相关文章:

windows - 如何在Windows进程之间传输敏感数据?

c - 通过杀死其父进程而成为孤儿的子进程不会被 init 收养。我该如何解决?

ios - 从 Windows 启用 iPhone(带有 iOS7)调试控制台

delphi - 获取当前时间毫秒

Delphi:TRichEdit 非默认非 Unicode 系统语言中的文本作为字符串 (ANSI)

c - 使用 execv 时并行处理不起作用

javascript - 在 JavaScript 中单击浏览器窗口或选项卡关闭时如何实现注销功能?

c# - Delphi 到 .NET + C#

multithreading - 如何安全地检查另一个线程的主线程标志?

c# - 需要增加窗口服务超时