External function for checking a process

Question:
Our Powerbuilder application launches an external program using the RUN command. We use the Timer Event to keep checkingif the process is running by using theKERNAL32 external function GetModuleHandleA.

However, this function isalways returning ZERO, thus our PB app thinksthe program just launched is NOT running.Can I use GetModuleHandleA for a 32-bit app onNT? Am I doing something wrong? What otherway is there for PowerBuilder to see ifanother process is still running?

Answer:
Under 32-bit Windows, you cannot get a module handle for another process so the method you are using will not work.

A different solution that may solve your problem is to use the FindWindowA function, you can use the same Run command you have now and a similar loop but instead of looking for the Module Handle you can look for the window title.

When you run your process note down the title bar of the window that gets created, then use the FindWindowA function to look for the window, when you can no longer find the window your process will be complete.

The definition for FindWindowA is as follows:

HWND FindWindow( LPCTSTR lpClassName, // pointer to class name LPCTSTR lpWindowName // pointer to window name ); 

If the HWND returned is zero then the window was not found. HWND is a long, LPCTSTR is a string passed by reference. Remember to add the A after the function definition to use the ASCII version of the function. The function is part of the user32.dll package.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: