// copied from ppxml sample #ifndef _UNKNOWN2_HXX #define _UNKNOWN2_HXX template class _simpleobj : public implementation { private: long _refcount; public: _simpleobj () { _refcount = 0; } virtual ~_simpleobj () { } virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppvObject) { if (riid == IID_IUnknown) { *ppvObject = static_cast(this); } else if (riid == __uuidof(derivedinterface)) { *ppvObject = static_cast(this); } else { *ppvObject = NULL; return E_NOINTERFACE; } reinterpret_cast(*ppvObject)->AddRef(); return S_OK; } virtual ULONG STDMETHODCALLTYPE AddRef( void) { return InterlockedIncrement(&_refcount); } virtual ULONG STDMETHODCALLTYPE Release( void) { if (InterlockedDecrement(&_refcount) == 0) { delete this; return 0; } return _refcount; } }; //=========================================================================== // This template implements the IUnknown portion of a given COM interface. template class _simpleunknown : public I { private: long _refcount; public: _simpleunknown () { _refcount = 0; } virtual ~_simpleunknown () { } virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppvObject) { if (riid == IID_IUnknown) { *ppvObject = static_cast(this); } else if (riid == __uuidof(I)) { *ppvObject = static_cast(this); } else { *ppvObject = NULL; return E_NOINTERFACE; } reinterpret_cast(*ppvObject)->AddRef(); return S_OK; } virtual ULONG STDMETHODCALLTYPE AddRef( void) { return InterlockedIncrement(&_refcount); } virtual ULONG STDMETHODCALLTYPE Release( void) { if (InterlockedDecrement(&_refcount) == 0) { delete this; return 0; } return _refcount; } }; #endif _UNKNOWN2_HXX