1

I've created a COM class within an exe server. It's designed to be a singleton. It basically gets instantiated once, and then it keeps tabs on various events occurring on the machine. Also, other COM classes, which are loaded via DLL into another process, communicate with it every now and then.

I've read that DECLARE_CLASSFACTORY_SINGLETON/CComClassFactorySingleton are bad and should not be used.

My question is whether RegisterActiveObject/GetActiveObject is a suitable alternative API for this set up. And if not, is there something else I should be using? Thanks for any guidance.

  • 1
    CComClassFactorySingleton is a class factory (IClassFactory). You need a class factory. If you *want* a singleton, what exactly is the problem with CComClassFactorySingleton? RegisterActiveObject is about the ROT (a way to expose your object with monikers same as IRunningObjectTable::Register). That's something else. Or do you really need a singleton? – Simon Mourier Oct 04 '21 at 18:18
  • Well, I'm not completely sure, but I think I need a singleton. I had just [read](https://flylib.com/books/en/3.286.1.53/1/) that `DECLARE_CLASSFACTORY_SINGLETON` should be avoided, but perhaps that warning applies mainly to DLL, in-proc singletons. –  Oct 04 '21 at 19:14
  • The warning is general not related to ATL in particular https://stackoverflow.com/questions/12755539/why-is-singleton-considered-an-anti-pattern, but if you want one, CComClassFactorySingleton is fine. – Simon Mourier Oct 04 '21 at 19:35

0 Answers0