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);
39 extern void DPFromHimetric(HDC hdc, LPPOINT pt, int count);
40 extern void HimetricFromDP(HDC hdc, LPPOINT pt, int count);
44 template<class T> class VLCEnum : IUnknown
49 VLCEnum(REFIID riid, std::vector<T> &);
50 VLCEnum(const VLCEnum<T> &);
51 virtual ~VLCEnum() {};
53 VLCEnum<T>& operator=(const VLCEnum<T> &t);
56 STDMETHODIMP QueryInterface(REFIID riid, void **);
57 STDMETHODIMP_(ULONG) AddRef(void);
58 STDMETHODIMP_(ULONG) Release(void);
61 STDMETHODIMP Next(ULONG, T *, ULONG *);
62 STDMETHODIMP Skip(ULONG);
63 STDMETHODIMP Reset(void);
64 // cloning is implemented by subclasses and must use copy constructor
65 //STDMETHODIMP Clone(VLCEnum<T> **);
67 typedef void (*retainer)(T);
69 void setRetainOperation(retainer retain) { _retain = retain; };
75 typename std::vector<T>::iterator _i;
81 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
91 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
99 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
102 this->_riid = e._riid;
109 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
111 if( NULL == ppv ) return E_POINTER;
112 if( (IID_IUnknown == riid)
113 && ( _riid == riid) ) {
115 *ppv = reinterpret_cast<LPVOID>(this);
118 return E_NOINTERFACE;
122 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
124 return InterlockedIncrement(&_refcount);
128 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
130 ULONG refcount = InterlockedDecrement(&_refcount);
140 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
145 if( (celt > 1) && (NULL == pceltFetched) )
149 typename std::vector<T>::iterator end = _v.end();
151 while( (c < celt) && (_i != end) )
154 if( NULL != _retain ) _retain(rgelt[c]);
159 if( NULL != pceltFetched )
162 return (c == celt) ? S_OK : S_FALSE;
166 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
169 typename std::vector<T>::iterator end = _v.end();
171 while( (c < celt) && (_i != end) )
176 return (c == celt) ? S_OK : S_FALSE;
180 STDMETHODIMP VLCEnum<T>::Reset(void)