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 7595789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:45:32+00:00 2026-05-30T21:45:32+00:00

Using Delphi XE2 update 3 or update 4 on Win7 64 bit. Calling enumwindows

  • 0

Using Delphi XE2 update 3 or update 4 on Win7 64 bit.

Calling enumwindows does not work like it used to work in Delphi 6.

In Delphi 6 enumwindows processed windows until the callback function returned False. That is what the documentation says it should do:

“To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.”

Making a call to enumwindows as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@FindMyWindow,0);
  if GLBWindowHandle <> 0 then begin
    ShowMessage('found');
  end;
end;

Here is the callback function:

function FindMyWindow(hWnd: HWND; lParam: LPARAM): boolean; stdcall;
var TheText : array[0..150] of char;
str : string;
begin
Result := True;
GLBWindowHandle := 0;
if (GetWindowText(hWnd, TheText, 150) <> 0) then
   begin
   str := TheText;
   if str = 'Form1' then
      begin
      GLBWindowHandle := hWnd;
      Result := False;
      end
   else
      result := True;
   end;
end;

Just to be clear the callback function is defined in code BEFORE the buttonclick event so it is found by the compiler without needing to be defined in the interface section.

If this is run using Delphi 6 the enumeration of windows stops once the False result is returned and GLBWindowHandle is not zero

If this is run using Delphi XE2 the enumeration continues after the False result is returned and GLBWindowHandle is always zero.

WTF? Anybody have any ideas why the enumeration is not stopping like the documentation states it should and how it used to in Delphi 6?

Cheers!

  • 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-05-30T21:45:33+00:00Added an answer on May 30, 2026 at 9:45 pm

    This declaration is incorrect:

    function FindMyWindow(hWnd: HWND; lParam: LPARAM): boolean; stdcall;
    

    It should be:

    function FindMyWindow(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
    

    You have to be careful not to mix up Boolean and BOOL since they are not the same thing. The former is a single byte, the latter is 4 bytes. This mismatch between what EnumWindows expects and what your callback function delivers is enough to cause the behaviour you observe.


    In addition, Rob Kennedy contributed this excellent comment:

    The compiler can help find this error if you get out of the habit of using the @ operator before the function name when you call EnumWindows. If the function signature is compatible, the compiler will let you use it without @. Using @ turns it into a generic pointer, and that’s compatible with everything, so the error is masked by unnecessary syntax. In short, using @ to create function pointers should be considered a code smell.


    Discussion

    Unfortunately the Windows.pas header translation defines EnumWindows in a most unhelpful manner, like this:

    function EnumWindows(lpEnumFunc: TFNWndEnumProc; lParam: LPARAM): BOOL; stdcall;
    

    Now, the problem is in the definition of TFNWndEnumProc. It is defined as:

    TFarProc = Pointer;
    TFNWndEnumProc = TFarProc;
    

    This means that you have to use the @ operator to make a generic pointer, because the function needs a generic pointer. If TFNWndEnumProc were declared like this:

    TFNWndEnumProc = function(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
    

    then the compiler would have been able to find the error.

    type
      TFNWndEnumProc = function(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
    
    function EnumWindows(lpEnumFunc: TFNWndEnumProc;
      lParam: LPARAM): BOOL; stdcall; external 'user32';
    
    function FindMyWindow(hWnd: HWND; lParam: LPARAM): Boolean; stdcall;
    begin
      Result := False;
    end;
    
    ....
    EnumWindows(FindMyWindow, 0);
    

    The compiler rejects the call to EnumWindows with the following error:

    [DCC Error] Unit1.pas(38): E2010 Incompatible types: ‘LongBool’ and ‘Boolean’

    I think I will QC this issue and try my luck at persuading Embarcadero to stop using TFarProc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Delphi and need to get the current Windows DNS server IP address
Yesterday I installed Delphi XE2 using the download option, so I guess the installed
I've built a 32-bit dylib for OS X with Delphi XE2 Upd. 3. It's
I am using Delphi XE2 with help installed. I want to see the hints
I am trying to write an iPhone app using Delphi XE2 / FireMonkey and
Using Delphi 2009 on Windows XP to develop desktop application. Is there any way
I am using Delphi 2010 to build a Win32 GUI application running on Windows
I use ActivateKeyboardLayout(HKL_NEXT, KLF_ACTIVATE); to load Persian keyboard layout using Delphi XE2, But sometimes
I'm migrating an old Delphi application (using ZeosDB) to Delphi XE2. I want to
Having trouble with Delphi XE2 (update2) using MS SQL 2008 R2 (sp 2) or

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.