Typically, such a callback would look like this:
void Callback( void* data) { CMyClass *myClassInstance = static_cast<CMyClass *>(data); myClassInstance->MyInstanceMethod(); }
Of course, you need to make sure that the data points to an instance of your class. For instance.
CMyClass* data = new CMyClass(); FunctionCallingMyCallback( data, &Callback); delete data;
Now, if I understand you correctly, you also need to pass char *. You can either wrap both in the structure and expand it in the callback like this:
MyStruct* data = new MyStruct(); data->PtrToMyClass = new CMyClass(); data->MyCharPtr = "test"; FunctionCallingMyCallback( data, &Callback); delete data->PtrToMyClass; delete data; void Callback( void* data) { MyStruct *myStructInstance = static_cast<MyStruct *>(data); CMyClass *myClassInstance = myStructInstance->PtrToMyClass; char * myData = myStructInstance->MyCharPtr; myClassInstance->MyInstanceMethod(myData); }
or, if you can change the definition of CMyClass, put all the necessary data in the members of the class so that you can use the callback, as in the first example.
source share