Problem with settgin a callback under directshow

This is a discussion on Problem with settgin a callback under directshow within the Windows Programming forums, part of the Platform Specific Boards category; 1>..\Include\CDirectShowCamera.cpp(224) : error C3867: 'CDirectShowCamera::BufferCB': function call missing argument list; use '&CDirectShowCamera::BufferCB' to create a pointer to member Code: this ...

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189

    Problem with settgin a callback under directshow

    1>..\Include\CDirectShowCamera.cpp(224) : error C3867: 'CDirectShowCamera::BufferCB': function call missing argument list; use '&CDirectShowCamera::BufferCB' to create a pointer to member
    Code:
    this->pGrabber->SetCallback(this->BufferCB , 1);
    
    keep returning errors, here is the callback function, which is implimented as a member function

    Code:
    HRESULT CDirectShowCamera::BufferCB(double SampleTime , BYTE* pImage , long BufferLen){ 
     // snip irrelevant guts
       return S_OK;
     } 
    
    except if I add the ampersand it gives this error

    Code:
     this->pGrabber->SetCallback(&CDirectShowCamera::BufferCB , 1);
    1>..\Include\CDirectShowCamera.cpp(224) : error C2664: 'ISampleGrabber::SetCallback' : cannot convert parameter 1 from 'HRESULT (__thiscall CDirectShowCamera::* )(double,BYTE *,long)' to 'ISampleGrabberCB *'


    which makes even less sense. Obviously I need to be able to call this callback function, but I need it to know what instance of CDIrectShowCamera it is handling, so that it can add the sampels to the appropriate buffer. There will be more than one instance of the class operating simultaneously. I know im probably missing somethign realyl obvious.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Never worked with these, but: "You can't convert a member-function pointer to a ISampleGrabberCB *" -- is what that error says... where are you getting lost?

    Seems to me you should derive from ISampleGrabberCB, and implement that interface, instantiate it, and pass the instance. The derived class could hold whatever data you needed it to, such as a pointer to your CDIrectShowCamera. No different than predicates to C++'s standard functions, such as sort(), really.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Right, assuming you've derived the class from ISampleGrabberCB and overloaded the BufferCB or SampleCB functions, you'll just need to pass a pointer to the object itself, ie:

    Code:
    this->pGrabber->SetCallback(this, 1);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    I tried making a derived class but the compiler pukes because there is no appropriate constructor type in the base class, and when I tried overloading the constructor it puked again saying constructors are not allowed a return type, which didnt make sense since the constructor had no return type. I think im starting to see why pointers to member functions are not used very often.

    I'm rethinking my strategy to possibly avoid pointers to member functions. It late and I think im messing up on implimenting the ISampleGrabberCB interface, so ill get soem sleep adn try again tomorrow.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I tried making a derived class but the compiler pukes because there is no appropriate constructor type in the base class, and when I tried overloading the constructor it puked again

    Well, you can't override a constructor. Can you post a compilable example?
    Last edited by Sebastiani; 06-23-2009 at 11:40 PM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    Quote Originally Posted by abachler
    I tried making a derived class but the compiler pukes because there is no appropriate constructor type in the base class
    If I understand this particular hurdle correctly, you could invoke the appropriate base class constructor in the derived class constructor's initialisation list.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Sebastiani View Post
    >> I tried making a derived class but the compiler pukes because there is no appropriate constructor type in the base class, and when I tried overloading the constructor it puked again

    Well, you can't override a constructor. Can you post a compilable example?
    The last compilable example I have doesnt have any of this code in it. It's using the GetCurrentBuffer() method, which I want to improve so that I get every image, with no duplicates. All im trying to do is add the callback so I can buffer each sample and then ill rewrite the CDirectShowCamera::GetCurrentImage() member function to retrieve images from the buffer instead of from GetCurrentBuffer(). This is the relevant code from the constructor function in the last compilable version,

    Code:
      this->pGrabber->SetCallback(NULL , 1);
      this->pGrabber->SetBufferSamples(TRUE);
    
      this->Stage = 17;
      hr = this->pControl->Run();
      if(FAILED(hr)) return;
    
      this->Stage = 0xffffffff;
      this->Initialized = TRUE;
      return;
    I cant post the whole class as its quite lengthy, this is actually the last thing it does before running the graph
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21