Sweden-Number/dlls/devenum/mediacatenum.c

965 lines
26 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);
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;
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;
}
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 = lstrcmpiW(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((lstrlenW(deviceW) + lstrlenW(dmoW)
+ 2 * CHARS_IN_GUID + 1) * sizeof(WCHAR));
if (!buffer) return E_OUTOFMEMORY;
lstrcpyW(buffer, deviceW);
lstrcatW(buffer, dmoW);
StringFromGUID2(&This->clsid, buffer + lstrlenW(buffer), CHARS_IN_GUID);
StringFromGUID2(&This->class, buffer + lstrlenW(buffer), CHARS_IN_GUID);
2003-07-01 06:30:30 +02:00
}
else
{
buffer = CoTaskMemAlloc((lstrlenW(deviceW) + 3 + (This->has_class ? CHARS_IN_GUID : 0)
+ lstrlenW(This->name) + 1) * sizeof(WCHAR));
if (!buffer) return E_OUTOFMEMORY;
lstrcpyW(buffer, deviceW);
if (This->type == DEVICE_FILTER)
lstrcatW(buffer, swW);
else if (This->type == DEVICE_CODEC)
lstrcatW(buffer, cmW);
if (This->has_class)
{
StringFromGUID2(&This->class, buffer + lstrlenW(buffer), CHARS_IN_GUID);
lstrcatW(buffer, backslashW);
}
lstrcatW(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
{
IEnumDMO_Release(This->dmo_enum);
RegCloseKey(This->sw_key);
RegCloseKey(This->cm_key);
2003-07-01 06:30:30 +02:00
CoTaskMemFree(This);
DEVENUM_UnlockModule();
2003-07-01 06:30:30 +02:00
return 0;
}
return ref;
2003-07-01 06:30:30 +02:00
}
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;
HRESULT hr;
GUID clsid;
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 ((hr = IEnumDMO_Next(This->dmo_enum, 1, &clsid, NULL, NULL)) == S_OK)
{
moniker = dmo_moniker_create(This->class, clsid);
}
/* 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 (IEnumDMO_Skip(This->dmo_enum, 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
IEnumDMO_Reset(This->dmo_enum);
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 **ppEnumMoniker)
{
EnumMonikerImpl * pEnumMoniker = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
WCHAR buffer[78];
HRESULT hr;
if (!pEnumMoniker)
return E_OUTOFMEMORY;
2012-04-03 00:16:52 +02:00
pEnumMoniker->IEnumMoniker_iface.lpVtbl = &IEnumMoniker_Vtbl;
pEnumMoniker->ref = 1;
pEnumMoniker->sw_index = 0;
pEnumMoniker->cm_index = 0;
pEnumMoniker->class = *class;
lstrcpyW(buffer, clsidW);
lstrcatW(buffer, backslashW);
StringFromGUID2(class, buffer + lstrlenW(buffer), CHARS_IN_GUID);
lstrcatW(buffer, instanceW);
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, buffer, 0, KEY_ENUMERATE_SUB_KEYS, &pEnumMoniker->sw_key))
pEnumMoniker->sw_key = NULL;
lstrcpyW(buffer, wszActiveMovieKey);
StringFromGUID2(class, buffer + lstrlenW(buffer), CHARS_IN_GUID);
if (RegOpenKeyExW(HKEY_CURRENT_USER, buffer, 0, KEY_ENUMERATE_SUB_KEYS, &pEnumMoniker->cm_key))
pEnumMoniker->cm_key = NULL;
hr = DMOEnum(class, 0, 0, NULL, 0, NULL, &pEnumMoniker->dmo_enum);
if (FAILED(hr))
{
IEnumMoniker_Release(&pEnumMoniker->IEnumMoniker_iface);
return hr;
}
*ppEnumMoniker = &pEnumMoniker->IEnumMoniker_iface;
DEVENUM_LockModule();
return S_OK;
}