encapsulate C callback function into a C++ class

M

mosfet

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 ?
 
M

Mike Wahler

mosfet said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top