Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help:CallBack function

Help:CallBack function

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutoriallearning
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    curiosity5374
    wrote on last edited by
    #1

    What is the CallBack function? How to use a CallBack function? When to use? Can someone help me? I am a beginner. curiosity

    J 1 Reply Last reply
    0
    • C curiosity5374

      What is the CallBack function? How to use a CallBack function? When to use? Can someone help me? I am a beginner. curiosity

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      curiosity5374 wrote: What is the CallBack function? A user supplied function. (Example: WndProc) curiosity5374 wrote: How to use a CallBack function? A callback (function pointer) is usualy passed as an argument to anouther function, so that it can be called back to process some of the information required for that function. Examples: 1) qsort(elem1,elem2,compare) where compare is the callback function. 2) SetTimer(hWnd,nIDEvent,uElapse,lpTimerFunc) where lpTimerFunc (timer procedure) is the callback function. curiosity5374 wrote: When to use? When a function you are calling requires it, or when a structure (or class) requires it as a member variable (normaly passed as argument to some other function). INTP

      M 1 Reply Last reply
      0
      • J John R Shaw

        curiosity5374 wrote: What is the CallBack function? A user supplied function. (Example: WndProc) curiosity5374 wrote: How to use a CallBack function? A callback (function pointer) is usualy passed as an argument to anouther function, so that it can be called back to process some of the information required for that function. Examples: 1) qsort(elem1,elem2,compare) where compare is the callback function. 2) SetTimer(hWnd,nIDEvent,uElapse,lpTimerFunc) where lpTimerFunc (timer procedure) is the callback function. curiosity5374 wrote: When to use? When a function you are calling requires it, or when a structure (or class) requires it as a member variable (normaly passed as argument to some other function). INTP

        M Offline
        M Offline
        Member 421025
        wrote on last edited by
        #3

        Nice answer but I would like to add something to 'when to use' Callback function is used to get events without having to keep on polling them or keep waiting for them in a loop For example lpTimerFunc mentioned above will be called when the time is elapsed,the program need not bother about it in meantime and continue to do other tasks

        B 1 Reply Last reply
        0
        • M Member 421025

          Nice answer but I would like to add something to 'when to use' Callback function is used to get events without having to keep on polling them or keep waiting for them in a loop For example lpTimerFunc mentioned above will be called when the time is elapsed,the program need not bother about it in meantime and continue to do other tasks

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          How about: When your program is written in C instead of C++. In 'C', since you want to allow the 'client' to override some basic functionality, you need to provide a callback - the client provides the pointer to his function that will do the special processing. In 'C++' you can just provide a stub virtual fuction in a base class and the client can create a derived class and override the virtual function to do something special for his purposes. Sounds like a good test question...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups