Sweden-Number/dlls/devenum/mediacatenum.c

1080 lines
29 KiB
C
Raw Normal View History

2003-07-01 06:30:30 +02:00
/*
* IEnumMoniker implementation for DEVENUM.dll
*
* Copyright (C) 2002 Robert Shearman
*
* 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
2003-07-01 06:30:30 +02:00
*
* NOTES ON THIS FILE:
* - Implements IEnumMoniker interface which enumerates through moniker
* objects created from HKEY_CLASSES/CLSID/{DEVICE_CLSID}/Instance
*/
#include "devenum_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(devenum);
BOOL array_reserve(void **elements, unsigned int *capacity, unsigned int count, unsigned int size)
{
unsigned int max_capacity, new_capacity;
void *new_elements;
if (count <= *capacity)
return TRUE;
max_capacity = ~0u / size;
if (count > max_capacity)
return FALSE;
new_capacity = max(8, *capacity);
while (new_capacity < count && new_capacity <= max_capacity / 2)
new_capacity *= 2;
if (new_capacity < count)
new_capacity = count;
if (!(new_elements = realloc(*elements, new_capacity * size)))
{
ERR("Failed to allocate memory.\n");
return FALSE;
}
*elements = new_elements;
*capacity = new_capacity;
return TRUE;
}
2012-04-03 00:16:52 +02:00
typedef struct
{
IEnumMoniker IEnumMoniker_iface;
CLSID class;
2012-04-03 00:16:52 +02:00
LONG ref;
IEnumDMO *dmo_enum, *dmo_enum2;
HKEY sw_key;
DWORD sw_index;
HKEY cm_key;
DWORD cm_index;
2012-04-03 00:16:52 +02:00
} EnumMonikerImpl;
static inline struct moniker *impl_from_IPropertyBag(IPropertyBag *iface)
{
return CONTAINING_RECORD(iface, struct moniker, IPropertyBag_iface);
}
static HRESULT WINAPI property_bag_QueryInterface(IPropertyBag *iface, REFIID iid, void **out)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IPropertyBag(iface);
2008-12-07 11:38:12 +01:00
TRACE("moniker %p, iid %s, out %p.\n", moniker, debugstr_guid(iid), out);
2003-07-01 06:30:30 +02:00
if (!out)
return E_POINTER;
2003-07-01 06:30:30 +02:00
if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IPropertyBag))
2003-07-01 06:30:30 +02:00
{
*out = iface;
IPropertyBag_AddRef(iface);
2003-07-01 06:30:30 +02:00
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
*out = NULL;
2003-07-01 06:30:30 +02:00
return E_NOINTERFACE;
}
static ULONG WINAPI property_bag_AddRef(IPropertyBag *iface)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IPropertyBag(iface);
return IMoniker_AddRef(&moniker->IMoniker_iface);
2003-07-01 06:30:30 +02:00
}
static ULONG WINAPI property_bag_Release(IPropertyBag *iface)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IPropertyBag(iface);
return IMoniker_Release(&moniker->IMoniker_iface);
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI property_bag_Read(IPropertyBag *iface,
const WCHAR *name, VARIANT *var, IErrorLog *errorlog)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IPropertyBag(iface);
WCHAR dmo_name[80];
DWORD size, type;
HKEY parent, key;
WCHAR path[78];
void *data;
HRESULT hr;
LONG ret;
2003-07-01 06:30:30 +02:00
TRACE("moniker %p, name %s, var %p, errorlog %p.\n", moniker, debugstr_w(name), var, errorlog);
2003-07-01 06:30:30 +02:00
if (!name || !var)
2003-07-01 06:30:30 +02:00
return E_POINTER;
if (moniker->type == DEVICE_DMO)
{
if (!wcscmp(name, L"FriendlyName"))
{
if (SUCCEEDED(hr = DMOGetName(&moniker->clsid, dmo_name)))
{
V_VT(var) = VT_BSTR;
V_BSTR(var) = SysAllocString(dmo_name);
}
return hr;
}
else if (!wcscmp(name, L"FilterData"))
{
REGFILTERPINS2 reg_pins[2] = {{0}};
REGFILTER2 reg_filter =
{
.dwVersion = 2,
.dwMerit = MERIT_NORMAL + 0x800,
.cPins2 = 2,
.rgPins2 = reg_pins,
};
unsigned int count = 1, input_count, output_count, i;
DMO_PARTIAL_MEDIATYPE *types = NULL, *new_array;
REGPINTYPES *reg_types;
HRESULT hr;
do
{
count *= 2;
if (!(new_array = realloc(types, 2 * count * sizeof(*types))))
{
free(types);
return E_OUTOFMEMORY;
}
types = new_array;
if (FAILED(hr = DMOGetTypes(&moniker->clsid, count, &input_count, types,
count, &output_count, types + count)))
{
free(types);
return hr;
}
} while (input_count == count || output_count == count);
if (!(reg_types = malloc(2 * count * sizeof(*reg_types))))
{
free(types);
return hr;
}
for (i = 0; i < input_count; ++i)
{
reg_types[i].clsMajorType = &types[i].type;
reg_types[i].clsMinorType = &types[i].subtype;
}
for (i = 0; i < output_count; ++i)
{
reg_types[count + i].clsMajorType = &types[count + i].type;
reg_types[count + i].clsMinorType = &types[count + i].subtype;
}
reg_pins[0].cInstances = 1;
reg_pins[0].nMediaTypes = input_count;
reg_pins[0].lpMediaType = reg_types;
reg_pins[1].dwFlags = REG_PINFLAG_B_OUTPUT;
reg_pins[1].cInstances = 1;
reg_pins[1].nMediaTypes = output_count;
reg_pins[1].lpMediaType = reg_types + count;
hr = create_filter_data(var, &reg_filter);
free(reg_types);
free(types);
return hr;
}
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
}
if (moniker->type == DEVICE_FILTER)
{
wcscpy(path, L"CLSID\\");
if (moniker->has_class)
{
StringFromGUID2(&moniker->class, path + wcslen(path), CHARS_IN_GUID);
wcscat(path, L"\\Instance");
}
if ((ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, 0, &parent)))
return HRESULT_FROM_WIN32(ret);
}
else if (moniker->type == DEVICE_CODEC)
2003-07-01 06:30:30 +02:00
{
wcscpy(path, L"Software\\Microsoft\\ActiveMovie\\devenum\\");
if (moniker->has_class)
StringFromGUID2(&moniker->class, path + wcslen(path), CHARS_IN_GUID);
if ((ret = RegOpenKeyExW(HKEY_CURRENT_USER, path, 0, 0, &parent)))
return HRESULT_FROM_WIN32(ret);
}
ret = RegOpenKeyExW(parent, moniker->name, 0, KEY_READ, &key);
RegCloseKey(parent);
if (ret)
return HRESULT_FROM_WIN32(ret);
if ((ret = RegQueryValueExW(key, name, NULL, NULL, NULL, &size)))
{
RegCloseKey(key);
return HRESULT_FROM_WIN32(ret);
}
data = malloc(size);
if ((ret = RegQueryValueExW(key, name, NULL, &type, data, &size)))
{
RegCloseKey(key);
free(data);
return HRESULT_FROM_WIN32(ret);
}
RegCloseKey(key);
switch (type)
{
case REG_SZ:
if (V_VT(var) == VT_EMPTY)
V_VT(var) = VT_BSTR;
if (V_VT(var) != VT_BSTR)
2003-07-01 06:30:30 +02:00
{
WARN("Invalid type %s.\n", debugstr_vt(V_VT(var)));
return E_INVALIDARG;
2003-07-01 06:30:30 +02:00
}
V_BSTR(var) = SysAllocStringLen(data, size / sizeof(WCHAR) - 1);
free(data);
return S_OK;
case REG_DWORD:
if (V_VT(var) == VT_EMPTY)
V_VT(var) = VT_I4;
if (V_VT(var) != VT_I4)
{
WARN("Invalid type %s.\n", debugstr_vt(V_VT(var)));
return E_INVALIDARG;
}
V_I4(var) = *(DWORD *)data;
free(data);
return S_OK;
case REG_BINARY:
{
SAFEARRAYBOUND bound = {.cElements = size};
void *array_data;
2003-07-01 06:30:30 +02:00
if (V_VT(var) == VT_EMPTY)
V_VT(var) = VT_ARRAY | VT_UI1;
if (V_VT(var) != (VT_ARRAY | VT_UI1))
{
WARN("Invalid type %s.\n", debugstr_vt(V_VT(var)));
return E_INVALIDARG;
}
if (!(V_ARRAY(var) = SafeArrayCreate(VT_UI1, 1, &bound)))
{
free(data);
return E_OUTOFMEMORY;
}
SafeArrayAccessData(V_ARRAY(var), &array_data);
memcpy(array_data, data, size);
SafeArrayUnaccessData(V_ARRAY(var));
free(data);
return S_OK;
}
default:
FIXME("Unhandled type %#x.\n", type);
free(data);
return E_NOTIMPL;
}
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI property_bag_Write(IPropertyBag *iface, const WCHAR *name, VARIANT *var)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IPropertyBag(iface);
HKEY parent, key;
WCHAR path[78];
LONG ret;
2003-07-01 06:30:30 +02:00
TRACE("moniker %p, name %s, var %s.\n", moniker, debugstr_w(name), debugstr_variant(var));
2003-07-01 06:30:30 +02:00
if (moniker->type == DEVICE_DMO)
return E_ACCESSDENIED;
if (moniker->type == DEVICE_FILTER)
{
wcscpy(path, L"CLSID\\");
if (moniker->has_class)
{
StringFromGUID2(&moniker->class, path + wcslen(path), CHARS_IN_GUID);
wcscat(path, L"\\Instance");
}
if ((ret = RegCreateKeyExW(HKEY_CLASSES_ROOT, path, 0, NULL, 0, 0, NULL, &parent, NULL)))
return HRESULT_FROM_WIN32(ret);
}
else if (moniker->type == DEVICE_CODEC)
{
wcscpy(path, L"Software\\Microsoft\\ActiveMovie\\devenum\\");
if (moniker->has_class)
StringFromGUID2(&moniker->class, path + wcslen(path), CHARS_IN_GUID);
if ((ret = RegCreateKeyExW(HKEY_CURRENT_USER, path, 0, NULL, 0, 0, NULL, &parent, NULL)))
return HRESULT_FROM_WIN32(ret);
}
ret = RegCreateKeyExW(parent, moniker->name, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL);
RegCloseKey(parent);
if (ret)
return HRESULT_FROM_WIN32(ret);
switch (V_VT(var))
2003-07-01 06:30:30 +02:00
{
case VT_BSTR:
ret = RegSetValueExW(key, name, 0, REG_SZ, (BYTE *)V_BSTR(var),
(wcslen(V_BSTR(var)) + 1) * sizeof(WCHAR));
2003-07-01 06:30:30 +02:00
break;
case VT_I4:
ret = RegSetValueExW(key, name, 0, REG_DWORD, (BYTE *)&V_I4(var), sizeof(DWORD));
2003-07-01 06:30:30 +02:00
break;
case VT_ARRAY | VT_UI1:
{
LONG lbound, ubound;
void *array_data;
SafeArrayGetLBound(V_ARRAY(var), 1, &lbound);
SafeArrayGetUBound(V_ARRAY(var), 1, &ubound);
SafeArrayAccessData(V_ARRAY(var), &array_data);
ret = RegSetValueExW(key, name, 0, REG_BINARY, array_data, ubound - lbound + 1);
SafeArrayUnaccessData(V_ARRAY(var));
2003-07-01 06:30:30 +02:00
break;
}
default:
WARN("Unhandled type %s.\n", debugstr_vt(V_VT(var)));
return E_INVALIDARG;
2003-07-01 06:30:30 +02:00
}
RegCloseKey(key);
return S_OK;
2003-07-01 06:30:30 +02:00
}
static const IPropertyBagVtbl IPropertyBag_Vtbl =
2003-07-01 06:30:30 +02:00
{
property_bag_QueryInterface,
property_bag_AddRef,
property_bag_Release,
property_bag_Read,
property_bag_Write,
2003-07-01 06:30:30 +02:00
};
static inline struct moniker *impl_from_IMoniker(IMoniker *iface)
2003-07-01 06:30:30 +02:00
{
return CONTAINING_RECORD(iface, struct moniker, IMoniker_iface);
}
2003-07-01 06:30:30 +02:00
static HRESULT WINAPI moniker_QueryInterface(IMoniker *iface, REFIID riid, void **ppv)
{
TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
2003-07-01 06:30:30 +02:00
if (!ppv)
return E_POINTER;
2003-07-01 06:30:30 +02:00
if (IsEqualGUID(riid, &IID_IUnknown) ||
IsEqualGUID(riid, &IID_IPersist) ||
IsEqualGUID(riid, &IID_IPersistStream) ||
IsEqualGUID(riid, &IID_IMoniker))
{
*ppv = iface;
IMoniker_AddRef(iface);
2003-07-01 06:30:30 +02:00
return S_OK;
}
FIXME("- no interface IID: %s\n", debugstr_guid(riid));
*ppv = NULL;
2003-07-01 06:30:30 +02:00
return E_NOINTERFACE;
}
static ULONG WINAPI moniker_AddRef(IMoniker *iface)
2003-07-01 06:30:30 +02:00
{
struct moniker *This = impl_from_IMoniker(iface);
ULONG ref = InterlockedIncrement(&This->ref);
2003-07-01 06:30:30 +02:00
TRACE("(%p) ref=%d\n", This, ref);
return ref;
2003-07-01 06:30:30 +02:00
}
static ULONG WINAPI moniker_Release(IMoniker *iface)
2003-07-01 06:30:30 +02:00
{
struct moniker *This = impl_from_IMoniker(iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) ref=%d\n", This, ref);
2003-07-01 06:30:30 +02:00
if (ref == 0) {
free(This->name);
free(This);
DEVENUM_UnlockModule();
2003-07-01 06:30:30 +02:00
}
return ref;
}
static HRESULT WINAPI moniker_GetClassID(IMoniker *iface, CLSID *pClassID)
2003-07-01 06:30:30 +02:00
{
struct moniker *This = impl_from_IMoniker(iface);
TRACE("(%p)->(%p)\n", This, pClassID);
2003-07-01 06:30:30 +02:00
if (pClassID == NULL)
return E_INVALIDARG;
2003-07-01 06:30:30 +02:00
*pClassID = CLSID_CDeviceMoniker;
return S_OK;
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI moniker_IsDirty(IMoniker *iface)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(): stub\n", iface);
2003-07-01 06:30:30 +02:00
return S_FALSE;
}
static HRESULT WINAPI moniker_Load(IMoniker *iface, IStream *pStm)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p): stub\n", iface, pStm);
2003-07-01 06:30:30 +02:00
return E_NOTIMPL;
}
static HRESULT WINAPI moniker_Save(IMoniker *iface, IStream *pStm, BOOL fClearDirty)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p, %s): stub\n", iface, pStm, fClearDirty ? "true" : "false");
2003-07-01 06:30:30 +02:00
return STG_E_CANTSAVE;
}
static HRESULT WINAPI moniker_GetSizeMax(IMoniker *iface, ULARGE_INTEGER *pcbSize)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p): stub\n", iface, pcbSize);
2003-07-01 06:30:30 +02:00
ZeroMemory(pcbSize, sizeof(*pcbSize));
return S_OK;
}
static HRESULT WINAPI moniker_BindToObject(IMoniker *iface, IBindCtx *bind_ctx,
IMoniker *left, REFIID iid, void **out)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IMoniker(iface);
IPersistPropertyBag *persist_bag;
IUnknown *unk;
CLSID clsid;
2003-07-01 06:30:30 +02:00
VARIANT var;
HRESULT hr;
2003-07-01 06:30:30 +02:00
TRACE("moniker %p, bind_ctx %p, left %p, iid %s, out %p.\n",
moniker, bind_ctx, left, debugstr_guid(iid), out);
2003-07-01 06:30:30 +02:00
if (!out)
return E_POINTER;
*out = NULL;
2003-07-01 06:30:30 +02:00
if (moniker->type == DEVICE_DMO)
{
IDMOWrapperFilter *wrapper;
if (FAILED(hr = CoCreateInstance(&CLSID_DMOWrapperFilter, NULL,
CLSCTX_INPROC_SERVER, &IID_IDMOWrapperFilter, (void **)&wrapper)))
return hr;
if (SUCCEEDED(hr = IDMOWrapperFilter_Init(wrapper, &moniker->clsid, &moniker->class)))
{
hr = IDMOWrapperFilter_QueryInterface(wrapper, iid, out);
}
IDMOWrapperFilter_Release(wrapper);
return hr;
}
VariantInit(&var);
V_VT(&var) = VT_BSTR;
if (FAILED(hr = IPropertyBag_Read(&moniker->IPropertyBag_iface, L"CLSID", &var, NULL)))
return hr;
2003-07-01 06:30:30 +02:00
hr = CLSIDFromString(V_BSTR(&var), &clsid);
VariantClear(&var);
if (FAILED(hr))
return hr;
2003-07-01 06:30:30 +02:00
if (FAILED(hr = CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &IID_IUnknown, (void **)&unk)))
return hr;
2003-07-01 06:30:30 +02:00
if (SUCCEEDED(IUnknown_QueryInterface(unk, &IID_IPersistPropertyBag, (void **)&persist_bag)))
{
hr = IPersistPropertyBag_Load(persist_bag, &moniker->IPropertyBag_iface, NULL);
IPersistPropertyBag_Release(persist_bag);
}
if (SUCCEEDED(hr))
hr = IUnknown_QueryInterface(unk, iid, out);
IUnknown_Release(unk);
2003-07-01 06:30:30 +02:00
return hr;
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI moniker_BindToStorage(IMoniker *iface, IBindCtx *pbc,
IMoniker *pmkToLeft, REFIID riid, void **out)
2003-07-01 06:30:30 +02:00
{
struct moniker *moniker = impl_from_IMoniker(iface);
TRACE("moniker %p, left %p, iid %s, out %p.\n", moniker, pmkToLeft, debugstr_guid(riid), out);
2003-07-01 06:30:30 +02:00
*out = NULL;
2003-07-01 06:30:30 +02:00
if (pmkToLeft)
2003-07-01 06:30:30 +02:00
return MK_E_NOSTORAGE;
if (pbc != NULL)
{
static DWORD reported;
if (!reported)
{
FIXME("ignoring IBindCtx %p\n", pbc);
reported++;
}
}
2003-07-01 06:30:30 +02:00
if (IsEqualGUID(riid, &IID_IPropertyBag))
{
*out = &moniker->IPropertyBag_iface;
IPropertyBag_AddRef(&moniker->IPropertyBag_iface);
return S_OK;
2003-07-01 06:30:30 +02:00
}
return MK_E_NOSTORAGE;
}
static HRESULT WINAPI moniker_Reduce(IMoniker *iface, IBindCtx *pbc,
DWORD dwReduceHowFar, IMoniker **ppmkToLeft, IMoniker **ppmkReduced)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
2003-07-01 06:30:30 +02:00
if (ppmkToLeft)
*ppmkToLeft = NULL;
*ppmkReduced = iface;
return MK_S_REDUCED_TO_SELF;
}
static HRESULT WINAPI moniker_ComposeWith(IMoniker *iface, IMoniker *pmkRight,
BOOL fOnlyIfNotGeneric, IMoniker **ppmkComposite)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p, %s, %p): stub\n", iface, pmkRight, fOnlyIfNotGeneric ? "true" : "false", ppmkComposite);
2003-07-01 06:30:30 +02:00
/* FIXME: use CreateGenericComposite? */
*ppmkComposite = NULL;
return E_NOTIMPL;
}
static HRESULT WINAPI moniker_Enum(IMoniker *iface, BOOL fForward,
IEnumMoniker **ppenumMoniker)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%s, %p): stub\n", iface, fForward ? "true" : "false", ppenumMoniker);
2003-07-01 06:30:30 +02:00
*ppenumMoniker = NULL;
return S_OK;
}
static HRESULT WINAPI moniker_IsEqual(IMoniker *iface, IMoniker *pmkOtherMoniker)
2003-07-01 06:30:30 +02:00
{
CLSID clsid;
LPOLESTR this_name, other_name;
IBindCtx *bind;
HRESULT res;
2003-07-01 06:30:30 +02:00
TRACE("(%p)->(%p)\n", iface, pmkOtherMoniker);
if (!pmkOtherMoniker)
return E_INVALIDARG;
IMoniker_GetClassID(pmkOtherMoniker, &clsid);
if (!IsEqualCLSID(&clsid, &CLSID_CDeviceMoniker))
return S_FALSE;
res = CreateBindCtx(0, &bind);
if (FAILED(res))
return res;
res = S_FALSE;
if (SUCCEEDED(IMoniker_GetDisplayName(iface, bind, NULL, &this_name)) &&
SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker, bind, NULL, &other_name)))
{
int result = wcsicmp(this_name, other_name);
CoTaskMemFree(this_name);
CoTaskMemFree(other_name);
if (!result)
res = S_OK;
}
IBindCtx_Release(bind);
return res;
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI moniker_Hash(IMoniker *iface, DWORD *pdwHash)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p)\n", iface, pdwHash);
2003-07-01 06:30:30 +02:00
*pdwHash = 0;
return S_OK;
}
static HRESULT WINAPI moniker_IsRunning(IMoniker *iface, IBindCtx *pbc,
IMoniker *pmkToLeft, IMoniker *pmkNewlyRunning)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p, %p, %p): stub\n", iface, pbc, pmkToLeft, pmkNewlyRunning);
2003-07-01 06:30:30 +02:00
return S_FALSE;
}
static HRESULT WINAPI moniker_GetTimeOfLastChange(IMoniker *iface, IBindCtx *pbc,
IMoniker *pmkToLeft, FILETIME *pFileTime)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, pFileTime);
2003-07-01 06:30:30 +02:00
pFileTime->dwLowDateTime = 0xFFFFFFFF;
pFileTime->dwHighDateTime = 0x7FFFFFFF;
return MK_E_UNAVAILABLE;
}
static HRESULT WINAPI moniker_Inverse(IMoniker *iface, IMoniker **ppmk)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p)\n", iface, ppmk);
2003-07-01 06:30:30 +02:00
*ppmk = NULL;
return MK_E_NOINVERSE;
}
static HRESULT WINAPI moniker_CommonPrefixWith(IMoniker *iface,
IMoniker *pmkOtherMoniker, IMoniker **ppmkPrefix)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p, %p)\n", iface, pmkOtherMoniker, ppmkPrefix);
2003-07-01 06:30:30 +02:00
*ppmkPrefix = NULL;
return MK_E_NOPREFIX;
}
static HRESULT WINAPI moniker_RelativePathTo(IMoniker *iface, IMoniker *pmkOther,
IMoniker **ppmkRelPath)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p, %p)\n", iface, pmkOther, ppmkRelPath);
2003-07-01 06:30:30 +02:00
*ppmkRelPath = pmkOther;
return MK_S_HIM;
}
static HRESULT WINAPI moniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc,
IMoniker *pmkToLeft, LPOLESTR *ppszDisplayName)
2003-07-01 06:30:30 +02:00
{
struct moniker *This = impl_from_IMoniker(iface);
WCHAR *buffer;
2003-07-01 06:30:30 +02:00
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p, %p, %p)\n", iface, pbc, pmkToLeft, ppszDisplayName);
2003-07-01 06:30:30 +02:00
*ppszDisplayName = NULL;
if (This->type == DEVICE_DMO)
2003-07-01 06:30:30 +02:00
{
buffer = CoTaskMemAlloc((12 + 2 * CHARS_IN_GUID + 1) * sizeof(WCHAR));
if (!buffer) return E_OUTOFMEMORY;
wcscpy(buffer, L"@device:dmo:");
StringFromGUID2(&This->clsid, buffer + wcslen(buffer), CHARS_IN_GUID);
StringFromGUID2(&This->class, buffer + wcslen(buffer), CHARS_IN_GUID);
2003-07-01 06:30:30 +02:00
}
else
{
buffer = CoTaskMemAlloc((11 + (This->has_class ? CHARS_IN_GUID : 0)
+ wcslen(This->name) + 1) * sizeof(WCHAR));
if (!buffer) return E_OUTOFMEMORY;
if (This->type == DEVICE_FILTER)
wcscpy(buffer, L"@device:sw:");
else if (This->type == DEVICE_CODEC)
wcscpy(buffer, L"@device:cm:");
if (This->has_class)
{
StringFromGUID2(&This->class, buffer + wcslen(buffer), CHARS_IN_GUID);
wcscat(buffer, L"\\");
}
wcscat(buffer, This->name);
}
2003-07-01 06:30:30 +02:00
*ppszDisplayName = buffer;
return S_OK;
2003-07-01 06:30:30 +02:00
}
static HRESULT WINAPI moniker_ParseDisplayName(IMoniker *iface, IBindCtx *pbc,
IMoniker *pmkToLeft, LPOLESTR pszDisplayName, ULONG *pchEaten, IMoniker **ppmkOut)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
FIXME("(%p)->(%p, %p, %s, %p, %p)\n", iface, pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
2003-07-01 06:30:30 +02:00
*pchEaten = 0;
*ppmkOut = NULL;
return MK_E_SYNTAX;
}
static HRESULT WINAPI moniker_IsSystemMoniker(IMoniker *iface, DWORD *pdwMksys)
2003-07-01 06:30:30 +02:00
{
2008-12-07 11:38:12 +01:00
TRACE("(%p)->(%p)\n", iface, pdwMksys);
2003-07-01 06:30:30 +02:00
return S_FALSE;
}
static const IMonikerVtbl IMoniker_Vtbl =
2003-07-01 06:30:30 +02:00
{
moniker_QueryInterface,
moniker_AddRef,
moniker_Release,
moniker_GetClassID,
moniker_IsDirty,
moniker_Load,
moniker_Save,
moniker_GetSizeMax,
moniker_BindToObject,
moniker_BindToStorage,
moniker_Reduce,
moniker_ComposeWith,
moniker_Enum,
moniker_IsEqual,
moniker_Hash,
moniker_IsRunning,
moniker_GetTimeOfLastChange,
moniker_Inverse,
moniker_CommonPrefixWith,
moniker_RelativePathTo,
moniker_GetDisplayName,
moniker_ParseDisplayName,
moniker_IsSystemMoniker,
2003-07-01 06:30:30 +02:00
};
struct moniker *filter_moniker_create(const GUID *class, const WCHAR *name)
2003-07-01 06:30:30 +02:00
{
struct moniker *object;
if (!(object = calloc(1, sizeof(*object))))
2003-07-01 06:30:30 +02:00
return NULL;
object->IMoniker_iface.lpVtbl = &IMoniker_Vtbl;
object->IPropertyBag_iface.lpVtbl = &IPropertyBag_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->IPropertyBag_iface.lpVtbl = &IPropertyBag_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->IPropertyBag_iface.lpVtbl = &IPropertyBag_Vtbl;
object->ref = 1;
object->type = DEVICE_DMO;
object->class = class;
object->clsid = clsid;
2003-07-01 06:30:30 +02:00
DEVENUM_LockModule();
return object;
2003-07-01 06:30:30 +02:00
}
2012-04-03 00:16:52 +02:00
static inline EnumMonikerImpl *impl_from_IEnumMoniker(IEnumMoniker *iface)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
return CONTAINING_RECORD(iface, EnumMonikerImpl, IEnumMoniker_iface);
}
2008-12-07 11:38:12 +01:00
static HRESULT WINAPI enum_moniker_QueryInterface(IEnumMoniker *iface, REFIID riid, void **ppv)
2012-04-03 00:16:52 +02:00
{
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
2003-07-01 06:30:30 +02:00
2012-04-03 00:16:52 +02:00
if (!ppv)
return E_POINTER;
2003-07-01 06:30:30 +02:00
if (IsEqualGUID(riid, &IID_IUnknown) ||
IsEqualGUID(riid, &IID_IEnumMoniker))
{
2012-04-03 00:16:52 +02:00
*ppv = iface;
IEnumMoniker_AddRef(iface);
2003-07-01 06:30:30 +02:00
return S_OK;
}
FIXME("- no interface IID: %s\n", debugstr_guid(riid));
2012-04-03 00:16:52 +02:00
*ppv = NULL;
2003-07-01 06:30:30 +02:00
return E_NOINTERFACE;
}
static ULONG WINAPI enum_moniker_AddRef(IEnumMoniker *iface)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
ULONG ref = InterlockedIncrement(&This->ref);
2003-07-01 06:30:30 +02:00
2012-04-03 00:16:52 +02:00
TRACE("(%p) ref=%d\n", This, ref);
2003-07-01 06:30:30 +02:00
return ref;
2003-07-01 06:30:30 +02:00
}
static ULONG WINAPI enum_moniker_Release(IEnumMoniker *iface)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
ULONG ref = InterlockedDecrement(&This->ref);
2003-07-01 06:30:30 +02:00
2012-04-03 00:16:52 +02:00
TRACE("(%p) ref=%d\n", This, ref);
2003-07-01 06:30:30 +02:00
if (!ref)
2003-07-01 06:30:30 +02:00
{
if (This->dmo_enum)
IEnumDMO_Release(This->dmo_enum);
if (This->dmo_enum2)
IEnumDMO_Release(This->dmo_enum2);
RegCloseKey(This->sw_key);
RegCloseKey(This->cm_key);
free(This);
DEVENUM_UnlockModule();
2003-07-01 06:30:30 +02:00
return 0;
}
return ref;
2003-07-01 06:30:30 +02:00
}
static struct moniker *get_dmo_moniker(EnumMonikerImpl *enum_moniker)
{
GUID clsid;
if (IsEqualGUID(&enum_moniker->class, &CLSID_LegacyAmFilterCategory))
{
if (enum_moniker->dmo_enum && IEnumDMO_Next(enum_moniker->dmo_enum, 1, &clsid, NULL, NULL) == S_OK)
return dmo_moniker_create(DMOCATEGORY_AUDIO_DECODER, clsid);
if (enum_moniker->dmo_enum2 && IEnumDMO_Next(enum_moniker->dmo_enum2, 1, &clsid, NULL, NULL) == S_OK)
return dmo_moniker_create(DMOCATEGORY_VIDEO_DECODER, clsid);
}
else
{
if (enum_moniker->dmo_enum && IEnumDMO_Next(enum_moniker->dmo_enum, 1, &clsid, NULL, NULL) == S_OK)
return dmo_moniker_create(enum_moniker->class, clsid);
}
return NULL;
}
static HRESULT WINAPI enum_moniker_Next(IEnumMoniker *iface, ULONG celt, IMoniker **rgelt,
2012-04-03 00:16:52 +02:00
ULONG *pceltFetched)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
2003-07-01 06:30:30 +02:00
WCHAR buffer[MAX_PATH + 1];
struct moniker *moniker;
2003-07-01 06:30:30 +02:00
LONG res;
ULONG fetched = 0;
HKEY hkey;
2003-07-01 06:30:30 +02:00
TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
2003-07-01 06:30:30 +02:00
while (fetched < celt)
{
/* FIXME: try PNP devices first */
/* try DMOs */
if ((moniker = get_dmo_moniker(This)))
;
/* try DirectShow filters */
else if (!(res = RegEnumKeyW(This->sw_key, This->sw_index, buffer, ARRAY_SIZE(buffer))))
2003-07-01 06:30:30 +02:00
{
This->sw_index++;
if ((res = RegOpenKeyExW(This->sw_key, buffer, 0, KEY_QUERY_VALUE, &hkey)))
break;
moniker = filter_moniker_create(&This->class, buffer);
2003-07-01 06:30:30 +02:00
}
/* then try codecs */
else if (!(res = RegEnumKeyW(This->cm_key, This->cm_index, buffer, ARRAY_SIZE(buffer))))
{
This->cm_index++;
if ((res = RegOpenKeyExW(This->cm_key, buffer, 0, KEY_QUERY_VALUE, &hkey)))
break;
moniker = codec_moniker_create(&This->class, buffer);
}
else
break;
if (!moniker)
return E_OUTOFMEMORY;
rgelt[fetched++] = &moniker->IMoniker_iface;
2003-07-01 06:30:30 +02:00
}
TRACE("-- fetched %d\n", fetched);
2003-07-01 06:30:30 +02:00
if (pceltFetched)
*pceltFetched = fetched;
if (fetched != celt)
return S_FALSE;
else
return S_OK;
}
static HRESULT WINAPI enum_moniker_Skip(IEnumMoniker *iface, ULONG celt)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
2003-07-01 06:30:30 +02:00
TRACE("(%p)->(%d)\n", iface, celt);
2003-07-01 06:30:30 +02:00
while (celt--)
{
/* FIXME: try PNP devices first */
/* try DMOs */
if (This->dmo_enum && IEnumDMO_Skip(This->dmo_enum, 1) == S_OK)
;
else if (This->dmo_enum2 && IEnumDMO_Skip(This->dmo_enum2, 1) == S_OK)
;
/* try DirectShow filters */
else if (RegEnumKeyW(This->sw_key, This->sw_index, NULL, 0) != ERROR_NO_MORE_ITEMS)
{
This->sw_index++;
}
/* then try codecs */
else if (RegEnumKeyW(This->cm_key, This->cm_index, NULL, 0) != ERROR_NO_MORE_ITEMS)
{
This->cm_index++;
}
else
return S_FALSE;
}
2003-07-01 06:30:30 +02:00
return S_OK;
}
static HRESULT WINAPI enum_moniker_Reset(IEnumMoniker *iface)
2003-07-01 06:30:30 +02:00
{
2012-04-03 00:16:52 +02:00
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
2003-07-01 06:30:30 +02:00
TRACE("(%p)->()\n", iface);
2003-07-01 06:30:30 +02:00
if (This->dmo_enum)
IEnumDMO_Reset(This->dmo_enum);
if (This->dmo_enum2)
IEnumDMO_Reset(This->dmo_enum2);
This->sw_index = 0;
This->cm_index = 0;
2003-07-01 06:30:30 +02:00
return S_OK;
}
static HRESULT WINAPI enum_moniker_Clone(IEnumMoniker *iface, IEnumMoniker **ppenum)
2003-07-01 06:30:30 +02:00
{
FIXME("(%p)->(%p): stub\n", iface, ppenum);
2003-07-01 06:30:30 +02:00
return E_NOTIMPL;
}
/**********************************************************************
* IEnumMoniker_Vtbl
*/
static const IEnumMonikerVtbl IEnumMoniker_Vtbl =
2003-07-01 06:30:30 +02:00
{
enum_moniker_QueryInterface,
enum_moniker_AddRef,
enum_moniker_Release,
enum_moniker_Next,
enum_moniker_Skip,
enum_moniker_Reset,
enum_moniker_Clone,
2003-07-01 06:30:30 +02:00
};
HRESULT enum_moniker_create(REFCLSID class, IEnumMoniker **out)
{
EnumMonikerImpl *object;
WCHAR buffer[78];
if (!(object = calloc(1, sizeof(*object))))
return E_OUTOFMEMORY;
object->IEnumMoniker_iface.lpVtbl = &IEnumMoniker_Vtbl;
object->ref = 1;
object->class = *class;
wcscpy(buffer, L"CLSID\\");
StringFromGUID2(class, buffer + wcslen(buffer), CHARS_IN_GUID);
wcscat(buffer, L"\\Instance");
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, buffer, 0, KEY_ENUMERATE_SUB_KEYS, &object->sw_key))
object->sw_key = NULL;
wcscpy(buffer, L"Software\\Microsoft\\ActiveMovie\\devenum\\");
StringFromGUID2(class, buffer + wcslen(buffer), CHARS_IN_GUID);
if (RegOpenKeyExW(HKEY_CURRENT_USER, buffer, 0, KEY_ENUMERATE_SUB_KEYS, &object->cm_key))
object->cm_key = NULL;
if (IsEqualGUID(class, &CLSID_LegacyAmFilterCategory))
{
if (FAILED(DMOEnum(&DMOCATEGORY_AUDIO_DECODER, 0, 0, NULL, 0, NULL, &object->dmo_enum)))
object->dmo_enum = NULL;
if (FAILED(DMOEnum(&DMOCATEGORY_VIDEO_DECODER, 0, 0, NULL, 0, NULL, &object->dmo_enum2)))
object->dmo_enum2 = NULL;
}
else
{
if (FAILED(DMOEnum(class, 0, 0, NULL, 0, NULL, &object->dmo_enum)))
object->dmo_enum = NULL;
}
*out = &object->IEnumMoniker_iface;
DEVENUM_LockModule();
return S_OK;
}