Add an empty hook function for WSASetBlockingHook to return.
[wine/wine64.git] / dlls / devenum / parsedisplayname.c
blobb5b1c13d23abcc21bb906e96842117c5b638350c
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 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);
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 ICOM_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 ICOM_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 not in
94 * "@device:sw:{CLSID1}\{CLSID2}" 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;
109 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
111 *ppmkOut = NULL;
112 if (pchEaten)
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));
122 if (!pszClass)
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);
132 if (SUCCEEDED(res))
134 res = DEVENUM_ICreateDevEnum_CreateClassEnumerator((ICreateDevEnum *)&DEVENUM_CreateDevEnum, &clsidDevice, &pEm, 0);
137 if (SUCCEEDED(res))
139 pMoniker = DEVENUM_IMediaCatMoniker_Construct();
140 if (pMoniker)
142 if (RegCreateKeyW(((EnumMonikerImpl *)pEm)->hkey,
143 pszBetween,
144 &pMoniker->hkey) == ERROR_SUCCESS)
145 *ppmkOut = (LPMONIKER)pMoniker;
146 else
148 IMoniker_Release((LPMONIKER)pMoniker);
149 res = MK_E_NOOBJECT;
154 if (pEm)
155 IEnumMoniker_Release(pEm);
157 if (pszClass)
158 CoTaskMemFree(pszClass);
160 TRACE("-- returning: %lx\n", res);
161 return res;
164 /**********************************************************************
165 * IParseDisplayName_Vtbl
167 static ICOM_VTABLE(IParseDisplayName) IParseDisplayName_Vtbl =
169 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
170 DEVENUM_IParseDisplayName_QueryInterface,
171 DEVENUM_IParseDisplayName_AddRef,
172 DEVENUM_IParseDisplayName_Release,
173 DEVENUM_IParseDisplayName_ParseDisplayName
176 /* The one instance of this class */
177 ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl, 0 };