ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

enumregfilters.c
Go to the documentation of this file.
00001 /*
00002  * Implementation of IEnumRegFilters Interface
00003  *
00004  * Copyright 2004 Christian Costa
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "quartz_private.h"
00022 
00023 #include "wine/unicode.h"
00024 
00025 #include "wine/debug.h"
00026 
00027 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
00028 
00029 typedef struct IEnumRegFiltersImpl
00030 {
00031     const IEnumRegFiltersVtbl * lpVtbl;
00032     LONG refCount;
00033     ULONG size;
00034     REGFILTER* RegFilters;
00035     ULONG uIndex;
00036 } IEnumRegFiltersImpl;
00037 
00038 static const struct IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl;
00039 
00040 HRESULT IEnumRegFiltersImpl_Construct(REGFILTER* pInRegFilters, const ULONG size, IEnumRegFilters ** ppEnum)
00041 {
00042     IEnumRegFiltersImpl* pEnumRegFilters;
00043     REGFILTER* pRegFilters = NULL;
00044     unsigned int i;
00045 
00046     TRACE("(%p, %d, %p)\n", pInRegFilters, size, ppEnum);
00047 
00048     pEnumRegFilters = CoTaskMemAlloc(sizeof(IEnumRegFiltersImpl));
00049     if (!pEnumRegFilters)
00050     {
00051         *ppEnum = NULL;
00052         return E_OUTOFMEMORY;
00053     }
00054 
00055     /* Accept size of 0 */
00056     if (size)
00057     {
00058         pRegFilters = CoTaskMemAlloc(sizeof(REGFILTER)*size);
00059         if (!pRegFilters)
00060     {
00061             CoTaskMemFree(pEnumRegFilters);
00062             *ppEnum = NULL;
00063            return E_OUTOFMEMORY;
00064         }
00065     }
00066 
00067     for(i = 0; i < size; i++)
00068     {
00069         pRegFilters[i].Clsid = pInRegFilters[i].Clsid;
00070         pRegFilters[i].Name = CoTaskMemAlloc((strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
00071         if (!pRegFilters[i].Name)
00072         {
00073             while(i)
00074                 CoTaskMemFree(pRegFilters[--i].Name);
00075             CoTaskMemFree(pRegFilters);
00076             CoTaskMemFree(pEnumRegFilters);
00077             return E_OUTOFMEMORY;
00078         }
00079         CopyMemory(pRegFilters[i].Name, pInRegFilters[i].Name, (strlenW(pInRegFilters[i].Name)+1)*sizeof(WCHAR));
00080     }
00081 
00082     pEnumRegFilters->lpVtbl = &IEnumRegFiltersImpl_Vtbl;
00083     pEnumRegFilters->refCount = 1;
00084     pEnumRegFilters->uIndex = 0;
00085     pEnumRegFilters->RegFilters = pRegFilters;
00086     pEnumRegFilters->size = size;
00087 
00088     *ppEnum = (IEnumRegFilters *)(&pEnumRegFilters->lpVtbl);
00089 
00090     return S_OK;
00091 }
00092 
00093 static HRESULT WINAPI IEnumRegFiltersImpl_QueryInterface(IEnumRegFilters * iface, REFIID riid, LPVOID * ppv)
00094 {
00095     TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
00096 
00097     *ppv = NULL;
00098 
00099     if (IsEqualIID(riid, &IID_IUnknown))
00100         *ppv = iface;
00101     else if (IsEqualIID(riid, &IID_IEnumRegFilters))
00102         *ppv = iface;
00103 
00104     if (*ppv)
00105     {
00106         IUnknown_AddRef((IUnknown *)(*ppv));
00107         return S_OK;
00108     }
00109 
00110     FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
00111 
00112     return E_NOINTERFACE;
00113 }
00114 
00115 static ULONG WINAPI IEnumRegFiltersImpl_AddRef(IEnumRegFilters * iface)
00116 {
00117     IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
00118     ULONG refCount = InterlockedIncrement(&This->refCount);
00119 
00120     TRACE("(%p)\n", iface);
00121 
00122     return refCount;
00123 }
00124 
00125 static ULONG WINAPI IEnumRegFiltersImpl_Release(IEnumRegFilters * iface)
00126 {
00127     IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
00128     ULONG refCount = InterlockedDecrement(&This->refCount);
00129 
00130     TRACE("(%p)\n", iface);
00131 
00132     if (!refCount)
00133     {
00134         ULONG i;
00135 
00136         for(i = 0; i < This->size; i++)
00137         {
00138             CoTaskMemFree(This->RegFilters[i].Name);
00139         }
00140         CoTaskMemFree(This->RegFilters);
00141         CoTaskMemFree(This);
00142         return 0;
00143     } else
00144         return refCount;
00145 }
00146 
00147 static HRESULT WINAPI IEnumRegFiltersImpl_Next(IEnumRegFilters * iface, ULONG cFilters, REGFILTER ** ppRegFilter, ULONG * pcFetched)
00148 {
00149     ULONG cFetched; 
00150     IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
00151     unsigned int i;
00152 
00153     cFetched = min(This->size, This->uIndex + cFilters) - This->uIndex;
00154 
00155     TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppRegFilter, pcFetched);
00156 
00157     if (cFetched > 0)
00158     {
00159         for(i = 0; i < cFetched; i++)
00160         {
00161             /* The string in the REGFILTER structure must be allocated in the same block as the REGFILTER structure itself */
00162             ppRegFilter[i] = CoTaskMemAlloc(sizeof(REGFILTER)+(strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
00163             if (!ppRegFilter[i])
00164             {
00165                 while(i)
00166                 {
00167                     CoTaskMemFree(ppRegFilter[--i]);
00168                     ppRegFilter[i] = NULL;
00169                 }
00170                 return E_OUTOFMEMORY;
00171         }
00172             ppRegFilter[i]->Clsid = This->RegFilters[This->uIndex + i].Clsid;
00173             ppRegFilter[i]->Name = (WCHAR*)((char*)ppRegFilter[i]+sizeof(REGFILTER));
00174             CopyMemory(ppRegFilter[i]->Name, This->RegFilters[This->uIndex + i].Name,
00175                             (strlenW(This->RegFilters[This->uIndex + i].Name)+1)*sizeof(WCHAR));
00176         }
00177 
00178         This->uIndex += cFetched;
00179         if (pcFetched)
00180             *pcFetched = cFetched;
00181         return S_OK;
00182     }
00183 
00184     return S_FALSE;
00185 }
00186 
00187 static HRESULT WINAPI IEnumRegFiltersImpl_Skip(IEnumRegFilters * iface, ULONG n)
00188 {
00189     TRACE("(%p)->(%u)\n", iface, n);
00190 
00191     return E_NOTIMPL;
00192 }
00193 
00194 static HRESULT WINAPI IEnumRegFiltersImpl_Reset(IEnumRegFilters * iface)
00195 {
00196     IEnumRegFiltersImpl *This = (IEnumRegFiltersImpl *)iface;
00197 
00198     TRACE("(%p)\n", iface);
00199 
00200     This->uIndex = 0;
00201     return S_OK;
00202 }
00203 
00204 static HRESULT WINAPI IEnumRegFiltersImpl_Clone(IEnumRegFilters * iface, IEnumRegFilters ** ppEnum)
00205 {
00206     TRACE("(%p)->(%p)\n", iface, ppEnum);
00207 
00208     return E_NOTIMPL;
00209 }
00210 
00211 static const IEnumRegFiltersVtbl IEnumRegFiltersImpl_Vtbl =
00212 {
00213     IEnumRegFiltersImpl_QueryInterface,
00214     IEnumRegFiltersImpl_AddRef,
00215     IEnumRegFiltersImpl_Release,
00216     IEnumRegFiltersImpl_Next,
00217     IEnumRegFiltersImpl_Skip,
00218     IEnumRegFiltersImpl_Reset,
00219     IEnumRegFiltersImpl_Clone
00220 };

Generated on Sat May 26 2012 04:20:28 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.