Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:20:39+00:00 2026-06-15T16:20:39+00:00

I’m, trying to list all running processes on my computer. What is wrong with

  • 0

I’m, trying to list all running processes on my computer.

What is wrong with my EnumWindowsProc() calling statement in my short example code. My compiler claims that, in this line:

EnumWindows(@EnumWindowsProc, ListBox1);

that there needs to be a variable inside the function call. How should I change @EnumWindowsProc to a var ?

unit Unit_process_logger;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, 
  Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }    
  public
    { Public-Deklarationen }
  end;

function EnumWindowsProc(wHandle: HWND; lb: TListBox): Boolean;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function EnumWindowsProc(wHandle: HWND; lb: TListBox): Boolean;
var
  Title, ClassName: array[0..255] of Char;
begin
  GetWindowText(wHandle, Title, 255);
  GetClassName(wHandle, ClassName, 255);
  if IsWindowVisible(wHandle) then
     lb.Items.Add(string(Title) + '-' + string(ClassName));
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ListBox1.Items.Clear;    
  EnumWindows(@EnumWindowsProc, ListBox1);    
end;

end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:20:40+00:00Added an answer on June 15, 2026 at 4:20 pm

    First of all the declaration is wrong. It needs to be stdcall, and it returns BOOL.

    function EnumWindowsProc(wHandle: HWND; lb: TListBox): BOOL; stdcall;
    

    Secondly, your implementation doesn’t set the return value. Return True to continue enumeration, False to stop enumeration. In your case you need to return True.

    Finally, you’ll need to cast the list box to be LPARAM when you call EnumWindows.

    EnumWindows(@EnumWindowsProc , LPARAM(ListBox1));
    

    Consult the documentation for the full details.

    Putting it all together you have this:

    function EnumWindowsProc(wHandle: HWND; lb: TListBox): BOOL; stdcall;
    var
      Title, ClassName: array[0..255] of char;
    begin
      GetWindowText(wHandle, Title, 255);
      GetClassName(wHandle, ClassName, 255);
      if IsWindowVisible(wHandle) then
        lb.Items.Add(string(Title) + '-' + string(ClassName));
      Result := True;
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      ListBox1.Items.Clear;
      EnumWindows(@EnumWindowsProc, LPARAM(ListBox1));
    end;
    

    Note also that EnumWindows does not enumerate all running processes. What it does is enumerate all top level windows. Note quite the same thing. To enumerate all running processes there is EnumProcesses. However, since you are reading out window titles and window class names, you probably do want to use EnumWindows.


    As I’ve said many times before, I loath the fact that the Delphi header translation for EnumWindows uses Pointer for the EnumWindowsProc parameter. Which means that you can’t rely on the compiler to check type safety. I personally always use my own version of EnumWindows.

    type
      TFNWndEnumProc = function(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
    
    function EnumWindows(lpEnumFunc: TFNWndEnumProc; lParam: LPARAM): BOOL;
      stdcall; external  user32;
    

    And then when you call the function you don’t use the @ operator and so let the compiler check that your callback function is declared correctly:

    EnumWindows(EnumWindowsProc, ...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.