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 *CStrFromWSTR(UINT codePage, LPCWSTR wstr, UINT len);
32 extern char *CStrFromBSTR(UINT codePage, BSTR bstr);
33 extern BSTR BSTRFromCStr(UINT codePage, LPCSTR s);
36 extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
39 extern HDC CreateDevDC(DVTARGETDEVICE *ptd);
40 extern void DPFromHimetric(HDC hdc, LPPOINT pt, int count);
41 extern void HimetricFromDP(HDC hdc, LPPOINT pt, int count);
44 extern LPWSTR CombineURL(LPCWSTR baseUrl, LPCWSTR url);
46 /**************************************************************************************************/
48 /* this function object is used to dereference the iterator into a value */
49 template <typename T, class Iterator>
52 T operator()(const Iterator& i) const
58 template<REFIID EnumeratorIID, class Enumerator, typename T, class Iterator, typename Dereference = VLCDereference<T, Iterator> >
59 class VLCEnumIterator : public Enumerator
64 VLCEnumIterator(const Iterator& from, const Iterator& to) :
71 VLCEnumIterator(const VLCEnumIterator& e) :
73 _refcount(e._refcount),
79 virtual ~VLCEnumIterator()
83 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
87 if( (IID_IUnknown == riid)
88 || (EnumeratorIID == riid) )
91 *ppv = reinterpret_cast<LPVOID>(this);
98 STDMETHODIMP_(ULONG) AddRef(void)
100 return InterlockedIncrement(&_refcount);
103 STDMETHODIMP_(ULONG) Release(void)
105 ULONG refcount = InterlockedDecrement(&_refcount);
116 STDMETHODIMP Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
121 if( (celt > 1) && (NULL == pceltFetched) )
126 while( (c < celt) && (_curr != _end) )
128 rgelt[c] = dereference(_curr);
133 if( NULL != pceltFetched )
136 return (c == celt) ? S_OK : S_FALSE;
139 STDMETHODIMP Skip(ULONG celt)
143 while( (c < celt) && (_curr != _end) )
148 return (c == celt) ? S_OK : S_FALSE;
151 STDMETHODIMP Reset(void)
157 STDMETHODIMP Clone(Enumerator **ppEnum)
161 *ppEnum = dynamic_cast<Enumerator *>(new VLCEnumIterator(*this));
162 return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
168 Iterator _begin, _curr, _end;
170 Dereference dereference;