1 /*****************************************************************************
2 * utils.h: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
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> **);
63 // cloning is implemented by subclasses and must use copy constructor
65 typedef void (*retainer)(T);
67 void setRetainOperation(retainer retain) { _retain = retain; };
73 typename std::vector<T>::iterator _i;
79 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
89 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
97 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
100 this->_riid = e._riid;
106 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
108 if( NULL == ppv ) return E_POINTER;
109 if( (IID_IUnknown == riid)
110 && ( _riid == riid) ) {
112 *ppv = reinterpret_cast<LPVOID>(this);
115 return E_NOINTERFACE;
119 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
121 return InterlockedIncrement(&_refcount);
125 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
127 ULONG refcount = InterlockedDecrement(&_refcount);
137 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
142 if( (celt > 1) && (NULL == pceltFetched) )
146 typename std::vector<T>::iterator end = _v.end();
148 while( (c < celt) && (_i != end) )
151 if( NULL != _retain ) _retain(rgelt[c]);
156 if( NULL != pceltFetched )
159 return (c == celt) ? S_OK : S_FALSE;
163 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
166 typename std::vector<T>::iterator end = _v.end();
168 while( (c < celt) && (_i != end) )
173 return (c == celt) ? S_OK : S_FALSE;
177 STDMETHODIMP VLCEnum<T>::Reset(void)