c++ callback syntax in a class
- by Mr Bell
I am trying to figure out the syntax to register a callback with this 3rd party software. I think it is probably a basic question, I just am not too familiar with c++. They have a method for registering a callback function so their code can call a function in my code when an event happens. They provided a working example that registers the callback from the main file, but I want to know how to do it when working inside a class
Their method signature:
smHTRegisterHeadPoseCallback(smEngineHandle engine_handle, void *user_data, smHTHeadPoseCallback callback_fun);
Working example from the main file:
void STDCALL receiveHeadPose(void *,smEngineHeadPoseData head_pose, smCameraVideoFrame video_frame)
{
...
}
void main()
{
...
smHTRegisterHeadPoseCallback(engine_handle,0,receiveHeadPose)
...
}
But I want to use this from my class
MyClass.h
class FaceEngine
{
public:
void STDCALL receiveFaceData(void *, smEngineFaceData face_data, smCameraVideoFrame video_frame);
...
MyClass.cpp
void FaceEngine::Start(void)
{
rc = smHTRegisterFaceDataCallback(hFaceAPIEngine,0,&FaceEngine::receiveFaceData);
...
Results in this compiler error:
Error 1 error C2664: 'smHTRegisterFaceDataCallback' : cannot convert parameter 3 from 'void (__stdcall FaceEngine::* )(void *,smEngineFaceData,smCameraVideoFrame)' to 'smHTFaceDataCallback' d:\stuff\programming\visual studio 2008\projects\tut02_vertices\faceengine.cpp 43 Beard
If my question isn't clear please let me know how I can clarify.