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 not in
94 * "@device:sw:{CLSID1}\{CLSID2}" 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;
109 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
113 *pchEaten = strlenW(pszDisplayName);
115 pszDisplayName = strchrW(pszDisplayName, '{');
116 pszBetween = strchrW(pszDisplayName, '}') + 2;
118 /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID)
119 * + 1 (for NULL character)
121 pszClass = CoTaskMemAlloc((int)(pszBetween - pszDisplayName) * sizeof(WCHAR));
123 return E_OUTOFMEMORY;
125 strncpyW(pszClass, pszDisplayName, (int)(pszBetween - pszDisplayName) - 1);
126 pszClass[(int)(pszBetween - pszDisplayName) - 1] = 0;
128 TRACE("Device CLSID: %s\n", debugstr_w(pszClass));
130 res = CLSIDFromString(pszClass, &clsidDevice);
134 res = DEVENUM_ICreateDevEnum_CreateClassEnumerator((ICreateDevEnum *)(char*)&DEVENUM_CreateDevEnum, &clsidDevice, &pEm, 0);
135 if (res == S_FALSE) /* S_FALSE means no category */
141 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
144 if (RegCreateKeyW(((EnumMonikerImpl *)pEm)->hkey,
146 &pMoniker->hkey) == ERROR_SUCCESS)
147 *ppmkOut = (LPMONIKER)pMoniker;
150 IMoniker_Release((LPMONIKER)pMoniker);
157 IEnumMoniker_Release(pEm);
160 CoTaskMemFree(pszClass);
162 TRACE("-- returning: %lx\n", res);
166 /**********************************************************************
167 * IParseDisplayName_Vtbl
169 static ICOM_VTABLE(IParseDisplayName) IParseDisplayName_Vtbl =
171 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
172 DEVENUM_IParseDisplayName_QueryInterface,
173 DEVENUM_IParseDisplayName_AddRef,
174 DEVENUM_IParseDisplayName_Release,
175 DEVENUM_IParseDisplayName_ParseDisplayName
178 /* The one instance of this class */
179 ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl, 0 };