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
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
;
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
,
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
;
69 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
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
);
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
);
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
);
122 static HRESULT WINAPI
PropertyBag_CountProperties(IPropertyBag2
*iface
, ULONG
*pcProperties
)
124 PropertyBag
*This
= impl_from_IPropertyBag2(iface
);
126 TRACE("(%p,%p)\n", iface
, pcProperties
);
131 *pcProperties
= This
->prop_count
;
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
;
144 dest
->pstrName
= CoTaskMemAlloc((strlenW(src
->pstrName
)+1) * sizeof(WCHAR
));
146 dest
->pstrName
= HeapAlloc(GetProcessHeap(), 0, (strlenW(src
->pstrName
)+1) * sizeof(WCHAR
));
149 return E_OUTOFMEMORY
;
151 strcpyW(dest
->pstrName
, src
->pstrName
);
156 static HRESULT WINAPI
PropertyBag_GetPropertyInfo(IPropertyBag2
*iface
, ULONG iProperty
,
157 ULONG cProperties
, PROPBAG2
*pPropBag
, ULONG
*pcProperties
)
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
);
178 CoTaskMemFree( pPropBag
[--i
].pstrName
);
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
);
194 static const IPropertyBag2Vtbl PropertyBag_Vtbl
= {
195 PropertyBag_QueryInterface
,
200 PropertyBag_CountProperties
,
201 PropertyBag_GetPropertyInfo
,
202 PropertyBag_LoadObject
205 HRESULT
CreatePropertyBag2(PROPBAG2
*options
, UINT count
,
206 IPropertyBag2
**ppPropertyBag2
)
212 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(PropertyBag
));
213 if (!This
) return E_OUTOFMEMORY
;
215 This
->IPropertyBag2_iface
.lpVtbl
= &PropertyBag_Vtbl
;
217 This
->prop_count
= count
;
221 This
->properties
= NULL
;
225 This
->properties
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PROPBAG2
)*count
);
227 if (!This
->properties
)
230 for (i
=0; i
< count
; i
++)
232 res
= copy_propbag2(This
->properties
+i
, options
+i
, FALSE
);
235 This
->properties
[i
].dwHint
= i
+1; /* 0 means unset, so we start with 1 */
241 PropertyBag_Release(&This
->IPropertyBag2_iface
);
242 *ppPropertyBag2
= NULL
;
245 *ppPropertyBag2
= &This
->IPropertyBag2_iface
;