
duplicated Singleton instances problem...
Hi all,
I have a problem with a singleton, I created a singleton
with the:
DECLARE_CLASSFACTORY_SINGLETON(MySingletonObj)
and it is ok, there is only one instance of the component
interface MySingletonObj. This way each time it is
requested an instance by COM, CoCreateInstanceEx it will
effectivelly create/return the only one instance.
The problem arises when I try to make this object global
(TopLevelObject) for easing the access from a Visual Basic
client. I created an additional interface TopLevelObject
that has a property that creates and returns an instance of
MySingletonObj (created with the "within component way"):
CComObject<MySingletonObj> *pMySingletonObj;
CComObject<MySingletonObj>::CreateInstance(&pMySingletonObj);
hr = pMySingletonObj->QueryInterface(IID_IDispatch,(void**)pVal);
this obviously bypass the Class factory and enables having several
instances of the MySingletonObj object.
Any workarounds to this problem? I don't want to renounce to the
ToLevelObject...
Thanks in advance,
Giovanni