encapsulate C callback function into a C++ class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mosfet

    encapsulate C callback function into a C++ class

    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_SetFinge rStatus(T__STAT US i_nStatus, T__UCHAR *i_pImage,
    T__ULONG i_nRow, T__ULONG i_nCol, T__BOOL *o_pContinue)
    {
    }


    T__STATUS SM_BSP_SetMsgIn fos(T__INT i_nMsgId, T__BOOL *o_pContinue)
    {
    }

    T__STATUS SM_BSP_SetBSPSt atus(T__UCHAR i_nStatusId, T__BOOL *o_pContinue)
    {
    }

    l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)
    &SM_BSP_SetFing erStatus;
    l_GUICallbackFu nctions.SM_BSP_ SetMsgInfos = (PSM_BSP_SET_MS G_INFOS)
    &SM_BSP_SetMsgI nfos;
    l_GUICallbackFu nctions.SM_BSP_ SetBSPStatus = (PSM_BSP_SET_BS P_STATUS)
    &SM_BSP_SetBSPS tatus;
    ret = SM_BSP_SetGUICa llback(l_GUICal lbackFunctions) ;

    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_SetFinge rStatus();
    void EventDelay(DWOR D dwMilliSec);
    int m_nRet;
    SM_BSP_GUI_CALL BACK l_GUICallbackFu nctions;

    };


    //CBio.cpp
    int CBio::InitBio()
    {
    // register CallBacks
    l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)
    &SM_BSP_SetFing erStatus;
    }

    return m_nRet;
    }





    T__STATUS CBio::SM_BSP_Se tFingerStatus()
    {

    return 0;
    }

    The problem is
    l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)
    &SM_BSP_SetFing erStatus; doesn't
    compile. I need to pass to the SM_BSP_SetFinge rStatus function the adress of
    another function. It works in C but not in C++.
    How can I do this ?








  • Mike Wahler

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


    mosfet <tricubes@wanad oo.fr> wrote in message
    news:be44vc$pfc $1@news-reader4.wanadoo .fr...[color=blue]
    > 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_SetFinge rStatus(T__STAT US i_nStatus, T__UCHAR *i_pImage,
    > T__ULONG i_nRow, T__ULONG i_nCol, T__BOOL *o_pContinue)
    > {
    > }
    >
    >
    > T__STATUS SM_BSP_SetMsgIn fos(T__INT i_nMsgId, T__BOOL *o_pContinue)
    > {
    > }
    >
    > T__STATUS SM_BSP_SetBSPSt atus(T__UCHAR i_nStatusId, T__BOOL *o_pContinue)
    > {
    > }
    >
    > l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)
    > &SM_BSP_SetFing erStatus;
    > l_GUICallbackFu nctions.SM_BSP_ SetMsgInfos = (PSM_BSP_SET_MS G_INFOS)
    > &SM_BSP_SetMsgI nfos;
    > l_GUICallbackFu nctions.SM_BSP_ SetBSPStatus = (PSM_BSP_SET_BS P_STATUS)
    > &SM_BSP_SetBSPS tatus;
    > ret = SM_BSP_SetGUICa llback(l_GUICal lbackFunctions) ;
    >
    > 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_SetFinge rStatus();
    > void EventDelay(DWOR D dwMilliSec);
    > int m_nRet;
    > SM_BSP_GUI_CALL BACK l_GUICallbackFu nctions;
    >
    > };
    >
    >
    > file://CBio.cpp
    > int CBio::InitBio()
    > {
    > // register CallBacks
    >[/color]
    l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)[color=blue]
    > &SM_BSP_SetFing erStatus;
    > }
    >
    > return m_nRet;
    > }
    >
    >
    >
    >
    >
    > T__STATUS CBio::SM_BSP_Se tFingerStatus()
    > {
    >
    > return 0;
    > }
    >
    > The problem is
    > l_GUICallbackFu nctions.SM_BSP_ SetFingerStatus =(PSM_BSP_SET_F INGER_STATUS)
    > &SM_BSP_SetFing erStatus; doesn't
    > compile. I need to pass to the SM_BSP_SetFinge rStatus function the adress[/color]
    of[color=blue]
    > another function. It works in C but not in C++.
    > How can I do this ?[/color]



    Also see item 33.1

    -Mike



    Comment

    Working...