Re: [Boost-users] boost::bind, C++ member function and C callback function

Changing the OpenSSL API is not an option for me. Let's assume that the callback function accepts a void* parameter, can you show me an example that I can bind C++ member function to a C callback function? Thank you
I got the following error under VC++ 7.1:
error C2664: 'CRYPTO_set_id_callback' : cannot convert parameter 1 from 'boost::_bi::bind_t<R,F,L>' to 'unsigned long (__cdecl *)(void)' with [ R=unsigned long, F=boost::_mfi::mf0<unsigned long,Test>, L=boost::_bi::list1<boost::_bi::list_av_1<Test *>::B1> ] No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
It doesn't even take in void *???? Maybe the fact that it doesn't take in state means something. You should look up that specific callback in the openssl documentation
Is it possible to use boost::bind to bind a C++ member function as a callback function for C interface?
Its easy given that said C interface allows the user to pass in "other data" a la void *.

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Li, PingShan (Kansas City) Sent: Tuesday, May 08, 2007 7:44 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::bind,C++ member function and C callback function
Changing the OpenSSL API is not an option for me.
Let's assume that the callback function accepts a void* parameter, can you show me an example that I can bind C++ member function to a C callback function?
Untested: typedef boost::function<void(void)> fn_t; void generic_c_callback(void * data) { fn_t * f(reinterpret_cast<fn_t *>(data)); if(f) (*f)(); else log_oops("..."); // delete f; ? } int main() { register_c_callback(generic_c_callback,new fn_t(bind(a,something,something,something))); } I think something like this could work, but have never actually tried it :-) Sohail
participants (2)
-
Li, PingShan (Kansas City)
-
Sohail Somani