I am using a camera API that calls a callback function every time there is a new image. The callback function is passed as:
BOOL WINAPI StTrg_SetTransferEndCallback(HANDLE hCamera, funcTransferEndCallback func, PVOID pvContext);
Where funcTransferEndCallback is:
typedef void (WINAPI *funcTransferEndCallback)(HANDLE hCamera, DWORD dwFrameNo, DWORD dwWidth, DWORD dwHeight, WORD wColorArray, PBYTE pbyteRaw, PVOID pvContext);
I don't want to make a callback function but actually use a method in a class instead. I am calling this StTrg_SetTransferEndCallback() inside my classe's constructor, so I can initialize the camera and pass my classe's method to capture every new frame and process it.
My method is defined in my class .h as:
public class Camera
{
public:
.....
void TakePicture(string pictureFileName);
void StartRecording(string videoFileName);
void StopRecording(void);
.....
private:
volatile bool takePictureFlag;
volatile bool startRecordingFlag;
volatile bool stoptRecordingFlag;
void __stdcall TransferEndCallback(HANDLE hCamera, DWORD dwFrameNo, DWORD dwWidth, DWORD dwHeight, WORD wColorArray, PBYTE pbyteRaw, PVOID pvContext);
};
If I try this:
StTrg_SetTransferEndCallback(cameraHandle, TransferEndCallback, NULL);
Or this:
StTrg_SetTransferEndCallback(cameraHandle, this->TransferEndCallback, NULL)
Visual Studio 2013 says:
error C3867: 'MyNamespace::MyClass::TransferEndCallback': function call missing argument list; use '&MyNamespace::MyClass::TransferEndCallback' to create a pointer to member
So I use it as suggested:
StTrg_SetTransferEndCallback(cameraHandle, &MyNamespace::MyClass::TransferEndCallback, NULL)
And I receive this error message:
error C2664: 'BOOL StTrg_SetTransferEndCallback(HANDLE,funcTransferEndCallback,PVOID)' : cannot convert argument 2 from 'void (__stdcall MyNamespace::MyClass::* )(HANDLE,DWORD,DWORD,DWORD,WORD,PBYTE,PVOID)' to 'funcTransferEndCallback' There is no context in which this conversion is possible
So, is it possible to pass a member method as a function? Is this a case for std::bind?