This is not a new topic, but the only solution I've found on Google
Groups (or anywhere) is to replace REGCLS_MULTIPLEUSE with
REGCLS_SINGLEUSE when RegisterClassObjects is called. However, this is
a slight problem for ATL servers deriving from CAtlExeModuleT class,
because RegisterClassObjects is automatically called with
REGCLS_MULTIPLEUSE in CAtlExeModuleT::PreMessageLoop as defined in
atlbase.h.
For now, I've duplicated CAtlExeModuleT into another class and made the
ATL server class derive from that instead. However, it would be prone
to maintenance problems if MS ever changes the implementation of
CAtlExeModuleT.
I was wondering if anyone knows of a more elegant solution that
wouldn't be prone to maintenance problems in the future.
Thanks in advance.
Henru
I'd override RegisterClassObjects instead. You can do this since
PreMessageLoop calls it via static_cast<T*>(this) trick. Something like
this:
class CMyModule : public CAtlExeModuleT<CMyModule>
{
public:
HRESULT RegisterClassObjects(DWORD dwClsContext, DWORD dwFlags)
throw()
{
dwFlags =
((dwFlags & ~(REGCLS_MULTIPLEUSE | REGCLS_MULTI_SEPARATE ))
|
REGCLS_SINGLEUSE);
return
CAtlExeModuleT<CMyModule>::RegisterClassObjects(dwClsContext, dwFlags);
}
}
I agree that the original design that hardcodes the flags is, shall we
say, less than stellar.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925