Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/devenum/devenum_private.h | 4 +- dlls/devenum/mediacatenum.c | 89 +++++++++++++++++++-------------- dlls/devenum/parsedisplayname.c | 41 +++++++-------- 3 files changed, 73 insertions(+), 61 deletions(-)
diff --git a/dlls/devenum/devenum_private.h b/dlls/devenum/devenum_private.h index 11ebd5fa2a4..f3ae7f56d59 100644 --- a/dlls/devenum/devenum_private.h +++ b/dlls/devenum/devenum_private.h @@ -66,7 +66,9 @@ struct moniker }; };
-struct moniker *moniker_create(void) DECLSPEC_HIDDEN; +struct moniker *dmo_moniker_create(const GUID class, const GUID clsid) DECLSPEC_HIDDEN; +struct moniker *codec_moniker_create(const GUID *class, const WCHAR *name) DECLSPEC_HIDDEN; +struct moniker *filter_moniker_create(const GUID *class, const WCHAR *name) DECLSPEC_HIDDEN; HRESULT enum_moniker_create(REFCLSID class, IEnumMoniker **enum_mon) DECLSPEC_HIDDEN;
extern ICreateDevEnum devenum_factory DECLSPEC_HIDDEN; diff --git a/dlls/devenum/mediacatenum.c b/dlls/devenum/mediacatenum.c index d6feb657972..5878c9d71ee 100644 --- a/dlls/devenum/mediacatenum.c +++ b/dlls/devenum/mediacatenum.c @@ -769,7 +769,7 @@ static const IMonikerVtbl IMoniker_Vtbl = moniker_IsSystemMoniker, };
-struct moniker *moniker_create(void) +struct moniker *filter_moniker_create(const GUID *class, const WCHAR *name) { struct moniker *object;
@@ -778,6 +778,49 @@ struct moniker *moniker_create(void)
object->IMoniker_iface.lpVtbl = &IMoniker_Vtbl; object->ref = 1; + object->type = DEVICE_FILTER; + if (class) + object->class = *class; + object->has_class = !!class; + object->name = wcsdup(name); + + DEVENUM_LockModule(); + + return object; +} + +struct moniker *codec_moniker_create(const GUID *class, const WCHAR *name) +{ + struct moniker *object; + + if (!(object = calloc(1, sizeof(*object)))) + return NULL; + + object->IMoniker_iface.lpVtbl = &IMoniker_Vtbl; + object->ref = 1; + object->type = DEVICE_CODEC; + if (class) + object->class = *class; + object->has_class = !!class; + object->name = wcsdup(name); + + DEVENUM_LockModule(); + + return object; +} + +struct moniker *dmo_moniker_create(const GUID class, const GUID clsid) +{ + struct moniker *object; + + if (!(object = calloc(1, sizeof(*object)))) + return NULL; + + object->IMoniker_iface.lpVtbl = &IMoniker_Vtbl; + object->ref = 1; + object->type = DEVICE_DMO; + object->class = class; + object->clsid = clsid;
DEVENUM_LockModule();
@@ -843,11 +886,11 @@ static HRESULT WINAPI enum_moniker_Next(IEnumMoniker *iface, ULONG celt, IMonike { EnumMonikerImpl *This = impl_from_IEnumMoniker(iface); WCHAR buffer[MAX_PATH + 1]; - struct moniker *pMoniker; + struct moniker *moniker; LONG res; ULONG fetched = 0; - CLSID clsid; HRESULT hr; + GUID clsid; HKEY hkey;
TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched); @@ -859,14 +902,7 @@ static HRESULT WINAPI enum_moniker_Next(IEnumMoniker *iface, ULONG celt, IMonike /* try DMOs */ if ((hr = IEnumDMO_Next(This->dmo_enum, 1, &clsid, NULL, NULL)) == S_OK) { - if (!(pMoniker = moniker_create())) - return E_OUTOFMEMORY; - - pMoniker->type = DEVICE_DMO; - pMoniker->clsid = clsid; - - StringFromGUID2(&clsid, buffer, CHARS_IN_GUID); - StringFromGUID2(&This->class, buffer + CHARS_IN_GUID - 1, CHARS_IN_GUID); + moniker = dmo_moniker_create(This->class, clsid); } /* try DirectShow filters */ else if (!(res = RegEnumKeyW(This->sw_key, This->sw_index, buffer, ARRAY_SIZE(buffer)))) @@ -875,17 +911,7 @@ static HRESULT WINAPI enum_moniker_Next(IEnumMoniker *iface, ULONG celt, IMonike if ((res = RegOpenKeyExW(This->sw_key, buffer, 0, KEY_QUERY_VALUE, &hkey))) break;
- if (!(pMoniker = moniker_create())) - return E_OUTOFMEMORY; - - pMoniker->type = DEVICE_FILTER; - - if (!(pMoniker->name = CoTaskMemAlloc((lstrlenW(buffer) + 1) * sizeof(WCHAR)))) - { - IMoniker_Release(&pMoniker->IMoniker_iface); - return E_OUTOFMEMORY; - } - lstrcpyW(pMoniker->name, buffer); + moniker = filter_moniker_create(&This->class, buffer); } /* then try codecs */ else if (!(res = RegEnumKeyW(This->cm_key, This->cm_index, buffer, ARRAY_SIZE(buffer)))) @@ -895,26 +921,15 @@ static HRESULT WINAPI enum_moniker_Next(IEnumMoniker *iface, ULONG celt, IMonike if ((res = RegOpenKeyExW(This->cm_key, buffer, 0, KEY_QUERY_VALUE, &hkey))) break;
- if (!(pMoniker = moniker_create())) - return E_OUTOFMEMORY; - - pMoniker->type = DEVICE_CODEC; - - if (!(pMoniker->name = CoTaskMemAlloc((lstrlenW(buffer) + 1) * sizeof(WCHAR)))) - { - IMoniker_Release(&pMoniker->IMoniker_iface); - return E_OUTOFMEMORY; - } - lstrcpyW(pMoniker->name, buffer); + moniker = codec_moniker_create(&This->class, buffer); } else break;
- pMoniker->has_class = TRUE; - pMoniker->class = This->class; + if (!moniker) + return E_OUTOFMEMORY;
- rgelt[fetched] = &pMoniker->IMoniker_iface; - fetched++; + rgelt[fetched++] = &moniker->IMoniker_iface; }
TRACE("-- fetched %d\n", fetched); diff --git a/dlls/devenum/parsedisplayname.c b/dlls/devenum/parsedisplayname.c index ab0f7bf870d..45a89f69932 100644 --- a/dlls/devenum/parsedisplayname.c +++ b/dlls/devenum/parsedisplayname.c @@ -68,10 +68,10 @@ static ULONG WINAPI devenum_parser_Release(IParseDisplayName *iface) static HRESULT WINAPI devenum_parser_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR name, ULONG *eaten, IMoniker **ret) { + struct moniker *moniker; WCHAR buffer[MAX_PATH]; enum device_type type; - struct moniker *mon; - CLSID class; + GUID class, clsid;
TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(name), eaten, ret);
@@ -102,47 +102,42 @@ static HRESULT WINAPI devenum_parser_ParseDisplayName(IParseDisplayName *iface, return MK_E_SYNTAX; }
- if (!(mon = moniker_create())) - return E_OUTOFMEMORY; - if (type == DEVICE_DMO) { lstrcpynW(buffer, name, CHARS_IN_GUID); - if (FAILED(CLSIDFromString(buffer, &mon->clsid))) - { - IMoniker_Release(&mon->IMoniker_iface); + if (FAILED(CLSIDFromString(buffer, &clsid))) return MK_E_SYNTAX; - }
lstrcpynW(buffer, name + CHARS_IN_GUID - 1, CHARS_IN_GUID); - if (FAILED(CLSIDFromString(buffer, &mon->class))) - { - IMoniker_Release(&mon->IMoniker_iface); + if (FAILED(CLSIDFromString(buffer, &class))) return MK_E_SYNTAX; - } + + moniker = dmo_moniker_create(class, clsid); } else { lstrcpynW(buffer, name, CHARS_IN_GUID); if (CLSIDFromString(buffer, &class) == S_OK) { - mon->has_class = TRUE; - mon->class = class; name += CHARS_IN_GUID; + if (type == DEVICE_FILTER) + moniker = filter_moniker_create(&class, name); + else + moniker = codec_moniker_create(&class, name); } - - if (!(mon->name = CoTaskMemAlloc((lstrlenW(name) + 1) * sizeof(WCHAR)))) + else { - IMoniker_Release(&mon->IMoniker_iface); - return E_OUTOFMEMORY; + if (type == DEVICE_FILTER) + moniker = filter_moniker_create(NULL, name); + else + moniker = codec_moniker_create(NULL, name); } - lstrcpyW(mon->name, name); }
- mon->type = type; - - *ret = &mon->IMoniker_iface; + if (!moniker) + return E_OUTOFMEMORY;
+ *ret = &moniker->IMoniker_iface; return S_OK; }