void* pointer to class method pointer

I'm trying to do an operation which is probably horribly platform-specific.

Basically I'm using dlsym() with a mangled function name to get a pointer to a class method. My problem is converting the returned void* to a void (MyClass::*_my_function_pointer)(void)

In windows I can do
(FARPROC&)_my_function_pointer = GetProcAddress("mangled function name");

However I don't think it's working in Unix to do
(void*&)_my_function_pointer = dlsym("mangled function name");

dlsym() is returning a non-NULL pointer, so I think that means I'm using the correct mangled name.

If I later do a check:
1
2
_my_function_pointer == NULL; //is true
(void*&)_my_function_pointer == NULL; //is false 


I unfortunately don't have the luxury of statically linking to this method.
I'm not exactly sure, but after you set the pointer to NULL, you cast it to a reference to a void pointer. I've never tried that and somehow I doubt casting a pointer to a reference is a good idea. I don't think you want the &
Ok, this is an old thread, but I was away.

You have to be really, really careful, because sizeof( member-function-pointer ) is not necessarily equal to sizeof ( void* ).

You _should_ be ok as long as the member function is not virtual.

Take with a grain of salt though, because I've never tried anything like this before.

Topic archived. No new replies allowed.