Link to home
Start Free TrialLog in
Avatar of hshliang
hshliang

asked on

Call Back notification

I want to write a sort of Call Back fucntion to notifiy a caller the progress of the function.

Like:  main(){
          callfunc();

        ???some call back to notify this application about progress???

       }

       int callfunc(){
           while{
           //Do something that takes time
           CallBack function() //to tell appliction it has                                //done one step
           }
        }

This will eventually be use in MFC (Windows 95) application to display the progress bar.

Help is appreciated, but please tell me how to write Call Back function or any other simpler or easier ways.



Thanks a million!
ASKER CERTIFIED SOLUTION
Avatar of Mithander
Mithander

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RONSLOW
RONSLOW

main(){
  callfunc();
}

void callback() {
  ???some call back to notify this application about progress???
}

int callfunc(){
  while{
    //Do something that takes time
    CallBack() //to tell appliction it has
               //done one step
  }
}

If you really want main to get a look-in on every iteration, then I'd suggest putting the loop itself into main and have callfunc do a single iteration only.

In windows things are quite different as it is multi-threaded and you can sent messages etc.  so this sort of thing can be a bit easier.

Avatar of hshliang

ASKER

I have seen passing a function pointer to the loop, but I don't know if that is the best way. (like in Windows CallBack Function). Your first way involves the use of global variables, which may not be a good idea if I port it to C++. the second way related more to time but not percent done. I prefer the first way, but any though of avoiding global variables? As when I port it to a C++ class, it will not work. Thnaks.
have you function return a value (like a bool) rather than setting a global variable.

r you can pass a pointer a function (or variable) to call (or modify) in your function.