-#define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \
-class wxAutoOleInterface \
-{ \
- protected: \
- I *m_interface; \
-\
- public: \
- explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \
- wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \
- { QueryInterface(riid, pUnk); } \
- wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \
- { QueryInterface(riid, pDispatch); } \
- wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\
- { CreateInstance(clsid, riid); }\
- wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\
- { operator = (ti); }\
-\
- wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\
- {\
- if (ti.m_interface)\
- ti.m_interface->AddRef();\
- Free();\
- m_interface = ti.m_interface;\
- return *this;\
- }\
-\
- wxAutoOleInterface& operator = (I *&ti)\
- {\
- Free();\
- m_interface = ti;\
- return *this;\
- }\
-\
- ~wxAutoOleInterface() { Free(); }\
-\
- inline void Free()\
- {\
- if (m_interface)\
- m_interface->Release();\
- m_interface = NULL;\
- }\
-\
- HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\
- {\
- Free();\
- wxASSERT(pUnk != NULL);\
- return pUnk->QueryInterface(riid, (void **) &m_interface);\
- }\
-\
- HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\
- {\
- Free();\
- return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\
- }\
-\
- inline operator I *() const {return m_interface;}\
- inline I* operator ->() {return m_interface;}\
- inline I** GetRef() {return &m_interface;}\
- inline bool Ok() const { return IsOk(); }
- inline bool IsOk() const {return m_interface != NULL;}\
-};
+template<typename I>
+class wxAutoOleInterface
+{
+public:
+ typedef I Interface;
+
+ explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface)
+ {}
+ wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL)
+ { QueryInterface(riid, pUnk); }
+ wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL)
+ { QueryInterface(riid, pDispatch); }
+ wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)
+ { CreateInstance(clsid, riid); }
+ wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)
+ { operator=(ti); }
+
+ wxAutoOleInterface& operator=(const wxAutoOleInterface& ti)
+ {
+ if ( ti.m_interface )
+ ti.m_interface->AddRef();
+ Free();
+ m_interface = ti.m_interface;
+ return *this;
+ }
+
+ wxAutoOleInterface& operator=(I*& ti)
+ {
+ Free();
+ m_interface = ti;
+ return *this;
+ }