CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2002
    Posts
    2

    callback procedure

    What is a callback procedure in C++ terms ? How is it useful ?

  2. #2
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    For a callback, you usually register through a function by passing the function pointer to the funciton you want to be called.

    Thereafter, the callback function is called when it is appropriate.

    See it as an event handler.
    Martin Breton
    3D vision software developer and system integrator.

  3. #3
    Join Date
    Aug 1999
    Posts
    74
    The WIN32 SDK SetTimer() function is a good example.

    Lets say you want to write a program that prints the cricket score every 5 minutes. You have writen a function PrintScore() for it .. but you want it to be called every 5 minutes.

    So you pass your function pointer to SetTimer(). SetTimer() will call PrintScore() every 5 minutes.

    PrintScore() is the call back function.

  4. #4
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715

    call backs

    Call backs are very useful in a method of programming called loose couppleing. This means you can have two classes / functions who's designers might have never known about each other and they can be dynamically configured to call one another without making a programming change. This concept becomes very powerful when used in conjunction with dll's where code can be added to an executeable without being recompiled. Callbacks and loose coupling allows a programmer to literally build building blocks which can be added, subtracted or modified extensively with a minumum of brawn but rather substituting brain.

    Example.....

    Using a transport class one could register variable classes which once modified would automajically transfer and refresh data across a wire. New transfer classes could be added dynamically through a dll interface and be almost limitelessly expandable.

  5. #5
    Join Date
    Apr 2002
    Posts
    19

    another usage..

    they are commonly used for functions which sort something (e.g. qsort of the runtime library..)

    because of the fact, that these functions can't know which of your objects is bigger, you can write a function (return e.g. false for bigger) and then the other function can sort it..

    if you think that this concept is braindead or wrong..
    the whole stl is based on a similar concept.. just that the coupling is very elegantly (and complicated at first)

  6. #6
    Join Date
    Jun 2002
    Posts
    2
    Thank u all for the replies...got it now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured