我晕!这段代码错在哪里?(关于进程列表)

liang_z 2006-02-25 10:34:32
为什么有时有结果有时没有结果?
界面上只有一个ListBox和一个Button。

use TLHelp32

procedure TForm1.Button1Click(Sender: TObject);
var
lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
begin
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found := Process32First(Hand,lppe);
while found do
begin
ListBox1.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。
found := Process32Next(Hand,lppe);
end;
end;
...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuteant 2006-02-25
  • 打赏
  • 举报
回复
试了一下没有问题啊,每次都可以
StrPas(lppe.szExeFile)是不是改为string(lppe.szExeFile)
liang_z 2006-02-25
  • 打赏
  • 举报
回复
我晕,Sorry,昨天没发现这现有下面这段说明。
The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure. Process32First changes dwSize to the number of bytes written to the structure. This will never be greater than the initial value of
dwSize, but it may be smaller. If the value is smaller, do not rely on the values of any members whose offsets are greater than this value.
liang_z 2006-02-25
  • 打赏
  • 举报
回复
完美解决!
5星上将,果然不一样!
不过为什么要加lppe.dwSize := SizeOf(TProcessEntry32);这一句呢?
aiirii 2006-02-25
  • 打赏
  • 举报
回复

Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

lppe.dwSize := SizeOf(FProcessEntry32);

found := Process32First(Hand,lppe);

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧