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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. member function as callback function problem

member function as callback function problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
3 Posts 3 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.
  • Y Offline
    Y Offline
    yccheok
    wrote on last edited by
    #1

    i try to pass the following global function pointer to a c library function (cvcamSetProperty) which required the third parameter as callback function pointer. --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, callback2); } void callback2(IplImage* image) { } --------------------------------------------- the compilation stage works fine and no problem at all. however, when i try to pass the member function pointer, it failed :( --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, &CXFaceRecognitionDlg::callback); } void CXFaceRecognitionDlg::callback(IplImage* image) { } --------------------------------------------- here is the error message which i obtain when i try to compile the above code: D:\Documents and Settings\Administrator\Desktop\XFaceRecognition\XFaceRecognitionDlg.cpp(144) : error C2664: 'cvcamSetProperty' : cannot convert parameter 3 from 'void (__thiscall CXFaceRecognitionDlg::*)(struct _IplImage *)' to 'void *' There is no context in which this conversion is possible may i now how can i solve this problem? thank you. regards yccheok

    A C 2 Replies Last reply
    0
    • Y yccheok

      i try to pass the following global function pointer to a c library function (cvcamSetProperty) which required the third parameter as callback function pointer. --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, callback2); } void callback2(IplImage* image) { } --------------------------------------------- the compilation stage works fine and no problem at all. however, when i try to pass the member function pointer, it failed :( --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, &CXFaceRecognitionDlg::callback); } void CXFaceRecognitionDlg::callback(IplImage* image) { } --------------------------------------------- here is the error message which i obtain when i try to compile the above code: D:\Documents and Settings\Administrator\Desktop\XFaceRecognition\XFaceRecognitionDlg.cpp(144) : error C2664: 'cvcamSetProperty' : cannot convert parameter 3 from 'void (__thiscall CXFaceRecognitionDlg::*)(struct _IplImage *)' to 'void *' There is no context in which this conversion is possible may i now how can i solve this problem? thank you. regards yccheok

      A Offline
      A Offline
      AlexO
      wrote on last edited by
      #2

      I think it should be static function, if it is a member of a class(plus check the actual signature it might need to be __cdecl)

      1 Reply Last reply
      0
      • Y yccheok

        i try to pass the following global function pointer to a c library function (cvcamSetProperty) which required the third parameter as callback function pointer. --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, callback2); } void callback2(IplImage* image) { } --------------------------------------------- the compilation stage works fine and no problem at all. however, when i try to pass the member function pointer, it failed :( --------------------------------------------- BOOL CXFaceRecognitionDlg::OnInitDialog() { // // some code had been eliminated // // making call the the c library function cvcamSetProperty(0, CVCAM_PROP_CALLBACK, &CXFaceRecognitionDlg::callback); } void CXFaceRecognitionDlg::callback(IplImage* image) { } --------------------------------------------- here is the error message which i obtain when i try to compile the above code: D:\Documents and Settings\Administrator\Desktop\XFaceRecognition\XFaceRecognitionDlg.cpp(144) : error C2664: 'cvcamSetProperty' : cannot convert parameter 3 from 'void (__thiscall CXFaceRecognitionDlg::*)(struct _IplImage *)' to 'void *' There is no context in which this conversion is possible may i now how can i solve this problem? thank you. regards yccheok

        C Offline
        C Offline
        csc
        wrote on last edited by
        #3

        Declare the callback function as static function of the class class CXFaceRecognitionDlg:: ....... { : static void callback(IplImage* image); : } and i think you should not use the & for the call, just use the static function name : cvcamSetProperty(0, CVCAM_PROP_CALLBACK, CXFaceRecognitionDlg::callback);

        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