Reputation: 583
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?
Upvotes: 0
Views: 443
Reputation: 37597
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 explicit this
parameter. CALLBACK
macro is often used in Windows and typically stands for stdcall
calling convention.
To fix this error you need to
static int CALLBACK sampleCallbackFunction(struct SampleStruct sample);
Upvotes: 2