Using EnumWindows in 64-bit Delphi application

I am working in Delphi XE3, on a 64-bit Windows 8 machine, building 32-bit and 64-bit applications.

I am using EnumWindows to find out the Windows Handle of a process given its Process ID. The code uses the LPARAM parameter in the call back routine to pass a pointer to a record.

The code I am using has worked fine for a 32-bit build.

It is failing when I compile and run the 64-bit build. The problem occurs because the pointer is not passed correctly, and so the de-reference causes an access violation.



try to change lparam with Pointer:



try to change lparam with Pointer:



... alternatively ... go to this EE question and scroll down (find function FindExeProcess2) where I wrote function using wmi to find process ... similar ... using wmi you can find what you want.



Thanks for the response.

Changing Param to be a pointer makes no difference - the value the function receives when compiled for Win64 is still $FFFF

Your alternative WMI code snippet FindExeProcess2 returns the Process ID, not the Handle to the Main Window - which (in this instance) is what I actually want. I want to be able to post Windows messages to the main window of Process N .. so need to know the Windows Handle of that process's Main Window.

And (while I am interested in a work-around if necessary) this doesn't answer my original question as to why the EnumWindowsProc is being passed $FFFF (65535) instead of correct address of the structure I am passing.
It works under Win32 compilation ... but not Win64. I can't believe I am the only person in the world who uses this function, so I must be doing something wrong, and I'd like to understand what that is ...

Thanks

Jon



Some further information:
It transpires that the value I am expecting to be passed in the Param parameter, is in fact being passed in the Wnd parameter.

The Wnd value is NOT however swapped and sent in the Param parameter .. this is always set to $FFFF

It's almost as though the parameters being passed to the callback routine have slipped along one position ...



I run your code on windows 7/64 bit + XE3 ... and code works ok for both 32 bit and 64 bit app. Strange.
Maybe you can upload here small project .... Maybe I can see more ... (in project settings....)

Share this

Related Posts

There was an error in this gadget