tags:

views:

39

answers:

2

I have a DLL which has a function which accepts a function pointer converts it to a boost::function. This is then stored and then called from inside the DLL.

I want to add a function to the DLL to handle member functions in a similar way. I know I need to use boost::bind to wrap the member function pointer and the object together. I want to do the binding on the DLL side though so the EXE does not require boost libraries to be included.

How would you write this function? One which accepts a member function pointer and an object as arguments and binds them together.

Thanks!

A: 

Isn't Boost open source? If so, peek into the boost code, learn how it's done, and re-implement it yourself, without the dependency.

C Johnson
A: 

It might be a bad idea to try passing member function pointers into DLLs because they can vary in size depending on certain circumstances. (Some details here.) Maybe if you always know that you will be building both halves of the application with the same compiler you will be ok.

As for the function, I expect it would look something like this (completely untested and uncompiled code):

typedef void(ObjectType::*OTMemberFn)();

boost::function<void (ObjectType o)> bind_mem_fn(ObjectType o, OTMemberFn mf)
{
    return boost::bind(mf, o);
}
Kylotan