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);
46 template<class T> class VLCEnum : IUnknown
51 VLCEnum(REFIID riid, std::vector<T> &);
52 VLCEnum(const VLCEnum<T> &);
53 virtual ~VLCEnum() {};
55 VLCEnum<T>& operator=(const VLCEnum<T> &t);
58 STDMETHODIMP QueryInterface(REFIID riid, void **);
59 STDMETHODIMP_(ULONG) AddRef(void);
60 STDMETHODIMP_(ULONG) Release(void);
63 STDMETHODIMP Next(ULONG, T *, ULONG *);
64 STDMETHODIMP Skip(ULONG);
65 STDMETHODIMP Reset(void);
66 // cloning is implemented by subclasses and must use copy constructor
67 //STDMETHODIMP Clone(VLCEnum<T> **);
69 typedef void (*retainer)(T);
71 void setRetainOperation(retainer retain) { _retain = retain; };
77 typename std::vector<T>::iterator _i;
83 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
93 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
101 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
104 this->_riid = e._riid;
111 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
115 if( (IID_IUnknown == riid)
119 *ppv = reinterpret_cast<LPVOID>(this);
123 return E_NOINTERFACE;
127 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
129 return InterlockedIncrement(&_refcount);
133 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
135 ULONG refcount = InterlockedDecrement(&_refcount);
145 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
150 if( (celt > 1) && (NULL == pceltFetched) )
154 typename std::vector<T>::iterator end = _v.end();
156 while( (c < celt) && (_i != end) )
159 if( NULL != _retain ) _retain(rgelt[c]);
164 if( NULL != pceltFetched )
167 return (c == celt) ? S_OK : S_FALSE;
171 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
174 typename std::vector<T>::iterator end = _v.end();
176 while( (c < celt) && (_i != end) )
181 return (c == celt) ? S_OK : S_FALSE;
185 STDMETHODIMP VLCEnum<T>::Reset(void)