From 0c8dc2bfba843b0be72c0d592d82e94dafce05d5 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 29 Mar 2018 20:50:23 +0200 Subject: [PATCH] windowscodecs: Use common base structure for component info implementations. Signed-off-by: Jacek Caban Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/windowscodecs/info.c | 148 ++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 77 deletions(-) diff --git a/dlls/windowscodecs/info.c b/dlls/windowscodecs/info.c index 6ddfdda25f1..6d3272e9557 100644 --- a/dlls/windowscodecs/info.c +++ b/dlls/windowscodecs/info.c @@ -56,6 +56,12 @@ static const WCHAR supportspadding_valuename[] = {'S','u','p','p','o','r','t','s static const WCHAR fileextensions_valuename[] = {'F','i','l','e','E','x','t','e','n','s','i','o','n','s',0}; static const WCHAR containers_keyname[] = {'C','o','n','t','a','i','n','e','r','s',0}; +typedef struct { + IWICComponentInfo IWICComponentInfo_iface; + LONG ref; + CLSID clsid; +} ComponentInfo; + static HRESULT ComponentInfo_GetStringValue(HKEY classkey, LPCWSTR value, UINT buffer_size, WCHAR *buffer, UINT *actual_size) { @@ -204,15 +210,13 @@ static HRESULT ComponentInfo_GetGuidList(HKEY classkey, LPCWSTR subkeyname, } typedef struct { - IWICBitmapDecoderInfo IWICBitmapDecoderInfo_iface; - LONG ref; + ComponentInfo base; HKEY classkey; - CLSID clsid; } BitmapDecoderInfo; static inline BitmapDecoderInfo *impl_from_IWICBitmapDecoderInfo(IWICBitmapDecoderInfo *iface) { - return CONTAINING_RECORD(iface, BitmapDecoderInfo, IWICBitmapDecoderInfo_iface); + return CONTAINING_RECORD(iface, BitmapDecoderInfo, base.IWICComponentInfo_iface); } static HRESULT WINAPI BitmapDecoderInfo_QueryInterface(IWICBitmapDecoderInfo *iface, REFIID iid, @@ -228,7 +232,7 @@ static HRESULT WINAPI BitmapDecoderInfo_QueryInterface(IWICBitmapDecoderInfo *if IsEqualIID(&IID_IWICBitmapCodecInfo, iid) || IsEqualIID(&IID_IWICBitmapDecoderInfo ,iid)) { - *ppv = &This->IWICBitmapDecoderInfo_iface; + *ppv = &This->base.IWICComponentInfo_iface; } else { @@ -243,7 +247,7 @@ static HRESULT WINAPI BitmapDecoderInfo_QueryInterface(IWICBitmapDecoderInfo *if static ULONG WINAPI BitmapDecoderInfo_AddRef(IWICBitmapDecoderInfo *iface) { BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface); - ULONG ref = InterlockedIncrement(&This->ref); + ULONG ref = InterlockedIncrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -253,7 +257,7 @@ static ULONG WINAPI BitmapDecoderInfo_AddRef(IWICBitmapDecoderInfo *iface) static ULONG WINAPI BitmapDecoderInfo_Release(IWICBitmapDecoderInfo *iface) { BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface); - ULONG ref = InterlockedDecrement(&This->ref); + ULONG ref = InterlockedDecrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -283,8 +287,7 @@ static HRESULT WINAPI BitmapDecoderInfo_GetCLSID(IWICBitmapDecoderInfo *iface, C if (!pclsid) return E_INVALIDARG; - memcpy(pclsid, &This->clsid, sizeof(CLSID)); - + *pclsid = This->base.clsid; return S_OK; } @@ -621,7 +624,7 @@ static HRESULT WINAPI BitmapDecoderInfo_CreateInstance(IWICBitmapDecoderInfo *if TRACE("(%p,%p)\n", iface, ppIBitmapDecoder); - return create_instance(&This->clsid, &IID_IWICBitmapDecoder, (void**)ppIBitmapDecoder); + return create_instance(&This->base.clsid, &IID_IWICBitmapDecoder, (void**)ppIBitmapDecoder); } static const IWICBitmapDecoderInfoVtbl BitmapDecoderInfo_Vtbl = { @@ -653,7 +656,7 @@ static const IWICBitmapDecoderInfoVtbl BitmapDecoderInfo_Vtbl = { BitmapDecoderInfo_CreateInstance }; -static HRESULT BitmapDecoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo) +static HRESULT BitmapDecoderInfo_Constructor(HKEY classkey, REFCLSID clsid, ComponentInfo **ret) { BitmapDecoderInfo *This; @@ -664,25 +667,23 @@ static HRESULT BitmapDecoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWIC return E_OUTOFMEMORY; } - This->IWICBitmapDecoderInfo_iface.lpVtbl = &BitmapDecoderInfo_Vtbl; - This->ref = 1; + This->base.IWICComponentInfo_iface.lpVtbl = (const IWICComponentInfoVtbl*)&BitmapDecoderInfo_Vtbl; + This->base.ref = 1; This->classkey = classkey; - memcpy(&This->clsid, clsid, sizeof(CLSID)); + This->base.clsid = *clsid; - *ppIInfo = (IWICComponentInfo *)&This->IWICBitmapDecoderInfo_iface; + *ret = &This->base; return S_OK; } typedef struct { - IWICBitmapEncoderInfo IWICBitmapEncoderInfo_iface; - LONG ref; + ComponentInfo base; HKEY classkey; - CLSID clsid; } BitmapEncoderInfo; static inline BitmapEncoderInfo *impl_from_IWICBitmapEncoderInfo(IWICBitmapEncoderInfo *iface) { - return CONTAINING_RECORD(iface, BitmapEncoderInfo, IWICBitmapEncoderInfo_iface); + return CONTAINING_RECORD(iface, BitmapEncoderInfo, base.IWICComponentInfo_iface); } static HRESULT WINAPI BitmapEncoderInfo_QueryInterface(IWICBitmapEncoderInfo *iface, REFIID iid, @@ -698,7 +699,7 @@ static HRESULT WINAPI BitmapEncoderInfo_QueryInterface(IWICBitmapEncoderInfo *if IsEqualIID(&IID_IWICBitmapCodecInfo, iid) || IsEqualIID(&IID_IWICBitmapEncoderInfo ,iid)) { - *ppv = &This->IWICBitmapEncoderInfo_iface; + *ppv = &This->base.IWICComponentInfo_iface; } else { @@ -713,7 +714,7 @@ static HRESULT WINAPI BitmapEncoderInfo_QueryInterface(IWICBitmapEncoderInfo *if static ULONG WINAPI BitmapEncoderInfo_AddRef(IWICBitmapEncoderInfo *iface) { BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface); - ULONG ref = InterlockedIncrement(&This->ref); + ULONG ref = InterlockedIncrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -723,7 +724,7 @@ static ULONG WINAPI BitmapEncoderInfo_AddRef(IWICBitmapEncoderInfo *iface) static ULONG WINAPI BitmapEncoderInfo_Release(IWICBitmapEncoderInfo *iface) { BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface); - ULONG ref = InterlockedDecrement(&This->ref); + ULONG ref = InterlockedDecrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -753,8 +754,7 @@ static HRESULT WINAPI BitmapEncoderInfo_GetCLSID(IWICBitmapEncoderInfo *iface, C if (!pclsid) return E_INVALIDARG; - memcpy(pclsid, &This->clsid, sizeof(CLSID)); - + *pclsid = This->base.clsid; return S_OK; } @@ -914,7 +914,7 @@ static HRESULT WINAPI BitmapEncoderInfo_CreateInstance(IWICBitmapEncoderInfo *if TRACE("(%p,%p)\n", iface, ppIBitmapEncoder); - return create_instance(&This->clsid, &IID_IWICBitmapEncoder, (void**)ppIBitmapEncoder); + return create_instance(&This->base.clsid, &IID_IWICBitmapEncoder, (void**)ppIBitmapEncoder); } static const IWICBitmapEncoderInfoVtbl BitmapEncoderInfo_Vtbl = { @@ -944,7 +944,7 @@ static const IWICBitmapEncoderInfoVtbl BitmapEncoderInfo_Vtbl = { BitmapEncoderInfo_CreateInstance }; -static HRESULT BitmapEncoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo) +static HRESULT BitmapEncoderInfo_Constructor(HKEY classkey, REFCLSID clsid, ComponentInfo **ret) { BitmapEncoderInfo *This; @@ -955,25 +955,23 @@ static HRESULT BitmapEncoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWIC return E_OUTOFMEMORY; } - This->IWICBitmapEncoderInfo_iface.lpVtbl = &BitmapEncoderInfo_Vtbl; - This->ref = 1; + This->base.IWICComponentInfo_iface.lpVtbl = (const IWICComponentInfoVtbl*)&BitmapEncoderInfo_Vtbl; + This->base.ref = 1; This->classkey = classkey; - memcpy(&This->clsid, clsid, sizeof(CLSID)); + This->base.clsid = *clsid; - *ppIInfo = (IWICComponentInfo *)&This->IWICBitmapEncoderInfo_iface; + *ret = &This->base; return S_OK; } typedef struct { - IWICFormatConverterInfo IWICFormatConverterInfo_iface; - LONG ref; + ComponentInfo base; HKEY classkey; - CLSID clsid; } FormatConverterInfo; static inline FormatConverterInfo *impl_from_IWICFormatConverterInfo(IWICFormatConverterInfo *iface) { - return CONTAINING_RECORD(iface, FormatConverterInfo, IWICFormatConverterInfo_iface); + return CONTAINING_RECORD(iface, FormatConverterInfo, base.IWICComponentInfo_iface); } static HRESULT WINAPI FormatConverterInfo_QueryInterface(IWICFormatConverterInfo *iface, REFIID iid, @@ -988,7 +986,7 @@ static HRESULT WINAPI FormatConverterInfo_QueryInterface(IWICFormatConverterInfo IsEqualIID(&IID_IWICComponentInfo, iid) || IsEqualIID(&IID_IWICFormatConverterInfo ,iid)) { - *ppv = &This->IWICFormatConverterInfo_iface; + *ppv = &This->base.IWICComponentInfo_iface; } else { @@ -1003,7 +1001,7 @@ static HRESULT WINAPI FormatConverterInfo_QueryInterface(IWICFormatConverterInfo static ULONG WINAPI FormatConverterInfo_AddRef(IWICFormatConverterInfo *iface) { FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface); - ULONG ref = InterlockedIncrement(&This->ref); + ULONG ref = InterlockedIncrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -1013,7 +1011,7 @@ static ULONG WINAPI FormatConverterInfo_AddRef(IWICFormatConverterInfo *iface) static ULONG WINAPI FormatConverterInfo_Release(IWICFormatConverterInfo *iface) { FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface); - ULONG ref = InterlockedDecrement(&This->ref); + ULONG ref = InterlockedDecrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -1043,8 +1041,7 @@ static HRESULT WINAPI FormatConverterInfo_GetCLSID(IWICFormatConverterInfo *ifac if (!pclsid) return E_INVALIDARG; - memcpy(pclsid, &This->clsid, sizeof(CLSID)); - + *pclsid = This->base.clsid; return S_OK; } @@ -1121,7 +1118,7 @@ static HRESULT WINAPI FormatConverterInfo_CreateInstance(IWICFormatConverterInfo TRACE("(%p,%p)\n", iface, ppIFormatConverter); - return create_instance(&This->clsid, &IID_IWICFormatConverter, + return create_instance(&This->base.clsid, &IID_IWICFormatConverter, (void**)ppIFormatConverter); } @@ -1161,7 +1158,7 @@ static const IWICFormatConverterInfoVtbl FormatConverterInfo_Vtbl = { FormatConverterInfo_CreateInstance }; -static HRESULT FormatConverterInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo) +static HRESULT FormatConverterInfo_Constructor(HKEY classkey, REFCLSID clsid, ComponentInfo **ret) { FormatConverterInfo *This; @@ -1172,25 +1169,23 @@ static HRESULT FormatConverterInfo_Constructor(HKEY classkey, REFCLSID clsid, IW return E_OUTOFMEMORY; } - This->IWICFormatConverterInfo_iface.lpVtbl = &FormatConverterInfo_Vtbl; - This->ref = 1; + This->base.IWICComponentInfo_iface.lpVtbl = (const IWICComponentInfoVtbl*)&FormatConverterInfo_Vtbl; + This->base.ref = 1; This->classkey = classkey; - memcpy(&This->clsid, clsid, sizeof(CLSID)); + This->base.clsid = *clsid; - *ppIInfo = (IWICComponentInfo *)&This->IWICFormatConverterInfo_iface; + *ret = &This->base; return S_OK; } typedef struct { - IWICPixelFormatInfo2 IWICPixelFormatInfo2_iface; - LONG ref; + ComponentInfo base; HKEY classkey; - CLSID clsid; } PixelFormatInfo; static inline PixelFormatInfo *impl_from_IWICPixelFormatInfo2(IWICPixelFormatInfo2 *iface) { - return CONTAINING_RECORD(iface, PixelFormatInfo, IWICPixelFormatInfo2_iface); + return CONTAINING_RECORD(iface, PixelFormatInfo, base.IWICComponentInfo_iface); } static HRESULT WINAPI PixelFormatInfo_QueryInterface(IWICPixelFormatInfo2 *iface, REFIID iid, @@ -1206,7 +1201,7 @@ static HRESULT WINAPI PixelFormatInfo_QueryInterface(IWICPixelFormatInfo2 *iface IsEqualIID(&IID_IWICPixelFormatInfo, iid) || IsEqualIID(&IID_IWICPixelFormatInfo2 ,iid)) { - *ppv = &This->IWICPixelFormatInfo2_iface; + *ppv = &This->base.IWICComponentInfo_iface; } else { @@ -1221,7 +1216,7 @@ static HRESULT WINAPI PixelFormatInfo_QueryInterface(IWICPixelFormatInfo2 *iface static ULONG WINAPI PixelFormatInfo_AddRef(IWICPixelFormatInfo2 *iface) { PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface); - ULONG ref = InterlockedIncrement(&This->ref); + ULONG ref = InterlockedIncrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -1231,7 +1226,7 @@ static ULONG WINAPI PixelFormatInfo_AddRef(IWICPixelFormatInfo2 *iface) static ULONG WINAPI PixelFormatInfo_Release(IWICPixelFormatInfo2 *iface) { PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface); - ULONG ref = InterlockedDecrement(&This->ref); + ULONG ref = InterlockedDecrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -1261,8 +1256,7 @@ static HRESULT WINAPI PixelFormatInfo_GetCLSID(IWICPixelFormatInfo2 *iface, CLSI if (!pclsid) return E_INVALIDARG; - memcpy(pclsid, &This->clsid, sizeof(CLSID)); - + *pclsid = This->base.clsid; return S_OK; } @@ -1341,8 +1335,7 @@ static HRESULT WINAPI PixelFormatInfo_GetFormatGUID(IWICPixelFormatInfo2 *iface, if (!pFormat) return E_INVALIDARG; - *pFormat = This->clsid; - + *pFormat = This->base.clsid; return S_OK; } @@ -1455,7 +1448,7 @@ static const IWICPixelFormatInfo2Vtbl PixelFormatInfo_Vtbl = { PixelFormatInfo_GetNumericRepresentation }; -static HRESULT PixelFormatInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo) +static HRESULT PixelFormatInfo_Constructor(HKEY classkey, REFCLSID clsid, ComponentInfo **ret) { PixelFormatInfo *This; @@ -1466,26 +1459,24 @@ static HRESULT PixelFormatInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICCo return E_OUTOFMEMORY; } - This->IWICPixelFormatInfo2_iface.lpVtbl = &PixelFormatInfo_Vtbl; - This->ref = 1; + This->base.IWICComponentInfo_iface.lpVtbl = (const IWICComponentInfoVtbl*)&PixelFormatInfo_Vtbl; + This->base.ref = 1; This->classkey = classkey; - memcpy(&This->clsid, clsid, sizeof(CLSID)); + This->base.clsid = *clsid; - *ppIInfo = (IWICComponentInfo *)&This->IWICPixelFormatInfo2_iface; + *ret = &This->base; return S_OK; } typedef struct { - IWICMetadataReaderInfo IWICMetadataReaderInfo_iface; - LONG ref; + ComponentInfo base; HKEY classkey; - CLSID clsid; } MetadataReaderInfo; static inline MetadataReaderInfo *impl_from_IWICMetadataReaderInfo(IWICMetadataReaderInfo *iface) { - return CONTAINING_RECORD(iface, MetadataReaderInfo, IWICMetadataReaderInfo_iface); + return CONTAINING_RECORD(iface, MetadataReaderInfo, base.IWICComponentInfo_iface); } static HRESULT WINAPI MetadataReaderInfo_QueryInterface(IWICMetadataReaderInfo *iface, @@ -1502,7 +1493,7 @@ static HRESULT WINAPI MetadataReaderInfo_QueryInterface(IWICMetadataReaderInfo * IsEqualIID(&IID_IWICMetadataHandlerInfo, riid) || IsEqualIID(&IID_IWICMetadataReaderInfo, riid)) { - *ppv = &This->IWICMetadataReaderInfo_iface; + *ppv = &This->base.IWICComponentInfo_iface; } else { @@ -1517,7 +1508,7 @@ static HRESULT WINAPI MetadataReaderInfo_QueryInterface(IWICMetadataReaderInfo * static ULONG WINAPI MetadataReaderInfo_AddRef(IWICMetadataReaderInfo *iface) { MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface); - ULONG ref = InterlockedIncrement(&This->ref); + ULONG ref = InterlockedIncrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); return ref; @@ -1526,7 +1517,7 @@ static ULONG WINAPI MetadataReaderInfo_AddRef(IWICMetadataReaderInfo *iface) static ULONG WINAPI MetadataReaderInfo_Release(IWICMetadataReaderInfo *iface) { MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface); - ULONG ref = InterlockedDecrement(&This->ref); + ULONG ref = InterlockedDecrement(&This->base.ref); TRACE("(%p) refcount=%u\n", iface, ref); @@ -1556,7 +1547,7 @@ static HRESULT WINAPI MetadataReaderInfo_GetCLSID(IWICMetadataReaderInfo *iface, TRACE("(%p,%p)\n", iface, clsid); if (!clsid) return E_INVALIDARG; - *clsid = This->clsid; + *clsid = This->base.clsid; return S_OK; } @@ -1867,7 +1858,7 @@ static HRESULT WINAPI MetadataReaderInfo_CreateInstance(IWICMetadataReaderInfo * TRACE("(%p,%p)\n", iface, reader); - return create_instance(&This->clsid, &IID_IWICMetadataReader, (void **)reader); + return create_instance(&This->base.clsid, &IID_IWICMetadataReader, (void **)reader); } static const IWICMetadataReaderInfoVtbl MetadataReaderInfo_Vtbl = { @@ -1894,7 +1885,7 @@ static const IWICMetadataReaderInfoVtbl MetadataReaderInfo_Vtbl = { MetadataReaderInfo_CreateInstance }; -static HRESULT MetadataReaderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **info) +static HRESULT MetadataReaderInfo_Constructor(HKEY classkey, REFCLSID clsid, ComponentInfo **info) { MetadataReaderInfo *This; @@ -1905,12 +1896,12 @@ static HRESULT MetadataReaderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWI return E_OUTOFMEMORY; } - This->IWICMetadataReaderInfo_iface.lpVtbl = &MetadataReaderInfo_Vtbl; - This->ref = 1; + This->base.IWICComponentInfo_iface.lpVtbl = (const IWICComponentInfoVtbl*)&MetadataReaderInfo_Vtbl; + This->base.ref = 1; This->classkey = classkey; - This->clsid = *clsid; + This->base.clsid = *clsid; - *info = (IWICComponentInfo *)&This->IWICMetadataReaderInfo_iface; + *info = &This->base; return S_OK; } @@ -1920,7 +1911,7 @@ static const WCHAR instance_keyname[] = {'I','n','s','t','a','n','c','e',0}; struct category { WICComponentType type; const GUID *catid; - HRESULT (*constructor)(HKEY,REFCLSID,IWICComponentInfo**); + HRESULT (*constructor)(HKEY,REFCLSID,ComponentInfo**); }; static const struct category categories[] = { @@ -1934,6 +1925,7 @@ static const struct category categories[] = { HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo) { + ComponentInfo *info; HKEY clsidkey; HKEY classkey; HKEY catidkey; @@ -1975,7 +1967,7 @@ HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo) { res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &classkey); if (res == ERROR_SUCCESS) - hr = category->constructor(classkey, clsid, ppIInfo); + hr = category->constructor(classkey, clsid, &info); else hr = HRESULT_FROM_WIN32(res); } @@ -1987,6 +1979,8 @@ HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo) RegCloseKey(clsidkey); + if (SUCCEEDED(hr)) + *ppIInfo = &info->IWICComponentInfo_iface; return hr; } -- 2.11.4.GIT