Re: Conditional compiling according to C++ compiler version (Express or Professional)
----- Original Message -----
From: "Hendrik Schober" <Spamtrap@gmx.de>
Newsgroups: microsoft.public.vc.language
Sent: Thursday, November 20, 2008 7:50 PM
Subject: Re: Conditional compiling according to C++ compiler version
(Express or Professional)
Gingko wrote:
[...]
So I am now falling back on the idea of writing myself a small header
file providing a minimal template stub compatible with the ATL templates
that I use, and allowing the Visual C++ Express 2005 users to compile the
project.
Interesting. (I believe it was my question starting the
thread "finding <atlbase.h>" that Alex referred to.)
Do you already have any stubs? Will they be publicly
available?
Hello;
I 've started something, yes.
But it is very tiny (not more than 50 significant lines yet) and it is
only intended to fill the short needs of the project I work with.
(that is, just supplying some AddRef / Release / QueryInterface /
CoCreateInstance, and also VARIANT related calls)
It has been very few tested right now and is very likely that I will have to
add things in the future as needed by the project.
Here is how it looks like now (no comments inside, as this is only a
replacement for something that is expected to be already known) :
<quote>
template <class IU>
class CComPtr
{
public:
IU * p;
CComPtr() : p(NULL) {
}
CComPtr(IU* q) : p(q) {
if (p) p->AddRef();}
CComPtr(const CComPtr<IU> & r) : p(r.p) {
if (p) p->AddRef();}
IU * operator -> () const {
return p;}
bool operator ! () const {
return p==NULL;}
IU** operator & () {
return &p;}
operator IU * () {
return p;}
void Release() {
IU* t=p; if (t) {p=NULL; t->Release();}}
IU* operator = (const IU* q) {
Release(); p=q; p->AddRef(); return p;}
CComPtr<IU> & operator = (const CComPtr<IU> & r) {
Release(); p=r.p; p->AddRef(); return *this;}
template <class QI> HRESULT QueryInterface(QI** pp) const {
return p->QueryInterface(__uuidof(QI), (void**)pp);}
HRESULT CoCreateInstance(const GUID & g, IUnknown* u=NULL, unsigned long
c=CLSCTX_ALL) {
return ::CoCreateInstance(g, u, c, __uuidof(IU), (void**)&p);}
~CComPtr() {
Release();}
};
template <class IU, const GUID & g = __uuidof(IU)>
class CComQIPtr : public CComPtr<IU>
{
public:
CComQIPtr(IUnknown* q) {
if (q != NULL) q->QueryInterface(g, (void **)&p);}
};
class CComVariant : public VARIANT
{
public:
CComVariant()
{VariantInit(this);}
~CComVariant()
{VariantClear(this);}
};
</quote>
I use this instead of <atlbase.h>
Gingko