Hello everyone,
I am having a problem creating a 'In-proc', "Singleton" ActiveX Control using ATL 3.0. I have tried DECLARE_CLASSFACTORY_SINGLETON macro, but this doesn't work across the processes. I want only one instance of the ActiveX Component running across all process and even across the network.
If any other process tries to instantiate the Component second time onwards should receive NULL.
Please, Let me know if there is any way we can do it...
Thanking you in advance...
-Bye.

ATL COM Singleton
Klaus Keith
Use a Mutex that is created and locked when the first object is created. You can use FinalConstruct to do this. If the Mutex is already locked. You just return E_FAIL.
In this case the COM object can be created only once by one process.
BTW: In my eyes this doesn't make sense to me!
Vasile
Coco King
Well... Thanks Martin.
Yes, you may be right that making such a COMponent doesn't make any sense. But the requirements can be very strange, and I am dealing with a strange one right now.
Ok. but even after using Mutex the problem remains when the component is refered remotely. Can we make any work-around to be able to make it singleton across network too...
Thank you again.
Bye.
Peter G Lin
Thanks again Martin...
This is a good idea. Problems like this should be treated with the same sort of work-arounds.
Thanks for being there and answering.
Bye.
Andrew Mackie
If the scope is in-proc I do not see how it can determine if it is the only instance over more processes. There might be some trick/workarounds to do it but to do it properly it most likely has to be done out-of-proc instead.