初学delphi好高骛远地写了一个终止进程线程的函数……老是异常……用OD调试的时候感觉像是堆栈不平衡,还像是OpenThead引起的,不知道如何解决,望高手指教……
function KillAllThread(ProId:dword):BOOL;
var
hSnapshot:DWORD;
lpte:TThreadEntry32;
fou:bool;
hthread:DWORD;
begin
hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
lpte.dwSize :=SizeOf(TThreadEntry32);
fou:=Thread32First(hSnapshot,lpte);
while fou do begin
if lpte.th32OwnerProcessID = ProId then begin
hthread:=OpenThread($1F0FFF,False,lpte.th32ThreadID);
TerminateThread(hthread,0);
closehandle(hthread);
end;
fou:=Thread32Next(hSnapshot,lpte);
end;
closehandle(hSnapshot);
end;