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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
31 extern char *CStrFromBSTR(int codePage, BSTR bstr);
32 extern BSTR BSTRFromCStr(int codePage, const char *s);
35 extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
38 extern HDC CreateDevDC(DVTARGETDEVICE *ptd);
41 template<class T> class VLCEnum : IUnknown
46 VLCEnum(REFIID riid, std::vector<T> &);
47 VLCEnum(const VLCEnum<T> &);
48 virtual ~VLCEnum() {};
50 VLCEnum<T>& operator=(const VLCEnum<T> &t);
53 STDMETHODIMP QueryInterface(REFIID riid, void **);
54 STDMETHODIMP_(ULONG) AddRef(void);
55 STDMETHODIMP_(ULONG) Release(void);
58 STDMETHODIMP Next(ULONG, T *, ULONG *);
59 STDMETHODIMP Skip(ULONG);
60 STDMETHODIMP Reset(void);
61 // cloning is implemented by subclasses and must use copy constructor
62 //STDMETHODIMP Clone(VLCEnum<T> **);
64 typedef void (*retainer)(T);
66 void setRetainOperation(retainer retain) { _retain = retain; };
72 typename std::vector<T>::iterator _i;
78 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
88 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
96 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
99 this->_riid = e._riid;
105 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
107 if( NULL == ppv ) return E_POINTER;
108 if( (IID_IUnknown == riid)
109 && ( _riid == riid) ) {
111 *ppv = reinterpret_cast<LPVOID>(this);
114 return E_NOINTERFACE;
118 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
120 return InterlockedIncrement(&_refcount);
124 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
126 ULONG refcount = InterlockedDecrement(&_refcount);
136 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
141 if( (celt > 1) && (NULL == pceltFetched) )
145 typename std::vector<T>::iterator end = _v.end();
147 while( (c < celt) && (_i != end) )
150 if( NULL != _retain ) _retain(rgelt[c]);
155 if( NULL != pceltFetched )
158 return (c == celt) ? S_OK : S_FALSE;
162 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
165 typename std::vector<T>::iterator end = _v.end();
167 while( (c < celt) && (_i != end) )
172 return (c == celt) ? S_OK : S_FALSE;
176 STDMETHODIMP VLCEnum<T>::Reset(void)