|
|
|
@ -10,6 +10,95 @@ |
|
|
|
|
|
|
|
__IID_DEF(IUnknown, 0, 0, 0, C0, 00, 00, 00, 00, 00, 00, 46); |
|
|
|
|
|
|
|
template<class TInterface> |
|
|
|
class ComPtr |
|
|
|
{ |
|
|
|
private: |
|
|
|
TInterface* _obj; |
|
|
|
public: |
|
|
|
ComPtr() |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
} |
|
|
|
|
|
|
|
ComPtr(TInterface* pObj) |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
|
|
|
|
if (pObj) |
|
|
|
{ |
|
|
|
_obj = pObj; |
|
|
|
_obj->AddRef(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ComPtr(const ComPtr& ptr) |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
|
|
|
|
if (ptr._obj) |
|
|
|
{ |
|
|
|
_obj = ptr._obj; |
|
|
|
_obj->AddRef(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ComPtr& operator=(ComPtr other) |
|
|
|
{ |
|
|
|
if(_obj != NULL) |
|
|
|
_obj->Release(); |
|
|
|
_obj = other._obj; |
|
|
|
if(_obj != NULL) |
|
|
|
_obj->AddRef(); |
|
|
|
return *this; |
|
|
|
} |
|
|
|
|
|
|
|
~ComPtr() |
|
|
|
{ |
|
|
|
if (_obj) |
|
|
|
{ |
|
|
|
_obj->Release(); |
|
|
|
_obj = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TInterface* getRaw() |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
|
|
|
|
TInterface* getRetainedReference() |
|
|
|
{ |
|
|
|
if(_obj == NULL) |
|
|
|
return NULL; |
|
|
|
_obj->AddRef(); |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
|
|
|
|
TInterface** getPPV() |
|
|
|
{ |
|
|
|
return &_obj; |
|
|
|
} |
|
|
|
|
|
|
|
operator TInterface*() const |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
TInterface& operator*() const |
|
|
|
{ |
|
|
|
return *_obj; |
|
|
|
} |
|
|
|
TInterface** operator&() |
|
|
|
{ |
|
|
|
return &_obj; |
|
|
|
} |
|
|
|
TInterface* operator->() const |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
class ComObject : public virtual IUnknown |
|
|
|
{ |
|
|
|
private: |
|
|
|
@ -58,6 +147,12 @@ public: |
|
|
|
_refCount++; |
|
|
|
return S_OK; |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
|
ComPtr<IUnknown> UnknownSelf() |
|
|
|
{ |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
@ -104,94 +199,5 @@ public: |
|
|
|
virtual ~ComSingleObject(){} |
|
|
|
}; |
|
|
|
|
|
|
|
template<class TInterface> |
|
|
|
class ComPtr |
|
|
|
{ |
|
|
|
private: |
|
|
|
TInterface* _obj; |
|
|
|
public: |
|
|
|
ComPtr() |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
} |
|
|
|
|
|
|
|
ComPtr(TInterface* pObj) |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
|
|
|
|
if (pObj) |
|
|
|
{ |
|
|
|
_obj = pObj; |
|
|
|
_obj->AddRef(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ComPtr(const ComPtr& ptr) |
|
|
|
{ |
|
|
|
_obj = 0; |
|
|
|
|
|
|
|
if (ptr._obj) |
|
|
|
{ |
|
|
|
_obj = ptr._obj; |
|
|
|
_obj->AddRef(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ComPtr& operator=(ComPtr other) |
|
|
|
{ |
|
|
|
if(_obj != NULL) |
|
|
|
_obj->Release(); |
|
|
|
_obj = other._obj; |
|
|
|
if(_obj != NULL) |
|
|
|
_obj->AddRef(); |
|
|
|
return *this; |
|
|
|
} |
|
|
|
|
|
|
|
~ComPtr() |
|
|
|
{ |
|
|
|
if (_obj) |
|
|
|
{ |
|
|
|
_obj->Release(); |
|
|
|
_obj = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TInterface* getRaw() |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
|
|
|
|
TInterface* getRetainedReference() |
|
|
|
{ |
|
|
|
if(_obj == NULL) |
|
|
|
return NULL; |
|
|
|
_obj->AddRef(); |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
|
|
|
|
TInterface** getPPV() |
|
|
|
{ |
|
|
|
return &_obj; |
|
|
|
} |
|
|
|
|
|
|
|
operator TInterface*() const |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
TInterface& operator*() const |
|
|
|
{ |
|
|
|
return *_obj; |
|
|
|
} |
|
|
|
TInterface** operator&() |
|
|
|
{ |
|
|
|
return &_obj; |
|
|
|
} |
|
|
|
TInterface* operator->() const |
|
|
|
{ |
|
|
|
return _obj; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
#endif // COMIMPL_H_INCLUDED
|
|
|
|
#pragma clang diagnostic pop |
|
|
|
|