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 /**************************************************************************************************/
46 /* this function object is used to dereference the iterator into a value */
47 template <class T, class Iterator>
50 T operator()(const Iterator& i) const
56 template<REFIID EnumeratorIID, class Enumerator, class T, class Iterator, typename Dereference = VLCDereference<T, Iterator> >
57 class VLCEnumIterator : public Enumerator
62 VLCEnumIterator(const Iterator& from, const Iterator& to) :
69 VLCEnumIterator(const VLCEnumIterator& e) :
71 _refcount(e._refcount),
77 virtual ~VLCEnumIterator()
81 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
85 if( (IID_IUnknown == riid)
86 || (EnumeratorIID == riid) )
89 *ppv = reinterpret_cast<LPVOID>(this);
96 STDMETHODIMP_(ULONG) AddRef(void)
98 return InterlockedIncrement(&_refcount);
101 STDMETHODIMP_(ULONG) Release(void)
103 ULONG refcount = InterlockedDecrement(&_refcount);
114 STDMETHODIMP Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
119 if( (celt > 1) && (NULL == pceltFetched) )
124 while( (c < celt) && (_curr != _end) )
126 rgelt[c] = dereference(_curr);
131 if( NULL != pceltFetched )
134 return (c == celt) ? S_OK : S_FALSE;
137 STDMETHODIMP Skip(ULONG celt)
141 while( (c < celt) && (_curr != _end) )
146 return (c == celt) ? S_OK : S_FALSE;
149 STDMETHODIMP Reset(void)
155 STDMETHODIMP Clone(Enumerator **ppEnum)
159 *ppEnum = dynamic_cast<Enumerator *>(new VLCEnumIterator(*this));
160 return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
166 Iterator _begin, _curr, _end;
168 Dereference dereference;