var
hSnapshot: HWND;
te: THREADENTRY32;
fOk: Boolean;
hThread: THandle;
ctx: _CONTEXT;
begin
Result := True;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID);
if (hSnapshot <> INVALID_HANDLE_VALUE) then
begin
te.dwSize := SizeOf(THREADENTRY32);
fOk := Thread32First(hSnapshot, te);
while fOk do
begin
fOk := Thread32Next(hSnapshot, te);
if (te.th32OwnerProcessID = dwProcessID) then
begin
hThread := OpenThread(THREAD_ALL_ACCESS, FALSE, te.th32ThreadID);
if (hThread <> 0) then
begin
SuspendThread(hThread);
FillChar(ctx, SizeOf(_CONTEXT), #0);
ctx.ContextFlags := CONTEXT_FULL; //CONTEXT_ALL// 这里要设置线程标志为
GetThreadContext (hThread, ctx);
Form1.Caption:=IntToStr(getlasterror);
end;
CloseHandle(hThread);
end;
end;
CloseHandle(hSnapshot);
end;
end;