msdmo: Cleanup IEnumDMO creation code.

This commit is contained in:
Nikolay Sivov 2014-10-15 08:26:08 +04:00 committed by Alexandre Julliard
parent a426d335a4
commit 06c52ce940
1 changed files with 73 additions and 71 deletions

View File

@ -352,24 +352,27 @@ static BOOL IEnumDMOImpl_Destructor(IEnumDMOImpl* This)
/************************************************************************** /**************************************************************************
* IEnumDMO_Constructor * IEnumDMO_Constructor
*/ */
static IEnumDMO * IEnumDMO_Constructor( static HRESULT IEnumDMO_Constructor(
REFGUID guidCategory, REFGUID guidCategory,
DWORD dwFlags, DWORD dwFlags,
DWORD cInTypes, DWORD cInTypes,
const DMO_PARTIAL_MEDIATYPE *pInTypes, const DMO_PARTIAL_MEDIATYPE *pInTypes,
DWORD cOutTypes, DWORD cOutTypes,
const DMO_PARTIAL_MEDIATYPE *pOutTypes) const DMO_PARTIAL_MEDIATYPE *pOutTypes,
IEnumDMO **obj)
{ {
UINT size;
IEnumDMOImpl* lpedmo; IEnumDMOImpl* lpedmo;
BOOL ret = FALSE; HRESULT hr = S_OK;
UINT size;
*obj = NULL;
lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl)); lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
if (!lpedmo)
return E_OUTOFMEMORY;
if (lpedmo)
{
lpedmo->ref = 1;
lpedmo->IEnumDMO_iface.lpVtbl = &edmovt; lpedmo->IEnumDMO_iface.lpVtbl = &edmovt;
lpedmo->ref = 1;
lpedmo->index = -1; lpedmo->index = -1;
lpedmo->guidCategory = guidCategory; lpedmo->guidCategory = guidCategory;
lpedmo->dwFlags = dwFlags; lpedmo->dwFlags = dwFlags;
@ -379,7 +382,10 @@ static IEnumDMO * IEnumDMO_Constructor(
size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE); size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size); lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
if (!lpedmo->pInTypes) if (!lpedmo->pInTypes)
{
hr = E_OUTOFMEMORY;
goto lerr; goto lerr;
}
memcpy(lpedmo->pInTypes, pInTypes, size); memcpy(lpedmo->pInTypes, pInTypes, size);
lpedmo->cInTypes = cInTypes; lpedmo->cInTypes = cInTypes;
} }
@ -389,7 +395,10 @@ static IEnumDMO * IEnumDMO_Constructor(
size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE); size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size); lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
if (!lpedmo->pOutTypes) if (!lpedmo->pOutTypes)
{
hr = E_OUTOFMEMORY;
goto lerr; goto lerr;
}
memcpy(lpedmo->pOutTypes, pOutTypes, size); memcpy(lpedmo->pOutTypes, pOutTypes, size);
lpedmo->cOutTypes = cOutTypes; lpedmo->cOutTypes = cOutTypes;
} }
@ -397,9 +406,8 @@ static IEnumDMO * IEnumDMO_Constructor(
/* If not filtering by category enum from media objects root */ /* If not filtering by category enum from media objects root */
if (IsEqualGUID(guidCategory, &GUID_NULL)) if (IsEqualGUID(guidCategory, &GUID_NULL))
{ {
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_READ, &lpedmo->hkey))
0, KEY_READ, &lpedmo->hkey)) hr = E_FAIL;
ret = TRUE;
} }
else else
{ {
@ -408,23 +416,24 @@ static IEnumDMO * IEnumDMO_Constructor(
wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories, wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories,
GUIDToString(szguid, guidCategory)); GUIDToString(szguid, guidCategory));
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &lpedmo->hkey))
0, KEY_READ, &lpedmo->hkey)) hr = E_FAIL;
ret = TRUE;
} }
lerr: lerr:
if(!ret)
if (FAILED(hr))
{ {
IEnumDMOImpl_Destructor(lpedmo); IEnumDMOImpl_Destructor(lpedmo);
HeapFree(GetProcessHeap(), 0, lpedmo); HeapFree(GetProcessHeap(), 0, lpedmo);
lpedmo = NULL;
} }
} else
{
TRACE("returning %p\n", lpedmo); TRACE("returning %p\n", lpedmo);
*obj = &lpedmo->IEnumDMO_iface;
}
return (IEnumDMO*)lpedmo; return hr;
} }
@ -446,14 +455,13 @@ static HRESULT WINAPI IEnumDMO_fnQueryInterface(
REFIID riid, REFIID riid,
LPVOID *ppvObj) LPVOID *ppvObj)
{ {
IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
*ppvObj = NULL; *ppvObj = NULL;
if(IsEqualIID(riid, &IID_IUnknown)) if (IsEqualIID(riid, &IID_IEnumDMO) ||
*ppvObj = This; IsEqualIID(riid, &IID_IUnknown))
else if(IsEqualIID(riid, &IID_IEnumDMO)) {
*ppvObj = This; *ppvObj = iface;
}
if(*ppvObj) if(*ppvObj)
{ {
@ -689,17 +697,11 @@ HRESULT WINAPI DMOEnum(
const DMO_PARTIAL_MEDIATYPE *pOutTypes, const DMO_PARTIAL_MEDIATYPE *pOutTypes,
IEnumDMO **ppEnum) IEnumDMO **ppEnum)
{ {
HRESULT hres = E_FAIL;
TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n", TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
guidCategory, dwFlags, cInTypes, cOutTypes); guidCategory, dwFlags, cInTypes, cOutTypes);
*ppEnum = IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes, return IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes,
pInTypes, cOutTypes, pOutTypes); pInTypes, cOutTypes, pOutTypes, ppEnum);
if (*ppEnum)
hres = S_OK;
return hres;
} }