I understand that when using DLLs, we have certain restrictions such as:
1) Memory should be new-ed and deleted in the same memory space.
ie new in dll, delete in dll
2) templates used in dll's have to be instantiated(or whatever is the spelling) at compile time
3) Classes whose implementation is in the DLL(exported classes) should not be newed outside the DLL.(Im not really sure about this point or why it should be this way, perhaps someone can explain, but that is what i understand from what ive read. This explains the need for Factory classes which news an object and return a pointer to it.)
Now i want to design a GUI. I have successfully made one in the past without boost but it was not in a DLL and it used a Event class i made without the use of boost.
But now, i want to start using more of boost and my code is in a dll.
In DLL
class DLLEXPORT Button
{
boost::function<void> onClick;
boost::function<void> onMouseOver;
boost::function<void> onMouseRelease;
//etc;
}
It should work fine here. But i want the events to be declared in the exe where the user will declare the required response.
In EXE
class player
{
public:
void play();
void stop();
};
player thePlayer;
//use a factory because of restriction in point 3.
Button* myButton = Factory::createButton();
myButton->onClick = boost::bind(&player::play, &thePlayer);
Now i believe boost::bind will create a boost::function and myButton->onClick will be assigned the value through a copy which i believe might cause problems. I have not implemented this code yet, but i would like to clarify potential problems before i get started on it.