1 /*****************************************************************************
2 * utils.h: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
31 extern char *CStrFromBSTR(UINT codePage, BSTR bstr);
32 extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s);
34 extern char *CStrFromGUID(REFGUID clsid);
37 extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
40 extern HDC CreateDevDC(DVTARGETDEVICE *ptd);
41 extern void DPFromHimetric(HDC hdc, LPPOINT pt, int count);
42 extern void HimetricFromDP(HDC hdc, LPPOINT pt, int count);
44 /**************************************************************************************************/
47 template<class T> class VLCEnum : IUnknown
52 VLCEnum(REFIID riid, std::vector<T> &);
53 VLCEnum(const VLCEnum<T> &);
54 virtual ~VLCEnum() {};
56 VLCEnum<T>& operator=(const VLCEnum<T> &t);
59 STDMETHODIMP QueryInterface(REFIID riid, void **);
60 STDMETHODIMP_(ULONG) AddRef(void);
61 STDMETHODIMP_(ULONG) Release(void);
64 STDMETHODIMP Next(ULONG, T *, ULONG *);
65 STDMETHODIMP Skip(ULONG);
66 STDMETHODIMP Reset(void);
67 // cloning is implemented by subclasses and must use copy constructor
68 //STDMETHODIMP Clone(VLCEnum<T> **);
70 typedef void (*retainer)(T);
72 void setRetainOperation(retainer retain) { _retain = retain; };
78 typename std::vector<T>::iterator _i;
84 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
94 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
103 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
106 this->_riid = e._riid;
113 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
117 if( (IID_IUnknown == riid)
121 *ppv = reinterpret_cast<LPVOID>(this);
125 return E_NOINTERFACE;
129 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
131 return InterlockedIncrement(&_refcount);
135 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
137 ULONG refcount = InterlockedDecrement(&_refcount);
147 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
152 if( (celt > 1) && (NULL == pceltFetched) )
156 typename std::vector<T>::iterator end = _v.end();
158 while( (c < celt) && (_i != end) )
161 if( NULL != _retain ) _retain(rgelt[c]);
166 if( NULL != pceltFetched )
169 return (c == celt) ? S_OK : S_FALSE;
173 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
176 typename std::vector<T>::iterator end = _v.end();
178 while( (c < celt) && (_i != end) )
183 return (c == celt) ? S_OK : S_FALSE;
187 STDMETHODIMP VLCEnum<T>::Reset(void)