Removed some uses of the non-standard ICOM_THIS macro.
[wine/multimedia.git] / dlls / devenum / parsedisplayname.c
blobeb8cb076ad5b7735c58bbd88599c076e6aeb778e
1 /*
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
20 * NOTES ON THIS FILE:
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,
32 REFIID riid,
33 LPVOID *ppvObj)
35 ParseDisplayNameImpl *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);
45 return S_OK;
48 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
49 return E_NOINTERFACE;
52 /**********************************************************************
53 * DEVENUM_IParseDisplayName_AddRef (also IUnknown)
55 static ULONG WINAPI DEVENUM_IParseDisplayName_AddRef(LPPARSEDISPLAYNAME iface)
57 ParseDisplayNameImpl *This = (ParseDisplayNameImpl *)iface;
58 TRACE("\n");
60 if (This == NULL) return E_POINTER;
62 if (InterlockedIncrement(&This->ref) == 1) {
63 InterlockedIncrement(&dll_ref);
66 return ++This->ref;
69 /**********************************************************************
70 * DEVENUM_IParseDisplayName_Release (also IUnknown)
72 static ULONG WINAPI DEVENUM_IParseDisplayName_Release(LPPARSEDISPLAYNAME iface)
74 ParseDisplayNameImpl *This = (ParseDisplayNameImpl *)iface;
75 ULONG ref;
76 TRACE("\n");
78 if (This == NULL) return E_POINTER;
80 ref = --This->ref;
81 if (InterlockedDecrement(&This->ref) == 0) {
82 InterlockedDecrement(&dll_ref);
84 return ref;
87 /**********************************************************************
88 * DEVENUM_IParseDisplayName_ParseDisplayName
90 * Creates a moniker referenced to by the display string argument
92 * POSSIBLE BUGS:
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,
98 IBindCtx *pbc,
99 LPOLESTR pszDisplayName,
100 ULONG *pchEaten,
101 IMoniker **ppmkOut)
103 LPOLESTR pszBetween = NULL;
104 LPOLESTR pszClass = NULL;
105 IEnumMoniker * pEm = NULL;
106 MediaCatMoniker * pMoniker = NULL;
107 CLSID clsidDevice;
108 HRESULT res = S_OK;
110 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
112 *ppmkOut = NULL;
113 if (pchEaten)
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));
123 if (!pszClass)
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);
133 if (SUCCEEDED(res))
135 res = DEVENUM_ICreateDevEnum_CreateClassEnumerator((ICreateDevEnum *)(char*)&DEVENUM_CreateDevEnum, &clsidDevice, &pEm, 0);
136 if (res == S_FALSE) /* S_FALSE means no category */
137 res = MK_E_NOOBJECT;
140 if (SUCCEEDED(res))
142 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
143 if (pMoniker)
145 if (RegCreateKeyW(((EnumMonikerImpl *)pEm)->hkey,
146 pszBetween,
147 &pMoniker->hkey) == ERROR_SUCCESS)
148 *ppmkOut = (LPMONIKER)pMoniker;
149 else
151 IMoniker_Release((LPMONIKER)pMoniker);
152 res = MK_E_NOOBJECT;
157 if (pEm)
158 IEnumMoniker_Release(pEm);
160 if (pszClass)
161 CoTaskMemFree(pszClass);
163 TRACE("-- returning: %lx\n", res);
164 return res;
167 /**********************************************************************
168 * IParseDisplayName_Vtbl
170 static IParseDisplayNameVtbl IParseDisplayName_Vtbl =
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 };