how to pass a function as parameter (creating a callback function)

TopCatTom
TopCatTom used Ask the Experts™
on
hi,

I'm new to Powerbuilder Programming, so I come up with a simple question.
How can I pass a function as an argument to another function?

What I want to do is:
I want to get a list of all windows (including dialogs) that are visible on the screen. Therefore I use the API-function
long EnumWindows(long hwnd, long lParam) library 'user32.dll'
To this function I have to provide a callback function (as first parameter) that is called if EnumWindows() finds a window.
It should look somehow like this: EnumWindows(ADDRESS_OF(of_myCallback), 0)

Tom
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AFI

Commented:
Hello.  In PB all functions are recursive, you only have to call the function inside itself.
I made what you are trying.  What I recomend you is to use the following APIs.

Private Function Long GetWindow(long haWnd, long wCmd) Library "user32"
Private Function Long GetWindowTextA (long hWind, ref String lpString, long cch) Library "user32"
Private Function Long GetWindowTextLengthA(long hanWnd) Library "user32"
Private Function Boolean IsWindowVisible (long handWnd) Library "user32"

I you need something else please tell me.
Tom,  It is [still] not possible to do callback functions in Powerbuilder. Here is text directly from Sybase website.

"*If the word "Callback appears as a datatype, it cannot be performed by PowerBuilder. Callback routines are functions that are called from within functions."

Your only option is to find other alternatives similar to what AFI mentioned.

Here is a very useful page to keep as reference for external function calls:

http://my.sybase.com/detail?id=44648

Best Regards,
Rich Bianco

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial