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. Callback functions

Callback functions

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++delphi
7 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.
  • J Offline
    J Offline
    Jake Palmer
    wrote on last edited by
    #1

    I'm trying to use the function AVISave, which takes as a parameter a callback function: AVISAVECALLBACK lpfnCallback with the prototype: LONG PASCAL SaveCallback(int nPercent) When it comes to passing a function to another function, we leave the realm of any C++ that I understand. How do I call AVISave? And, where does the "Pascal" come from? thanks, Jake

    A 1 Reply Last reply
    0
    • J Jake Palmer

      I'm trying to use the function AVISave, which takes as a parameter a callback function: AVISAVECALLBACK lpfnCallback with the prototype: LONG PASCAL SaveCallback(int nPercent) When it comes to passing a function to another function, we leave the realm of any C++ that I understand. How do I call AVISave? And, where does the "Pascal" come from? thanks, Jake

      A Offline
      A Offline
      Andrew Peace
      wrote on last edited by
      #2

      I don't know the prototype for AVISave, but this is the general idea:

      LONG PASCAL SaveCallback(int nPercent)
      {
      UpdateProgress(nPercent);
      }

      void SaveAVIFile()
      {
      AVISave(SaveCallback, /*the othe parameters here*/);
      }

      So really, in essence, you just treat the function as a variable. Hope that helps, > Andrew.

      J 1 Reply Last reply
      0
      • A Andrew Peace

        I don't know the prototype for AVISave, but this is the general idea:

        LONG PASCAL SaveCallback(int nPercent)
        {
        UpdateProgress(nPercent);
        }

        void SaveAVIFile()
        {
        AVISave(SaveCallback, /*the othe parameters here*/);
        }

        So really, in essence, you just treat the function as a variable. Hope that helps, > Andrew.

        J Offline
        J Offline
        Jake Palmer
        wrote on last edited by
        #3

        This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake

        M C 2 Replies Last reply
        0
        • J Jake Palmer

          This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Your question is answered in the VC forum FAQ. See http://www.codeproject.com/useritems/cppforumfaq.asp#cpp_callbacks --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire."   -- Chris Maunder

          J 1 Reply Last reply
          0
          • M Michael Dunn

            Your question is answered in the VC forum FAQ. See http://www.codeproject.com/useritems/cppforumfaq.asp#cpp_callbacks --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire."   -- Chris Maunder

            J Offline
            J Offline
            Jake Palmer
            wrote on last edited by
            #5

            The ForumFAQ article has tons of good stuff, including telling me to make my callback function global or static, however I've tried it with each and still get the exact same error as before (see previous message). X| So, something else is killing me, I guess...any more ideas? thanks, Jake

            M 1 Reply Last reply
            0
            • J Jake Palmer

              This is what my code looks like, where AVISave takes a callback function as 3rd arg: long PASCAL CBadClass::SaveCallback(int percent) { return AVIERR_OK; } ... bool CBadClass::Foo() { AVISave(...,SaveCallback, ...); } This gives me the compilation error: error C2664: 'AVISaveA' : cannot convert parameter 3 from 'long (int)' to 'int (__stdcall *)(int)' None of the functions with this name in scope match the target type needless to say, I've got no ideas here X| thanks, Jake

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Well, for starters the parameter is a pointer to the callback function, so you might try &SaveCallback. Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.

              1 Reply Last reply
              0
              • J Jake Palmer

                The ForumFAQ article has tons of good stuff, including telling me to make my callback function global or static, however I've tried it with each and still get the exact same error as before (see previous message). X| So, something else is killing me, I guess...any more ideas? thanks, Jake

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                Your member function doesn't have the required prototype. It's

                long PASCAL CBadClass::SaveCallback(int percent)

                but AVISAVECALLBACK is defined as

                typedef BOOL (FAR PASCAL * AVISAVECALLBACK)(int);

                Change the return type of your function to BOOL. And BTW, FAR is obsolete and can be ignored, and PASCAL has been replaced by CALLBACK in Win32. --Mike-- http://home.inreach.com/mdunn/ "Make sure that if you are using a blow torch that you don't set anything on fire."   -- Chris Maunder

                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