Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

One process per ATL server instance

185 views
Skip to first unread message

wildg...@gmail.com

unread,
Dec 20, 2004, 2:43:52 PM12/20/04
to
Basically, I need to be able to have COM spawn a new process for each
instance of an ATL server created.

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

Igor Tandetnik

unread,
Dec 20, 2004, 2:58:32 PM12/20/04
to
<wildg...@gmail.com> wrote in message
news:1103571832.5...@z14g2000cwz.googlegroups.com

> 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'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


0 new messages