If you can put 2 global variables in the same DLL, this is not the same story. As Jem said in his own answer, the DLL debugging system is not guaranteed by the system. Therefore, you may have a big problem with 2 separated Dlls. I am not a Windows system guru, but looking using google I found msdn bloggers which says that they had the same problem and there was no good solution to solve it.
I can put them in one DLL, in my opinion, the solution is simpler, in this case you do not need to solve the problem of "not guaranteed answer to the DLL" (itβs not solvable, as I understand it).
But then you still need to solve a new problem: the global order of destruction of variables is not guaranteed by the C ++ language. But this can be solved:
you need to use some kind of reference couting. boost :: shared_ptr can do the trick.
Declare it global and define it as follows:
boost::shared_ptr my_resource_ptr ( new Resource() );
Then you need to change your user implementation to keep your own shared_ptr:
class User { ... boost::share_ptr a_resource_ptr; ... };
Until the entire user instance is destroyed, they will βsaveβ the Resource instance and thus prevent it from being deleted from the environment, even if the global shared_ptr could be destroyed. The last destroyed instance of the user (indirectly) will delete the instance of the resource.
Regardless of the reference count used, ComPtr is your own, it should do the trick.
source share