windowscodecs: Implement IPropertyBag2::GetPropertyInfo.
[wine.git] / dlls / windowscodecs / propertybag.c
blob077c600083740c723e71ca817fc75984ecd67833
1 /*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
3 * Copyright 2013 Ludger Sprenker
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "wincodec.h"
30 #include "wine/unicode.h"
32 #include "wincodecs_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
38 typedef struct PropertyBag {
39 IPropertyBag2 IPropertyBag2_iface;
40 LONG ref;
41 UINT prop_count;
42 PROPBAG2 *properties;
43 } PropertyBag;
45 static inline PropertyBag *impl_from_IPropertyBag2(IPropertyBag2 *iface)
47 return CONTAINING_RECORD(iface, PropertyBag, IPropertyBag2_iface);
50 static HRESULT WINAPI PropertyBag_QueryInterface(IPropertyBag2 *iface, REFIID iid,
51 void **ppv)
53 PropertyBag *This = impl_from_IPropertyBag2(iface);
54 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
56 if (!ppv) return E_INVALIDARG;
58 if (IsEqualIID(&IID_IUnknown, iid) ||
59 IsEqualIID(&IID_IPropertyBag2, iid))
61 *ppv = &This->IPropertyBag2_iface;
63 else
65 *ppv = NULL;
66 return E_NOINTERFACE;
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
73 static ULONG WINAPI PropertyBag_AddRef(IPropertyBag2 *iface)
75 PropertyBag *This = impl_from_IPropertyBag2(iface);
76 ULONG ref = InterlockedIncrement(&This->ref);
78 TRACE("(%p) refcount=%u\n", iface, ref);
80 return ref;
83 static ULONG WINAPI PropertyBag_Release(IPropertyBag2 *iface)
85 PropertyBag *This = impl_from_IPropertyBag2(iface);
86 ULONG ref = InterlockedDecrement(&This->ref);
88 TRACE("(%p) refcount=%u\n", iface, ref);
90 if (ref == 0)
92 ULONG i;
93 if (This->properties)
95 for (i=0; i < This->prop_count; i++)
97 HeapFree(GetProcessHeap(), 0, This->properties[i].pstrName);
101 HeapFree(GetProcessHeap(), 0, This->properties);
102 HeapFree(GetProcessHeap(), 0, This);
105 return ref;
108 static HRESULT WINAPI PropertyBag_Read(IPropertyBag2 *iface, ULONG cProperties,
109 PROPBAG2 *pPropBag, IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError)
111 FIXME("(%p,%u,%p,%p,%p,%p): stub\n", iface, cProperties, pPropBag, pErrLog, pvarValue, phrError);
112 return E_NOTIMPL;
115 static HRESULT WINAPI PropertyBag_Write(IPropertyBag2 *iface, ULONG cProperties,
116 PROPBAG2 *pPropBag, VARIANT *pvarValue)
118 FIXME("(%p,%u,%p,%p): stub\n", iface, cProperties, pPropBag, pvarValue);
119 return E_NOTIMPL;
122 static HRESULT WINAPI PropertyBag_CountProperties(IPropertyBag2 *iface, ULONG *pcProperties)
124 PropertyBag *This = impl_from_IPropertyBag2(iface);
126 TRACE("(%p,%p)\n", iface, pcProperties);
128 if (!pcProperties)
129 return E_INVALIDARG;
131 *pcProperties = This->prop_count;
133 return S_OK;
136 static HRESULT copy_propbag2(PROPBAG2 *dest, PROPBAG2 *src, BOOL useCoAlloc)
138 dest->cfType = src->cfType;
139 dest->clsid = src->clsid;
140 dest->dwHint = src->dwHint;
141 dest->dwType = src->dwType;
142 dest->vt = src->vt;
143 if(useCoAlloc)
144 dest->pstrName = CoTaskMemAlloc((strlenW(src->pstrName)+1) * sizeof(WCHAR));
145 else
146 dest->pstrName = HeapAlloc(GetProcessHeap(), 0, (strlenW(src->pstrName)+1) * sizeof(WCHAR));
148 if(!dest->pstrName)
149 return E_OUTOFMEMORY;
151 strcpyW(dest->pstrName, src->pstrName);
153 return S_OK;
156 static HRESULT WINAPI PropertyBag_GetPropertyInfo(IPropertyBag2 *iface, ULONG iProperty,
157 ULONG cProperties, PROPBAG2 *pPropBag, ULONG *pcProperties)
159 HRESULT res = S_OK;
160 ULONG i;
161 PropertyBag *This = impl_from_IPropertyBag2(iface);
163 TRACE("(%p,%u,%u,%p,%p)\n", iface, iProperty, cProperties, pPropBag, pcProperties);
165 if (iProperty >= This->prop_count && iProperty > 0)
166 return WINCODEC_ERR_VALUEOUTOFRANGE;
167 if (iProperty+cProperties > This->prop_count )
168 return WINCODEC_ERR_VALUEOUTOFRANGE;
170 *pcProperties = max(cProperties, This->prop_count-iProperty);
172 for (i=0; i < *pcProperties; i++)
174 res = copy_propbag2(pPropBag+i, This->properties+iProperty+i, TRUE);
175 if (FAILED(res))
177 do {
178 CoTaskMemFree( pPropBag[--i].pstrName );
179 } while (i);
180 break;
184 return res;
187 static HRESULT WINAPI PropertyBag_LoadObject(IPropertyBag2 *iface, LPCOLESTR pstrName,
188 DWORD dwHint, IUnknown *pUnkObject, IErrorLog *pErrLog)
190 FIXME("(%p,%s,%u,%p,%p): stub\n", iface, debugstr_w(pstrName), dwHint, pUnkObject, pErrLog);
191 return E_NOTIMPL;
194 static const IPropertyBag2Vtbl PropertyBag_Vtbl = {
195 PropertyBag_QueryInterface,
196 PropertyBag_AddRef,
197 PropertyBag_Release,
198 PropertyBag_Read,
199 PropertyBag_Write,
200 PropertyBag_CountProperties,
201 PropertyBag_GetPropertyInfo,
202 PropertyBag_LoadObject
205 HRESULT CreatePropertyBag2(PROPBAG2 *options, UINT count,
206 IPropertyBag2 **ppPropertyBag2)
208 UINT i;
209 HRESULT res = S_OK;
210 PropertyBag *This;
212 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PropertyBag));
213 if (!This) return E_OUTOFMEMORY;
215 This->IPropertyBag2_iface.lpVtbl = &PropertyBag_Vtbl;
216 This->ref = 1;
217 This->prop_count = count;
219 if (count == 0)
221 This->properties = NULL;
223 else
225 This->properties = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROPBAG2)*count);
227 if (!This->properties)
228 res = E_OUTOFMEMORY;
229 else
230 for (i=0; i < count; i++)
232 res = copy_propbag2(This->properties+i, options+i, FALSE);
233 if (FAILED(res))
234 break;
235 This->properties[i].dwHint = i+1; /* 0 means unset, so we start with 1 */
239 if (FAILED(res))
241 PropertyBag_Release(&This->IPropertyBag2_iface);
242 *ppPropertyBag2 = NULL;
244 else
245 *ppPropertyBag2 = &This->IPropertyBag2_iface;
247 return res;