Re: How to implement strategy pattern with ATL Control?
For starters, get rid of attributed ATL. Start your project anew
and uncheck the attributed ATL box.
Next, be aware that you should not derive from a complete
COM object in ATL, rather you can have a base class with a
big chunk of the implmentation and then your 3 derived classes
form the ATL framework around it.
The following 2 FAQ articles should help you I hope:
http://www.mvps.org/vcfaq/com/7.htm
http://www.mvps.org/vcfaq/com/8.htm (maybe)
The second article deals with derived interfaces so may not
apply to you.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Siegfried Heintze" <siegfried@heintze.com> wrote in message
news:OKRb4N35GHA.2264@TK2MSFTNGP02.phx.gbl...
I'm implementing a DVD clip player as a C++/ATL control that calls the
directshow API.I want to use the strategy pattern to implement three
almost identical ActiveX controls. The only difference is the
implementation of the function play.
I guess I will name the three different controls after the directshow
function used to implement the play function:
ClipPlayAtTimeInTitle
ClipPlayAtTime
ClipPlayAtTimeInTitleAutoStop
I want all these to inherit from an ActiveX control called ClipBase.
So I ran the ATL code generator in VS2005 and selected all the optional
choices and created a 419 line header file for ClipBase that defines
IClipBase and CClipBase.
I ran this again to create a control called ClipPlayAtTimeInTitle. I
gutted this file so it inherited from ClipBase. Now I get the following
error:
Error 3 error C3247: 'CClipPayAtTimeInTitle' : a coclass cannot inherit
from another coclass 'CClipBase'
c:\winoop\dvdclipeditorplayer\dvdplayer\dvdplayer\clippayattimeintitle.h
30
How do I use the strategy pattern in ATL?
I hope it is not necessary for ClipPlayAtTimeInTitle, ClipPlayAtTime and
ClipPlayAtTimeInTitleAutoStop to all define the same properties and call
backs. Uggghhh... that would be a huge amount of redundant code. Surely
there is a way to use the strategy pattern (as described in the book
"Design Patterns" by Gamma et. al)?
Thanks,
Siegfried
PS: Here is the code that caused the above error message:
// ClipPayAtTimeInTitle.h : Declaration of the CClipPayAtTimeInTitle
#pragma once
#include "resource.h" // main symbols
#include <atlctl.h>
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) &&
!defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows
CE platform, such as the Windows Mobile platforms that do not include full
DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL
to support creating single-thread COM object's and allow use of it's
single-threaded COM object implementations. The threading model in your
rgs file was set to 'Free' as that is the only threading model supported
in non DCOM Windows CE platforms."
#endif
#include "..\DVDClipBase\ClipBase.h"
// CClipPayAtTimeInTitle
[coclass,control,default(IClipBase,
_IClipBaseEvents),threading(apartment),vi_progid("DVDPlayer.ClipPayAtTimeInTitle"),progid("DVDPlayer.ClipPayAtTimeInTitle.1"),version(1.0),uuid("98D48207-ABF1-4103-BC72-450F62ED4E1E"),helpstring("ClipPayAtTimeInTitle
Class"),event_source(com),support_error_info(IClipPayAtTimeInTitle),registration_script("control.rgs")]
class ATL_NO_VTABLE CClipPayAtTimeInTitle :
public CClipBase{
public:
CClipPayAtTimeInTitle()
{
}
};