Clear buffer before querying the registry in SYSPARAMS_Load.
[wine/multimedia.git] / dlls / itss / moniker.c
blobd5165d799e7484c03df7aa0530c3469ae23786e3
1 /*
2 * ITSS Moniker implementation
4 * Copyright 2004 Mike McCormack
6 * Implementation of the infamous mk:@MSITStore moniker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "ole2.h"
37 #include "itss.h"
38 #include "uuids.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 #include "itsstor.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47 extern ULONG dll_count;
49 /*****************************************************************************/
51 typedef struct {
52 const IMonikerVtbl *vtbl_ITS_IMoniker;
53 DWORD ref;
54 LPWSTR szHtml;
55 WCHAR szFile[1];
56 } ITS_IMonikerImpl;
58 /*** IUnknown methods ***/
59 static HRESULT WINAPI ITS_IMonikerImpl_QueryInterface(
60 IMoniker* iface,
61 REFIID riid,
62 void** ppvObject)
64 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
66 if (IsEqualGUID(riid, &IID_IUnknown)
67 || IsEqualGUID(riid, &IID_IParseDisplayName))
69 IClassFactory_AddRef(iface);
70 *ppvObject = This;
71 return S_OK;
74 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
75 return E_NOINTERFACE;
78 static ULONG WINAPI ITS_IMonikerImpl_AddRef(
79 IMoniker* iface)
81 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
82 TRACE("%p\n", This);
83 return InterlockedIncrement(&This->ref);
86 static ULONG WINAPI ITS_IMonikerImpl_Release(
87 IMoniker* iface)
89 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
90 ULONG ref = InterlockedDecrement(&This->ref);
92 if (ref == 0) {
93 HeapFree(GetProcessHeap(), 0, This);
94 InterlockedDecrement(&dll_count);
97 return ref;
100 /*** IPersist methods ***/
101 static HRESULT WINAPI ITS_IMonikerImpl_GetClassID(
102 IMoniker* iface,
103 CLSID* pClassID)
105 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
107 TRACE("%p %p\n", This, pClassID);
108 memcpy( pClassID, &CLSID_ITStorage, sizeof (CLSID) );
109 return S_OK;
112 /*** IPersistStream methods ***/
113 static HRESULT WINAPI ITS_IMonikerImpl_IsDirty(
114 IMoniker* iface)
116 FIXME("\n");
117 return E_NOTIMPL;
120 static HRESULT WINAPI ITS_IMonikerImpl_Load(
121 IMoniker* iface,
122 IStream* pStm)
124 FIXME("\n");
125 return E_NOTIMPL;
128 static HRESULT WINAPI ITS_IMonikerImpl_Save(
129 IMoniker* iface,
130 IStream* pStm,
131 BOOL fClearDirty)
133 FIXME("\n");
134 return E_NOTIMPL;
137 static HRESULT WINAPI ITS_IMonikerImpl_GetSizeMax(
138 IMoniker* iface,
139 ULARGE_INTEGER* pcbSize)
141 FIXME("\n");
142 return E_NOTIMPL;
145 /*** IMoniker methods ***/
146 static HRESULT WINAPI ITS_IMonikerImpl_BindToObject(
147 IMoniker* iface,
148 IBindCtx* pbc,
149 IMoniker* pmkToLeft,
150 REFIID riidResult,
151 void** ppvResult)
153 FIXME("\n");
154 return E_NOTIMPL;
157 static HRESULT WINAPI ITS_IMonikerImpl_BindToStorage(
158 IMoniker* iface,
159 IBindCtx* pbc,
160 IMoniker* pmkToLeft,
161 REFIID riid,
162 void** ppvObj)
164 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
165 DWORD grfMode = STGM_SIMPLE | STGM_READ | STGM_SHARE_EXCLUSIVE;
166 HRESULT r;
167 IStorage *stg = NULL;
169 TRACE("%p %p %p %s %p\n", This,
170 pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
172 r = ITSS_StgOpenStorage( This->szFile, NULL, grfMode, 0, 0, &stg );
173 if( r == S_OK )
175 TRACE("Opened storage %s\n", debugstr_w( This->szFile ) );
176 if (IsEqualGUID(riid, &IID_IStream))
177 r = IStorage_OpenStream( stg, This->szHtml,
178 NULL, grfMode, 0, (IStream**)ppvObj );
179 else if (IsEqualGUID(riid, &IID_IStorage))
180 r = IStorage_OpenStorage( stg, This->szHtml,
181 NULL, grfMode, NULL, 0, (IStorage**)ppvObj );
182 else
183 r = STG_E_ACCESSDENIED;
184 IStorage_Release( stg );
187 return r;
190 static HRESULT WINAPI ITS_IMonikerImpl_Reduce(
191 IMoniker* iface,
192 IBindCtx* pbc,
193 DWORD dwReduceHowFar,
194 IMoniker** ppmkToLeft,
195 IMoniker** ppmkReduced)
197 FIXME("\n");
198 return E_NOTIMPL;
201 static HRESULT WINAPI ITS_IMonikerImpl_ComposeWith(
202 IMoniker* iface,
203 IMoniker* pmkRight,
204 BOOL fOnlyIfNotGeneric,
205 IMoniker** ppmkComposite)
207 FIXME("\n");
208 return E_NOTIMPL;
211 static HRESULT WINAPI ITS_IMonikerImpl_Enum(
212 IMoniker* iface,
213 BOOL fForward,
214 IEnumMoniker** ppenumMoniker)
216 FIXME("\n");
217 return E_NOTIMPL;
220 static HRESULT WINAPI ITS_IMonikerImpl_IsEqual(
221 IMoniker* iface,
222 IMoniker* pmkOtherMoniker)
224 FIXME("\n");
225 return E_NOTIMPL;
228 static HRESULT WINAPI ITS_IMonikerImpl_Hash(
229 IMoniker* iface,
230 DWORD* pdwHash)
232 FIXME("\n");
233 return E_NOTIMPL;
236 static HRESULT WINAPI ITS_IMonikerImpl_IsRunning(
237 IMoniker* iface,
238 IBindCtx* pbc,
239 IMoniker* pmkToLeft,
240 IMoniker* pmkNewlyRunning)
242 FIXME("\n");
243 return E_NOTIMPL;
246 static HRESULT WINAPI ITS_IMonikerImpl_GetTimeOfLastChange(
247 IMoniker* iface,
248 IBindCtx* pbc,
249 IMoniker* pmkToLeft,
250 FILETIME* pFileTime)
252 FIXME("\n");
253 return E_NOTIMPL;
256 static HRESULT WINAPI ITS_IMonikerImpl_Inverse(
257 IMoniker* iface,
258 IMoniker** ppmk)
260 FIXME("\n");
261 return E_NOTIMPL;
264 static HRESULT WINAPI ITS_IMonikerImpl_CommonPrefixWith(
265 IMoniker* iface,
266 IMoniker* pmkOther,
267 IMoniker** ppmkPrefix)
269 FIXME("\n");
270 return E_NOTIMPL;
273 static HRESULT WINAPI ITS_IMonikerImpl_RelativePathTo(
274 IMoniker* iface,
275 IMoniker* pmkOther,
276 IMoniker** ppmkRelPath)
278 FIXME("\n");
279 return E_NOTIMPL;
282 static HRESULT WINAPI ITS_IMonikerImpl_GetDisplayName(
283 IMoniker* iface,
284 IBindCtx* pbc,
285 IMoniker* pmkToLeft,
286 LPOLESTR* ppszDisplayName)
288 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
289 static const WCHAR szFormat[] = {
290 'm','s','-','i','t','s',':','%','s',':',':','%','s',0 };
291 DWORD len = sizeof szFormat / sizeof(WCHAR);
292 LPWSTR str;
294 TRACE("%p %p %p %p\n", iface, pbc, pmkToLeft, ppszDisplayName);
296 len = strlenW( This->szFile ) + strlenW( This->szHtml );
297 str = CoTaskMemAlloc( len*sizeof(WCHAR) );
298 sprintfW( str, szFormat, This->szFile, This->szHtml );
300 *ppszDisplayName = str;
302 return S_OK;
305 static HRESULT WINAPI ITS_IMonikerImpl_ParseDisplayName(
306 IMoniker* iface,
307 IBindCtx* pbc,
308 IMoniker* pmkToLeft,
309 LPOLESTR pszDisplayName,
310 ULONG* pchEaten,
311 IMoniker** ppmkOut)
313 FIXME("\n");
314 return E_NOTIMPL;
317 static HRESULT WINAPI ITS_IMonikerImpl_IsSystemMoniker(
318 IMoniker* iface,
319 DWORD* pdwMksys)
321 FIXME("\n");
322 return E_NOTIMPL;
325 static const IMonikerVtbl ITS_IMonikerImpl_Vtbl =
327 ITS_IMonikerImpl_QueryInterface,
328 ITS_IMonikerImpl_AddRef,
329 ITS_IMonikerImpl_Release,
330 ITS_IMonikerImpl_GetClassID,
331 ITS_IMonikerImpl_IsDirty,
332 ITS_IMonikerImpl_Load,
333 ITS_IMonikerImpl_Save,
334 ITS_IMonikerImpl_GetSizeMax,
335 ITS_IMonikerImpl_BindToObject,
336 ITS_IMonikerImpl_BindToStorage,
337 ITS_IMonikerImpl_Reduce,
338 ITS_IMonikerImpl_ComposeWith,
339 ITS_IMonikerImpl_Enum,
340 ITS_IMonikerImpl_IsEqual,
341 ITS_IMonikerImpl_Hash,
342 ITS_IMonikerImpl_IsRunning,
343 ITS_IMonikerImpl_GetTimeOfLastChange,
344 ITS_IMonikerImpl_Inverse,
345 ITS_IMonikerImpl_CommonPrefixWith,
346 ITS_IMonikerImpl_RelativePathTo,
347 ITS_IMonikerImpl_GetDisplayName,
348 ITS_IMonikerImpl_ParseDisplayName,
349 ITS_IMonikerImpl_IsSystemMoniker
352 static HRESULT ITS_IMoniker_create( IMoniker **ppObj, LPWSTR name, DWORD n )
354 ITS_IMonikerImpl *itsmon;
355 DWORD sz;
357 /* szFile[1] has space for one character already */
358 sz = sizeof(ITS_IMonikerImpl) + strlenW( name )*sizeof(WCHAR);
360 itsmon = HeapAlloc( GetProcessHeap(), 0, sz );
361 itsmon->vtbl_ITS_IMoniker = &ITS_IMonikerImpl_Vtbl;
362 itsmon->ref = 1;
363 strcpyW( itsmon->szFile, name );
364 itsmon->szHtml = &itsmon->szFile[n];
366 while( *itsmon->szHtml == ':' )
367 *itsmon->szHtml++ = 0;
369 TRACE("-> %p %s %s\n", itsmon,
370 debugstr_w(itsmon->szFile), debugstr_w(itsmon->szHtml) );
371 *ppObj = (IMoniker*) itsmon;
372 InterlockedIncrement(&dll_count);
374 return S_OK;
377 /*****************************************************************************/
379 typedef struct {
380 const IParseDisplayNameVtbl *vtbl_ITS_IParseDisplayName;
381 DWORD ref;
382 } ITS_IParseDisplayNameImpl;
384 static HRESULT WINAPI ITS_IParseDisplayNameImpl_QueryInterface(
385 IParseDisplayName* iface,
386 REFIID riid,
387 void** ppvObject)
389 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
391 if (IsEqualGUID(riid, &IID_IUnknown)
392 || IsEqualGUID(riid, &IID_IParseDisplayName))
394 IClassFactory_AddRef(iface);
395 *ppvObject = This;
396 return S_OK;
399 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
400 return E_NOINTERFACE;
403 static ULONG WINAPI ITS_IParseDisplayNameImpl_AddRef(
404 IParseDisplayName* iface)
406 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
407 TRACE("%p\n", This);
408 return InterlockedIncrement(&This->ref);
411 static ULONG WINAPI ITS_IParseDisplayNameImpl_Release(
412 IParseDisplayName* iface)
414 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
415 ULONG ref = InterlockedDecrement(&This->ref);
417 if (ref == 0) {
418 HeapFree(GetProcessHeap(), 0, This);
419 InterlockedDecrement(&dll_count);
422 return ref;
425 static HRESULT WINAPI ITS_IParseDisplayNameImpl_ParseDisplayName(
426 IParseDisplayName *iface,
427 IBindCtx * pbc,
428 LPOLESTR pszDisplayName,
429 ULONG * pchEaten,
430 IMoniker ** ppmkOut)
432 static const WCHAR szPrefix[] = {
433 '@','M','S','I','T','S','t','o','r','e',':',0 };
434 const DWORD prefix_len = (sizeof szPrefix/sizeof szPrefix[0])-1;
435 DWORD n;
437 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
439 TRACE("%p %s %p %p\n", This,
440 debugstr_w( pszDisplayName ), pchEaten, ppmkOut );
442 if( strncmpW( pszDisplayName, szPrefix, prefix_len ) )
443 return MK_E_SYNTAX;
445 /* search backwards for a double colon */
446 for( n = strlenW( pszDisplayName ) - 3; prefix_len <= n; n-- )
447 if( ( pszDisplayName[n] == ':' ) && ( pszDisplayName[n+1] == ':' ) )
448 break;
450 if( n < prefix_len )
451 return MK_E_SYNTAX;
453 if( !pszDisplayName[n+2] )
454 return MK_E_SYNTAX;
456 *pchEaten = strlenW( pszDisplayName ) - n - 3;
458 return ITS_IMoniker_create( ppmkOut,
459 &pszDisplayName[prefix_len], n-prefix_len );
462 static const IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl =
464 ITS_IParseDisplayNameImpl_QueryInterface,
465 ITS_IParseDisplayNameImpl_AddRef,
466 ITS_IParseDisplayNameImpl_Release,
467 ITS_IParseDisplayNameImpl_ParseDisplayName
470 HRESULT ITS_IParseDisplayName_create(IUnknown *pUnkOuter, LPVOID *ppObj)
472 ITS_IParseDisplayNameImpl *its;
474 if( pUnkOuter )
475 return CLASS_E_NOAGGREGATION;
477 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl) );
478 its->vtbl_ITS_IParseDisplayName = &ITS_IParseDisplayNameImpl_Vtbl;
479 its->ref = 1;
481 TRACE("-> %p\n", its);
482 *ppObj = (LPVOID) its;
483 InterlockedIncrement(&dll_count);
485 return S_OK;