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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
37 if (ppvObj == NULL) return E_POINTER;
39 if (IsEqualGUID(riid, &IID_IUnknown) ||
40 IsEqualGUID(riid, &IID_IParseDisplayName))
43 IParseDisplayName_AddRef(iface);
47 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
51 /**********************************************************************
52 * DEVENUM_IParseDisplayName_AddRef (also IUnknown)
54 static ULONG WINAPI DEVENUM_IParseDisplayName_AddRef(LPPARSEDISPLAYNAME iface)
60 return 2; /* non-heap based object */
63 /**********************************************************************
64 * DEVENUM_IParseDisplayName_Release (also IUnknown)
66 static ULONG WINAPI DEVENUM_IParseDisplayName_Release(LPPARSEDISPLAYNAME iface)
70 DEVENUM_UnlockModule();
72 return 1; /* non-heap based object */
75 /**********************************************************************
76 * DEVENUM_IParseDisplayName_ParseDisplayName
78 * Creates a moniker referenced to by the display string argument
81 * Might not handle more complicated strings properly (ie anything
82 * not in "@device:sw:{CLSID1}\<filter name or CLSID>" format
84 static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName(
85 LPPARSEDISPLAYNAME iface,
87 LPOLESTR pszDisplayName,
91 LPOLESTR pszBetween = NULL;
92 LPOLESTR pszClass = NULL;
93 MediaCatMoniker * pMoniker = NULL;
96 WCHAR wszRegKeyName[MAX_PATH];
99 static const WCHAR wszRegSeparator[] = {'\\', 0 };
101 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
105 *pchEaten = strlenW(pszDisplayName);
107 pszDisplayName = strchrW(pszDisplayName, '{');
108 pszBetween = strchrW(pszDisplayName, '}') + 2;
110 /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID)
111 * + 1 (for NULL character)
113 classlen = (int)(pszBetween - pszDisplayName - 1);
114 pszClass = CoTaskMemAlloc((classlen + 1) * sizeof(WCHAR));
116 return E_OUTOFMEMORY;
118 memcpy(pszClass, pszDisplayName, classlen * sizeof(WCHAR));
119 pszClass[classlen] = 0;
121 TRACE("Device CLSID: %s\n", debugstr_w(pszClass));
123 res = CLSIDFromString(pszClass, &clsidDevice);
127 res = DEVENUM_GetCategoryKey(&clsidDevice, &hbasekey, wszRegKeyName, MAX_PATH);
132 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
135 strcatW(wszRegKeyName, wszRegSeparator);
136 strcatW(wszRegKeyName, pszBetween);
138 if (RegCreateKeyW(hbasekey, wszRegKeyName, &pMoniker->hkey) == ERROR_SUCCESS)
139 *ppmkOut = (LPMONIKER)pMoniker;
142 IMoniker_Release((LPMONIKER)pMoniker);
148 CoTaskMemFree(pszClass);
150 TRACE("-- returning: %x\n", res);
154 /**********************************************************************
155 * IParseDisplayName_Vtbl
157 static const IParseDisplayNameVtbl IParseDisplayName_Vtbl =
159 DEVENUM_IParseDisplayName_QueryInterface,
160 DEVENUM_IParseDisplayName_AddRef,
161 DEVENUM_IParseDisplayName_Release,
162 DEVENUM_IParseDisplayName_ParseDisplayName
165 /* The one instance of this class */
166 ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl };