I've got a function with a signature like this
int iV_SetSampleCallback(pDLLSetSample pSampleCallbackFunction)
Where pDLLSetSample
is
typedef int (CALLBACK * pDLLSetSample) (struct SampleStruct rawDataSample);
I want to pass my member function as callback
int sampleCallbackFunction(struct SampleStruct sample);
And when I call it like
iV_SetSampleCallback(&MainWindow::sampleCallbackFunction);
I got an error
error: C2664: 'int iV_SetSampleCallback(pDLLSetSample)': cannot convert argument 1 from 'int (__thiscall MainWindow::* )(SampleStruct)' to 'pDLLSetSample'
And I can't understand why it happens. What is CALLBACK
macro is? Where is __thiscall
came from? How should I correctly pass my callback to this function?
Your error is occurring because you are trying to pass a pointer to a non-static class member function
sampleCallbackFunction
instead of a pointer to a regular function. Note that non-static class member functions have explicitthis
parameter.CALLBACK
macro is often used in Windows and typically stands forstdcall
calling convention.To fix this error you need to