2009-08-11 23:10:12 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Vincent Povirk for CodeWeavers
|
2013-01-29 19:50:36 +01:00
|
|
|
* Copyright 2013 Ludger Sprenker
|
2009-08-11 23:10:12 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "wincodec.h"
|
2013-01-25 00:04:55 +01:00
|
|
|
#include "wine/unicode.h"
|
2009-08-11 23:10:12 +02:00
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
|
|
|
typedef struct PropertyBag {
|
2010-12-08 22:59:37 +01:00
|
|
|
IPropertyBag2 IPropertyBag2_iface;
|
2009-08-11 23:10:12 +02:00
|
|
|
LONG ref;
|
2013-01-23 23:35:19 +01:00
|
|
|
UINT prop_count;
|
2013-01-25 00:04:55 +01:00
|
|
|
PROPBAG2 *properties;
|
2013-01-25 00:05:08 +01:00
|
|
|
VARIANT *values;
|
2009-08-11 23:10:12 +02:00
|
|
|
} PropertyBag;
|
|
|
|
|
2010-12-08 22:59:37 +01:00
|
|
|
static inline PropertyBag *impl_from_IPropertyBag2(IPropertyBag2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, PropertyBag, IPropertyBag2_iface);
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
static HRESULT WINAPI PropertyBag_QueryInterface(IPropertyBag2 *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2010-12-08 22:59:37 +01:00
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IPropertyBag2, iid))
|
|
|
|
{
|
2012-07-24 08:15:15 +02:00
|
|
|
*ppv = &This->IPropertyBag2_iface;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PropertyBag_AddRef(IPropertyBag2 *iface)
|
|
|
|
{
|
2010-12-08 22:59:37 +01:00
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI PropertyBag_Release(IPropertyBag2 *iface)
|
|
|
|
{
|
2010-12-08 22:59:37 +01:00
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2013-01-25 00:04:55 +01:00
|
|
|
ULONG i;
|
2013-01-25 00:05:08 +01:00
|
|
|
if (This->properties && This->values)
|
2013-01-25 00:04:55 +01:00
|
|
|
{
|
|
|
|
for (i=0; i < This->prop_count; i++)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->properties[i].pstrName);
|
2013-01-25 00:05:08 +01:00
|
|
|
VariantClear( This->values+i );
|
2013-01-25 00:04:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->properties);
|
2013-01-25 00:05:08 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->values);
|
2009-08-11 23:10:12 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2013-01-25 00:05:08 +01:00
|
|
|
static LONG find_item(PropertyBag *This, LPCOLESTR name)
|
|
|
|
{
|
|
|
|
LONG i;
|
|
|
|
if (!This->properties)
|
|
|
|
return -1;
|
|
|
|
if (!name)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i=0; i < This->prop_count; i++)
|
|
|
|
{
|
|
|
|
if (strcmpW(name, This->properties[i].pstrName) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
static HRESULT WINAPI PropertyBag_Read(IPropertyBag2 *iface, ULONG cProperties,
|
|
|
|
PROPBAG2 *pPropBag, IErrorLog *pErrLog, VARIANT *pvarValue, HRESULT *phrError)
|
|
|
|
{
|
2013-01-25 00:05:15 +01:00
|
|
|
HRESULT res = S_OK;
|
|
|
|
ULONG i;
|
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p,%p,%p,%p)\n", iface, cProperties, pPropBag, pErrLog, pvarValue, phrError);
|
|
|
|
|
|
|
|
for (i=0; i < cProperties; i++)
|
|
|
|
{
|
|
|
|
LONG idx;
|
|
|
|
if (pPropBag[i].dwHint && pPropBag[i].dwHint <= This->prop_count)
|
|
|
|
idx = pPropBag[i].dwHint-1;
|
|
|
|
else
|
|
|
|
idx = find_item(This, pPropBag[i].pstrName);
|
|
|
|
|
|
|
|
if (idx > -1)
|
|
|
|
{
|
|
|
|
VariantInit(pvarValue+i);
|
|
|
|
res = VariantCopy(pvarValue+i, This->values+idx);
|
|
|
|
if (FAILED(res))
|
|
|
|
break;
|
|
|
|
phrError[i] = res;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = E_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PropertyBag_Write(IPropertyBag2 *iface, ULONG cProperties,
|
|
|
|
PROPBAG2 *pPropBag, VARIANT *pvarValue)
|
|
|
|
{
|
2013-01-25 00:05:08 +01:00
|
|
|
HRESULT res = S_OK;
|
|
|
|
ULONG i;
|
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p,%p)\n", iface, cProperties, pPropBag, pvarValue);
|
|
|
|
|
|
|
|
for (i=0; i < cProperties; i++)
|
|
|
|
{
|
|
|
|
LONG idx;
|
|
|
|
if (pPropBag[i].dwHint && pPropBag[i].dwHint <= This->prop_count)
|
|
|
|
idx = pPropBag[i].dwHint-1;
|
|
|
|
else
|
|
|
|
idx = find_item(This, pPropBag[i].pstrName);
|
|
|
|
|
|
|
|
if (idx > -1)
|
|
|
|
{
|
|
|
|
if (This->properties[idx].vt != V_VT(pvarValue+i))
|
|
|
|
return WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE;
|
|
|
|
res = VariantCopy(This->values+idx, pvarValue+i);
|
|
|
|
if (FAILED(res))
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pPropBag[i].pstrName)
|
|
|
|
FIXME("Application tried to set the unknown option %s.\n",
|
|
|
|
debugstr_w(pPropBag[i].pstrName));
|
|
|
|
|
|
|
|
/* FIXME: Function is not atomar on error, but MSDN does not say anything about it
|
|
|
|
* (no reset of items between 0 and i-1) */
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PropertyBag_CountProperties(IPropertyBag2 *iface, ULONG *pcProperties)
|
|
|
|
{
|
2013-01-23 23:35:19 +01:00
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pcProperties);
|
|
|
|
|
|
|
|
if (!pcProperties)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pcProperties = This->prop_count;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 00:04:55 +01:00
|
|
|
static HRESULT copy_propbag2(PROPBAG2 *dest, PROPBAG2 *src, BOOL useCoAlloc)
|
|
|
|
{
|
|
|
|
dest->cfType = src->cfType;
|
|
|
|
dest->clsid = src->clsid;
|
|
|
|
dest->dwHint = src->dwHint;
|
|
|
|
dest->dwType = src->dwType;
|
|
|
|
dest->vt = src->vt;
|
|
|
|
if(useCoAlloc)
|
|
|
|
dest->pstrName = CoTaskMemAlloc((strlenW(src->pstrName)+1) * sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
dest->pstrName = HeapAlloc(GetProcessHeap(), 0, (strlenW(src->pstrName)+1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if(!dest->pstrName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
strcpyW(dest->pstrName, src->pstrName);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
static HRESULT WINAPI PropertyBag_GetPropertyInfo(IPropertyBag2 *iface, ULONG iProperty,
|
|
|
|
ULONG cProperties, PROPBAG2 *pPropBag, ULONG *pcProperties)
|
|
|
|
{
|
2013-01-25 00:04:55 +01:00
|
|
|
HRESULT res = S_OK;
|
|
|
|
ULONG i;
|
|
|
|
PropertyBag *This = impl_from_IPropertyBag2(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%u,%p,%p)\n", iface, iProperty, cProperties, pPropBag, pcProperties);
|
|
|
|
|
|
|
|
if (iProperty >= This->prop_count && iProperty > 0)
|
|
|
|
return WINCODEC_ERR_VALUEOUTOFRANGE;
|
|
|
|
if (iProperty+cProperties > This->prop_count )
|
|
|
|
return WINCODEC_ERR_VALUEOUTOFRANGE;
|
|
|
|
|
2014-08-07 02:41:09 +02:00
|
|
|
*pcProperties = min(cProperties, This->prop_count-iProperty);
|
2013-01-25 00:04:55 +01:00
|
|
|
|
|
|
|
for (i=0; i < *pcProperties; i++)
|
|
|
|
{
|
|
|
|
res = copy_propbag2(pPropBag+i, This->properties+iProperty+i, TRUE);
|
|
|
|
if (FAILED(res))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
CoTaskMemFree( pPropBag[--i].pstrName );
|
|
|
|
} while (i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PropertyBag_LoadObject(IPropertyBag2 *iface, LPCOLESTR pstrName,
|
|
|
|
DWORD dwHint, IUnknown *pUnkObject, IErrorLog *pErrLog)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%s,%u,%p,%p): stub\n", iface, debugstr_w(pstrName), dwHint, pUnkObject, pErrLog);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IPropertyBag2Vtbl PropertyBag_Vtbl = {
|
|
|
|
PropertyBag_QueryInterface,
|
|
|
|
PropertyBag_AddRef,
|
|
|
|
PropertyBag_Release,
|
|
|
|
PropertyBag_Read,
|
|
|
|
PropertyBag_Write,
|
|
|
|
PropertyBag_CountProperties,
|
|
|
|
PropertyBag_GetPropertyInfo,
|
|
|
|
PropertyBag_LoadObject
|
|
|
|
};
|
|
|
|
|
2013-01-29 19:50:36 +01:00
|
|
|
HRESULT CreatePropertyBag2(PROPBAG2 *options, UINT count,
|
|
|
|
IPropertyBag2 **ppPropertyBag2)
|
2009-08-11 23:10:12 +02:00
|
|
|
{
|
2013-01-25 00:04:55 +01:00
|
|
|
UINT i;
|
|
|
|
HRESULT res = S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
PropertyBag *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(PropertyBag));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-08 22:59:37 +01:00
|
|
|
This->IPropertyBag2_iface.lpVtbl = &PropertyBag_Vtbl;
|
2009-08-11 23:10:12 +02:00
|
|
|
This->ref = 1;
|
2013-01-23 23:35:19 +01:00
|
|
|
This->prop_count = count;
|
2009-08-11 23:10:12 +02:00
|
|
|
|
2013-01-25 00:04:55 +01:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
This->properties = NULL;
|
2013-01-25 00:05:08 +01:00
|
|
|
This->values = NULL;
|
2013-01-25 00:04:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
This->properties = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROPBAG2)*count);
|
2013-01-25 00:05:08 +01:00
|
|
|
This->values = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VARIANT)*count);
|
2013-01-25 00:04:55 +01:00
|
|
|
|
2013-01-25 00:05:08 +01:00
|
|
|
if (!This->properties || !This->values)
|
2013-01-25 00:04:55 +01:00
|
|
|
res = E_OUTOFMEMORY;
|
|
|
|
else
|
|
|
|
for (i=0; i < count; i++)
|
|
|
|
{
|
|
|
|
res = copy_propbag2(This->properties+i, options+i, FALSE);
|
|
|
|
if (FAILED(res))
|
|
|
|
break;
|
|
|
|
This->properties[i].dwHint = i+1; /* 0 means unset, so we start with 1 */
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 23:10:12 +02:00
|
|
|
|
2013-01-25 00:04:55 +01:00
|
|
|
if (FAILED(res))
|
|
|
|
{
|
|
|
|
PropertyBag_Release(&This->IPropertyBag2_iface);
|
|
|
|
*ppPropertyBag2 = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppPropertyBag2 = &This->IPropertyBag2_iface;
|
|
|
|
|
|
|
|
return res;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|