encapsulate C callback function into a C++ class

Discussion in 'C++' started by mosfet, Jul 4, 2003.

  1. mosfet

    mosfet Guest

    Hi,

    I have developped an MFC program that uses a fingerprint scanner.
    To control the Bio scanner I use a library with the following function



    these functions are used to get the status message from the scanner

    T__STATUS SM_BSP_SetFingerStatus(T__STATUS i_nStatus, T__UCHAR *i_pImage,
    T__ULONG i_nRow, T__ULONG i_nCol, T__BOOL *o_pContinue)
    {
    }


    T__STATUS SM_BSP_SetMsgInfos(T__INT i_nMsgId, T__BOOL *o_pContinue)
    {
    }

    T__STATUS SM_BSP_SetBSPStatus(T__UCHAR i_nStatusId, T__BOOL *o_pContinue)
    {
    }

    l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    &SM_BSP_SetFingerStatus;
    l_GUICallbackFunctions.SM_BSP_SetMsgInfos = (PSM_BSP_SET_MSG_INFOS)
    &SM_BSP_SetMsgInfos;
    l_GUICallbackFunctions.SM_BSP_SetBSPStatus = (PSM_BSP_SET_BSP_STATUS)
    &SM_BSP_SetBSPStatus;
    ret = SM_BSP_SetGUICallback(l_GUICallbackFunctions);

    SM_BSP_Capture(); //Capture fingerprint
    SM_BSP_Process(); // Process fingerprint


    My problem is I would like to create a C++ class like this

    // CBio.hpp
    class CBio
    {
    public:

    CBio(); // constructor
    ~CBio(); // destructor
    int InitBio();
    int Capture();


    private:
    static T__STATUS SM_BSP_SetFingerStatus();
    void EventDelay(DWORD dwMilliSec);
    int m_nRet;
    SM_BSP_GUI_CALLBACK l_GUICallbackFunctions;

    };


    //CBio.cpp
    int CBio::InitBio()
    {
    // register CallBacks
    l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    &SM_BSP_SetFingerStatus;
    }

    return m_nRet;
    }





    T__STATUS CBio::SM_BSP_SetFingerStatus()
    {

    return 0;
    }

    The problem is
    l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    &SM_BSP_SetFingerStatus; doesn't
    compile. I need to pass to the SM_BSP_SetFingerStatus function the adress of
    another function. It works in C but not in C++.
    How can I do this ?
     
    mosfet, Jul 4, 2003
    #1
    1. Advertising

  2. mosfet

    Mike Wahler Guest

    Re: [FAQ] encapsulate C callback function into a C++ class

    mosfet <> wrote in message
    news:be44vc$pfc$...
    > Hi,
    >
    > I have developped an MFC program that uses a fingerprint scanner.
    > To control the Bio scanner I use a library with the following function
    >
    >
    >
    > these functions are used to get the status message from the scanner
    >
    > T__STATUS SM_BSP_SetFingerStatus(T__STATUS i_nStatus, T__UCHAR *i_pImage,
    > T__ULONG i_nRow, T__ULONG i_nCol, T__BOOL *o_pContinue)
    > {
    > }
    >
    >
    > T__STATUS SM_BSP_SetMsgInfos(T__INT i_nMsgId, T__BOOL *o_pContinue)
    > {
    > }
    >
    > T__STATUS SM_BSP_SetBSPStatus(T__UCHAR i_nStatusId, T__BOOL *o_pContinue)
    > {
    > }
    >
    > l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    > &SM_BSP_SetFingerStatus;
    > l_GUICallbackFunctions.SM_BSP_SetMsgInfos = (PSM_BSP_SET_MSG_INFOS)
    > &SM_BSP_SetMsgInfos;
    > l_GUICallbackFunctions.SM_BSP_SetBSPStatus = (PSM_BSP_SET_BSP_STATUS)
    > &SM_BSP_SetBSPStatus;
    > ret = SM_BSP_SetGUICallback(l_GUICallbackFunctions);
    >
    > SM_BSP_Capture(); file://Capture fingerprint
    > SM_BSP_Process(); // Process fingerprint
    >
    >
    > My problem is I would like to create a C++ class like this
    >
    > // CBio.hpp
    > class CBio
    > {
    > public:
    >
    > CBio(); // constructor
    > ~CBio(); // destructor
    > int InitBio();
    > int Capture();
    >
    >
    > private:
    > static T__STATUS SM_BSP_SetFingerStatus();
    > void EventDelay(DWORD dwMilliSec);
    > int m_nRet;
    > SM_BSP_GUI_CALLBACK l_GUICallbackFunctions;
    >
    > };
    >
    >
    > file://CBio.cpp
    > int CBio::InitBio()
    > {
    > // register CallBacks
    >

    l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    > &SM_BSP_SetFingerStatus;
    > }
    >
    > return m_nRet;
    > }
    >
    >
    >
    >
    >
    > T__STATUS CBio::SM_BSP_SetFingerStatus()
    > {
    >
    > return 0;
    > }
    >
    > The problem is
    > l_GUICallbackFunctions.SM_BSP_SetFingerStatus=(PSM_BSP_SET_FINGER_STATUS)
    > &SM_BSP_SetFingerStatus; doesn't
    > compile. I need to pass to the SM_BSP_SetFingerStatus function the adress

    of
    > another function. It works in C but not in C++.
    > How can I do this ?


    http://www.parashift.com/c -faq-lite/pointers-to-members.html#faq-33.2

    Also see item 33.1

    -Mike
     
    Mike Wahler, Jul 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank
    Replies:
    1
    Views:
    697
    Eliyahu Goldin
    Oct 6, 2005
  2. Java_New
    Replies:
    1
    Views:
    397
    Andrew Thompson
    Feb 3, 2007
  3. TBass
    Replies:
    6
    Views:
    345
    mlimber
    Jun 21, 2006
  4. Giles Bowkett
    Replies:
    9
    Views:
    171
    Ben Tompkins
    Sep 12, 2007
  5. Replies:
    0
    Views:
    95
Loading...

Share This Page