I have come across a serious problem regarding a singleton class I have in a DLL. To put it short, I am finding that I get two instances of the same singleton created only lines apart in my code. This is baffling.
Please see the class diagram VS has created for at http://img242.imageshack.us/img242/3425/classdiagrammz6.jpg
I have a test app that calls the following:
ine1>& instance = MyNamespace::CSessionManag
Now, this results in RunFunc() being called:
BOOL RunFunc ()
instance = CSessionManager<CEngine1>:
return ExecuteSynchronousTask ( );
You can see I obtain a second instance at this point, just to make sure it is the same one as was initialised in my dialog test app. It is, since its m_bInitialised member is TRUE.
We then get
i2 = CSessionManager<CEngine1>:
This is where things go wrong. i2 insists on creating a second object, not using the one that has already been created. This is causing major inconsistency (in reality, the objects are far more complicated than is shown).
Someone please tell me what is going on here and how I can correct it. It is crucial that I can access the same object that was initialised in my test app from within my DLL. It cannot be a DLL-boundary issue since the call to MyFunc() is executed within the DLL, and that works fine.
I have created a very simple project (<100 lines) to demonstrate this problem; please download it at http://download.yousendit.com/AFD129DF0DD259D2
(vS 2008 format).