riched20: Use cell ptrs in the rtf parsing code.
[wine/zf.git] / dlls / devenum / parsedisplayname.c
blobf24b4329c80c8334ae9ab7bbfd3f88a825ccad5e
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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_parser_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
32 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
34 if (!ppv)
35 return E_POINTER;
37 if (IsEqualGUID(riid, &IID_IUnknown) ||
38 IsEqualGUID(riid, &IID_IParseDisplayName))
40 *ppv = iface;
41 IParseDisplayName_AddRef(iface);
42 return S_OK;
45 FIXME("- no interface IID: %s\n", debugstr_guid(riid));
46 *ppv = NULL;
47 return E_NOINTERFACE;
50 static ULONG WINAPI devenum_parser_AddRef(IParseDisplayName *iface)
52 TRACE("\n");
54 DEVENUM_LockModule();
56 return 2; /* non-heap based object */
59 static ULONG WINAPI devenum_parser_Release(IParseDisplayName *iface)
61 TRACE("\n");
63 DEVENUM_UnlockModule();
65 return 1; /* non-heap based object */
68 static HRESULT WINAPI devenum_parser_ParseDisplayName(IParseDisplayName *iface,
69 IBindCtx *pbc, LPOLESTR name, ULONG *eaten, IMoniker **ret)
71 struct moniker *moniker;
72 WCHAR buffer[MAX_PATH];
73 enum device_type type;
74 GUID class, clsid;
76 TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(name), eaten, ret);
78 *ret = NULL;
79 if (eaten)
80 *eaten = wcslen(name);
82 name = wcschr(name, ':') + 1;
84 if (!wcsncmp(name, L"sw:", 3))
86 type = DEVICE_FILTER;
87 name += 3;
89 else if (!wcsncmp(name, L"cm:", 3))
91 type = DEVICE_CODEC;
92 name += 3;
94 else if (!wcsncmp(name, L"dmo:", 4))
96 type = DEVICE_DMO;
97 name += 4;
99 else
101 FIXME("unhandled device type %s\n", debugstr_w(name));
102 return MK_E_SYNTAX;
105 if (type == DEVICE_DMO)
107 lstrcpynW(buffer, name, CHARS_IN_GUID);
108 if (FAILED(CLSIDFromString(buffer, &clsid)))
109 return MK_E_SYNTAX;
111 lstrcpynW(buffer, name + CHARS_IN_GUID - 1, CHARS_IN_GUID);
112 if (FAILED(CLSIDFromString(buffer, &class)))
113 return MK_E_SYNTAX;
115 moniker = dmo_moniker_create(class, clsid);
117 else
119 lstrcpynW(buffer, name, CHARS_IN_GUID);
120 if (CLSIDFromString(buffer, &class) == S_OK)
122 name += CHARS_IN_GUID;
123 if (type == DEVICE_FILTER)
124 moniker = filter_moniker_create(&class, name);
125 else
126 moniker = codec_moniker_create(&class, name);
128 else
130 if (type == DEVICE_FILTER)
131 moniker = filter_moniker_create(NULL, name);
132 else
133 moniker = codec_moniker_create(NULL, name);
137 if (!moniker)
138 return E_OUTOFMEMORY;
140 *ret = &moniker->IMoniker_iface;
141 return S_OK;
144 /**********************************************************************
145 * IParseDisplayName_Vtbl
147 static const IParseDisplayNameVtbl IParseDisplayName_Vtbl =
149 devenum_parser_QueryInterface,
150 devenum_parser_AddRef,
151 devenum_parser_Release,
152 devenum_parser_ParseDisplayName,
155 /* The one instance of this class */
156 IParseDisplayName devenum_parser = { &IParseDisplayName_Vtbl };