2 * IParseDisplayName implementation for DEVENUM.dll
4 * Copyright (C) 2002 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - Implements IParseDisplayName interface which creates a moniker
22 * from a string in a special format
24 #include "devenum_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
30 static HRESULT WINAPI DEVENUM_IParseDisplayName_QueryInterface(
31 LPPARSEDISPLAYNAME iface,
35 ICOM_THIS(ParseDisplayNameImpl, iface);
36 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
38 if (This == NULL || ppvObj == NULL) return E_POINTER;
40 if (IsEqualGUID(riid, &IID_IUnknown) ||
41 IsEqualGUID(riid, &IID_IParseDisplayName))
43 *ppvObj = (LPVOID)iface;
44 IParseDisplayName_AddRef(iface);
48 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
52 /**********************************************************************
53 * DEVENUM_IParseDisplayName_AddRef (also IUnknown)
55 static ULONG WINAPI DEVENUM_IParseDisplayName_AddRef(LPPARSEDISPLAYNAME iface)
57 ICOM_THIS(ParseDisplayNameImpl, iface);
60 if (This == NULL) return E_POINTER;
62 if (InterlockedIncrement(&This->ref) == 1) {
63 InterlockedIncrement(&dll_ref);
69 /**********************************************************************
70 * DEVENUM_IParseDisplayName_Release (also IUnknown)
72 static ULONG WINAPI DEVENUM_IParseDisplayName_Release(LPPARSEDISPLAYNAME iface)
74 ICOM_THIS(ParseDisplayNameImpl, iface);
78 if (This == NULL) return E_POINTER;
81 if (InterlockedDecrement(&This->ref) == 0) {
82 InterlockedDecrement(&dll_ref);
87 /**********************************************************************
88 * DEVENUM_IParseDisplayName_ParseDisplayName
90 * Creates a moniker referenced to by the display string argument
93 * Might not handle more complicated strings properly (ie anything
94 * not in "@device:sw:{CLSID1}\<filter name or CLSID>" format
96 static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName(
97 LPPARSEDISPLAYNAME iface,
99 LPOLESTR pszDisplayName,
103 LPOLESTR pszBetween = NULL;
104 LPOLESTR pszClass = NULL;
105 IEnumMoniker * pEm = NULL;
106 MediaCatMoniker * pMoniker = NULL;
110 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
114 *pchEaten = strlenW(pszDisplayName);
116 pszDisplayName = strchrW(pszDisplayName, '{');
117 pszBetween = strchrW(pszDisplayName, '}') + 2;
119 /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID)
120 * + 1 (for NULL character)
122 pszClass = CoTaskMemAlloc((int)(pszBetween - pszDisplayName) * sizeof(WCHAR));
124 return E_OUTOFMEMORY;
126 strncpyW(pszClass, pszDisplayName, (int)(pszBetween - pszDisplayName) - 1);
127 pszClass[(int)(pszBetween - pszDisplayName) - 1] = 0;
129 TRACE("Device CLSID: %s\n", debugstr_w(pszClass));
131 res = CLSIDFromString(pszClass, &clsidDevice);
135 res = DEVENUM_ICreateDevEnum_CreateClassEnumerator((ICreateDevEnum *)(char*)&DEVENUM_CreateDevEnum, &clsidDevice, &pEm, 0);
136 if (res == S_FALSE) /* S_FALSE means no category */
142 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
145 if (RegCreateKeyW(((EnumMonikerImpl *)pEm)->hkey,
147 &pMoniker->hkey) == ERROR_SUCCESS)
148 *ppmkOut = (LPMONIKER)pMoniker;
151 IMoniker_Release((LPMONIKER)pMoniker);
158 IEnumMoniker_Release(pEm);
161 CoTaskMemFree(pszClass);
163 TRACE("-- returning: %lx\n", res);
167 /**********************************************************************
168 * IParseDisplayName_Vtbl
170 static ICOM_VTABLE(IParseDisplayName) IParseDisplayName_Vtbl =
172 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
173 DEVENUM_IParseDisplayName_QueryInterface,
174 DEVENUM_IParseDisplayName_AddRef,
175 DEVENUM_IParseDisplayName_Release,
176 DEVENUM_IParseDisplayName_ParseDisplayName
179 /* The one instance of this class */
180 ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl, 0 };