Board index » delphi » Error code 87 after Process32First

Error code 87 after Process32First

When I move mouse over form then Process32First raise Error code 87
(Incorrect parameter ?).
WHY ?
When I have mouse cursor over Memo, button then it works fine.

...
Var  Lst:TStrings;
...
Lst:=TStrinList.Create:
...
//This function is called by Timer.OnTimer (Interval=5000)
Function GetProcList:TStrings;
var
  Snapshot: THandle;
  ProcessEntry: TProcessEntry32;
begin
  Lst:=TStringList.Create;
  Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if Snapshot = THandle(-1) then RaiseLastWin32Error;
  Process32First(Snapshot, ProcessEntry);
  if GetLastError <> 0 then RaiseLastWin32Error;
   // Raised code 87
  Lst.Add(ProcessEntry.szExeFile);
  CloseHandle(Snapshot);
  Result:=Lst;
end;

 

Re:Error code 87 after Process32First


I think it should be:

if not Process32First(Snapshot, @ProcessEntry) then
  RaiseLastWin32Error;

"Wysky" <wy...@centrum.cz> schreef in bericht
news:9ieape$1su9$1@news.vol.cz...

Quote
> When I move mouse over form then Process32First raise Error code 87
> (Incorrect parameter ?).
> WHY ?
> When I have mouse cursor over Memo, button then it works fine.

> ...
> Var  Lst:TStrings;
> ...
> Lst:=TStrinList.Create:
> ...
> file://This function is called by Timer.OnTimer (Interval=5000)
> Function GetProcList:TStrings;
> var
>   Snapshot: THandle;
>   ProcessEntry: TProcessEntry32;
> begin
>   Lst:=TStringList.Create;
>   Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
>   if Snapshot = THandle(-1) then RaiseLastWin32Error;
>   Process32First(Snapshot, ProcessEntry);
>   if GetLastError <> 0 then RaiseLastWin32Error;
>    // Raised code 87
>   Lst.Add(ProcessEntry.szExeFile);
>   CloseHandle(Snapshot);
>   Result:=Lst;
> end;

Re:Error code 87 after Process32First


No, this isn't solution
I try search where is problem and found this:

...
var
  Snapshot: THandle;
  ProcessEntry: TProcessEntry32;
begin
  memo1.Clear;
  Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if Snapshot = THandle(-1) then
    RaiseLastWin32Error;
  try
    if Process32First(Snapshot, ProcessEntry) then
    repeat
      memo1.Lines.Add(ProcessEntry.szExeFile);
    until not Process32Next(Snapshot, ProcessEntry);
  finally
    CloseHandle(Snapshot);
  end;
...

this is functionaly when I write it direct to OnTimer event, but ISN'T
functionaly if try to make Procedure and call it from OnTimer event.
WHY ? Where is Error ?

"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> p1e v diskusnm p?spvku
news:9iechd$732$1@scavenger.euro.net...

Quote
> I think it should be:

> if not Process32First(Snapshot, @ProcessEntry) then
>   RaiseLastWin32Error;

> "Wysky" <wy...@centrum.cz> schreef in bericht
> news:9ieape$1su9$1@news.vol.cz...
> > When I move mouse over form then Process32First raise Error code 87
> > (Incorrect parameter ?).
> > WHY ?
> > When I have mouse cursor over Memo, button then it works fine.

> > ...
> > Var  Lst:TStrings;
> > ...
> > Lst:=TStrinList.Create:
> > ...
> > file://This function is called by Timer.OnTimer (Interval=5000)
> > Function GetProcList:TStrings;
> > var
> >   Snapshot: THandle;
> >   ProcessEntry: TProcessEntry32;
> > begin
> >   Lst:=TStringList.Create;
> >   Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
> >   if Snapshot = THandle(-1) then RaiseLastWin32Error;
> >   Process32First(Snapshot, ProcessEntry);
> >   if GetLastError <> 0 then RaiseLastWin32Error;
> >    // Raised code 87
> >   Lst.Add(ProcessEntry.szExeFile);
> >   CloseHandle(Snapshot);
> >   Result:=Lst;
> > end;

Other Threads