Calling c++ object in callback function of c library -
i using c library, uses callback functions.
is there way can access calling object of c++ class ?
edit:
i using c-client lib. have function mm_log.
void mm_log(char* string, long err_flag)
which getting internally called library. want check on imap stream getting called.
more info can download library ftp://ftp.cac.washington.edu/imap
all (good) c library functions want callback have void* user_data
pointer part of function , callback parameter. pass pointer object function , gets passed in callback. example:
typedef void (*callback)(void*); void dumb_api_call(callback cb, void* user_data){ cb(user_data); } struct foo{}; void my_callback(void* my_data){ foo* my_foo = static_cast<foo*>(my_data); } int main(){ foo my_foo; dumb_api_call(my_callback, &my_foo); }
Comments
Post a Comment