2 * Copyright 2013 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wbemdisp_private.h"
23 #include <wbemdisp_classes.h>
25 static HINSTANCE instance
;
29 IMoniker IMoniker_iface
;
34 static inline struct moniker
*impl_from_IMoniker(
37 return CONTAINING_RECORD( iface
, struct moniker
, IMoniker_iface
);
40 static ULONG WINAPI
moniker_AddRef(
43 struct moniker
*moniker
= impl_from_IMoniker( iface
);
44 return InterlockedIncrement( &moniker
->refs
);
47 static ULONG WINAPI
moniker_Release(
50 struct moniker
*moniker
= impl_from_IMoniker( iface
);
51 LONG refs
= InterlockedDecrement( &moniker
->refs
);
54 TRACE( "destroying %p\n", moniker
);
55 IUnknown_Release( moniker
->obj
);
61 static HRESULT WINAPI
moniker_QueryInterface(
62 IMoniker
*iface
, REFIID riid
, void **ppvObject
)
64 struct moniker
*moniker
= impl_from_IMoniker( iface
);
66 TRACE( "%p, %s, %p\n", moniker
, debugstr_guid( riid
), ppvObject
);
68 if (IsEqualGUID( riid
, &IID_IMoniker
) ||
69 IsEqualGUID( riid
, &IID_IUnknown
))
75 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
78 IMoniker_AddRef( iface
);
82 static HRESULT WINAPI
moniker_GetClassID(
83 IMoniker
*iface
, CLSID
*pClassID
)
89 static HRESULT WINAPI
moniker_IsDirty(
96 static HRESULT WINAPI
moniker_Load(
97 IMoniker
*iface
, IStream
*pStm
)
103 static HRESULT WINAPI
moniker_Save(
104 IMoniker
*iface
, IStream
*pStm
, BOOL fClearDirty
)
110 static HRESULT WINAPI
moniker_GetSizeMax(
111 IMoniker
*iface
, ULARGE_INTEGER
*pcbSize
)
117 static HRESULT WINAPI
moniker_BindToObject(
118 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riidResult
, void **ppvResult
)
120 struct moniker
*moniker
= impl_from_IMoniker( iface
);
122 TRACE( "%p, %p, %p, %s, %p\n", iface
, pbc
, pmkToLeft
, debugstr_guid(riidResult
), ppvResult
);
123 return IUnknown_QueryInterface( moniker
->obj
, riidResult
, ppvResult
);
126 static HRESULT WINAPI
moniker_BindToStorage(
127 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riid
, void **ppvObj
)
133 static HRESULT WINAPI
moniker_Reduce(
134 IMoniker
*iface
, IBindCtx
*pbc
, DWORD dwReduceHowFar
, IMoniker
**ppmkToLeft
, IMoniker
**ppmkReduced
)
140 static HRESULT WINAPI
moniker_ComposeWith(
141 IMoniker
*iface
, IMoniker
*pmkRight
, BOOL fOnlyIfNotGeneric
, IMoniker
**ppmkComposite
)
147 static HRESULT WINAPI
moniker_Enum(
148 IMoniker
*iface
, BOOL fForward
, IEnumMoniker
**ppenumMoniker
)
154 static HRESULT WINAPI
moniker_IsEqual(
155 IMoniker
*iface
, IMoniker
*pmkOtherMoniker
)
161 static HRESULT WINAPI
moniker_Hash(
162 IMoniker
*iface
, DWORD
*pdwHash
)
168 static HRESULT WINAPI
moniker_IsRunning(
169 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, IMoniker
*pmkNewlyRunning
)
175 static HRESULT WINAPI
moniker_GetTimeOfLastChange(
176 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, FILETIME
*pFileTime
)
182 static HRESULT WINAPI
moniker_Inverse(
183 IMoniker
*iface
, IMoniker
**ppmk
)
189 static HRESULT WINAPI
moniker_CommonPrefixWith(
190 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkPrefix
)
196 static HRESULT WINAPI
moniker_RelativePathTo(
197 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkRelPath
)
203 static HRESULT WINAPI
moniker_GetDisplayName(
204 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR
*ppszDisplayName
)
210 static HRESULT WINAPI
moniker_ParseDisplayName(
211 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
*pchEaten
,
218 static HRESULT WINAPI
moniker_IsSystemMoniker(
219 IMoniker
*iface
, DWORD
*pdwMksys
)
225 static const IMonikerVtbl moniker_vtbl
=
227 moniker_QueryInterface
,
235 moniker_BindToObject
,
236 moniker_BindToStorage
,
243 moniker_GetTimeOfLastChange
,
245 moniker_CommonPrefixWith
,
246 moniker_RelativePathTo
,
247 moniker_GetDisplayName
,
248 moniker_ParseDisplayName
,
249 moniker_IsSystemMoniker
252 static HRESULT
Moniker_create( IUnknown
*unk
, IMoniker
**obj
)
254 struct moniker
*moniker
;
256 TRACE( "%p, %p\n", unk
, obj
);
258 if (!(moniker
= heap_alloc( sizeof(*moniker
) ))) return E_OUTOFMEMORY
;
259 moniker
->IMoniker_iface
.lpVtbl
= &moniker_vtbl
;
262 IUnknown_AddRef( moniker
->obj
);
264 *obj
= &moniker
->IMoniker_iface
;
265 TRACE( "returning iface %p\n", *obj
);
269 static HRESULT WINAPI
WinMGMTS_QueryInterface(IParseDisplayName
*iface
, REFIID riid
, void **ppv
)
271 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
272 TRACE("(IID_IUnknown %p)\n", ppv
);
274 }else if(IsEqualGUID(riid
, &IID_IParseDisplayName
)) {
275 TRACE("(IID_IParseDisplayName %p)\n", ppv
);
278 WARN("Unsupported riid %s\n", debugstr_guid(riid
));
280 return E_NOINTERFACE
;
283 IUnknown_AddRef((IUnknown
*)*ppv
);
287 static ULONG WINAPI
WinMGMTS_AddRef(IParseDisplayName
*iface
)
292 static ULONG WINAPI
WinMGMTS_Release(IParseDisplayName
*iface
)
297 static HRESULT
parse_path( const WCHAR
*str
, BSTR
*server
, BSTR
*namespace, BSTR
*relative
)
303 *server
= *namespace = *relative
= NULL
;
305 hr
= CoCreateInstance( &CLSID_WbemDefPath
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWbemPath
, (void **)&path
);
306 if (hr
!= S_OK
) return hr
;
308 hr
= IWbemPath_SetText( path
, WBEMPATH_CREATE_ACCEPT_ALL
, str
);
309 if (hr
!= S_OK
) goto done
;
312 hr
= IWbemPath_GetServer( path
, &len
, NULL
);
315 if (!(*server
= SysAllocStringLen( NULL
, len
)))
320 hr
= IWbemPath_GetServer( path
, &len
, *server
);
321 if (hr
!= S_OK
) goto done
;
325 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, NULL
);
328 if (!(*namespace = SysAllocStringLen( NULL
, len
)))
333 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, *namespace );
334 if (hr
!= S_OK
) goto done
;
337 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, NULL
);
340 if (!(*relative
= SysAllocStringLen( NULL
, len
)))
345 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, *relative
);
349 IWbemPath_Release( path
);
352 SysFreeString( *server
);
353 SysFreeString( *namespace );
354 SysFreeString( *relative
);
359 static HRESULT WINAPI
WinMGMTS_ParseDisplayName(IParseDisplayName
*iface
, IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
360 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
362 static const WCHAR prefixW
[] = {'w','i','n','m','g','m','t','s',':',0};
363 const DWORD prefix_len
= sizeof(prefixW
) / sizeof(prefixW
[0]) - 1;
364 ISWbemLocator
*locator
= NULL
;
365 ISWbemServices
*services
= NULL
;
366 ISWbemObject
*obj
= NULL
;
367 BSTR server
, namespace, relative
;
371 TRACE( "%p, %p, %s, %p, %p\n", iface
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
373 if (strncmpiW( pszDisplayName
, prefixW
, prefix_len
)) return MK_E_SYNTAX
;
375 p
= pszDisplayName
+ prefix_len
;
378 FIXME( "ignoring security settings\n" );
379 while (*p
&& *p
!= '}') p
++;
383 hr
= parse_path( p
, &server
, &namespace, &relative
);
384 if (hr
!= S_OK
) return hr
;
386 hr
= SWbemLocator_create( (void **)&locator
);
387 if (hr
!= S_OK
) goto done
;
389 hr
= ISWbemLocator_ConnectServer( locator
, server
, namespace, NULL
, NULL
, NULL
, NULL
, 0, NULL
, &services
);
390 if (hr
!= S_OK
) goto done
;
392 if (!relative
|| !*relative
) Moniker_create( (IUnknown
*)services
, ppmkOut
);
395 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
396 if (hr
!= S_OK
) goto done
;
397 hr
= Moniker_create( (IUnknown
*)obj
, ppmkOut
);
401 if (obj
) ISWbemObject_Release( obj
);
402 if (services
) ISWbemServices_Release( services
);
403 if (locator
) ISWbemLocator_Release( locator
);
404 SysFreeString( server
);
405 SysFreeString( namespace );
406 SysFreeString( relative
);
407 if (hr
== S_OK
) *pchEaten
= strlenW( pszDisplayName
);
411 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
412 WinMGMTS_QueryInterface
,
415 WinMGMTS_ParseDisplayName
418 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
420 static HRESULT
WinMGMTS_create(void **ppv
)
428 IClassFactory IClassFactory_iface
;
429 HRESULT (*fnCreateInstance
)( LPVOID
* );
432 static inline struct factory
*impl_from_IClassFactory( IClassFactory
*iface
)
434 return CONTAINING_RECORD( iface
, struct factory
, IClassFactory_iface
);
437 static HRESULT WINAPI
factory_QueryInterface( IClassFactory
*iface
, REFIID riid
, LPVOID
*obj
)
439 if (IsEqualGUID( riid
, &IID_IUnknown
) || IsEqualGUID( riid
, &IID_IClassFactory
))
441 IClassFactory_AddRef( iface
);
445 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
446 return E_NOINTERFACE
;
449 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
454 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
459 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
462 struct factory
*factory
= impl_from_IClassFactory( iface
);
466 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
469 if (outer
) return CLASS_E_NOAGGREGATION
;
471 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
475 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
476 IUnknown_Release( unk
);
480 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
482 FIXME( "%p, %d\n", iface
, lock
);
486 static const struct IClassFactoryVtbl factory_vtbl
=
488 factory_QueryInterface
,
491 factory_CreateInstance
,
495 static struct factory swbem_locator_cf
= { { &factory_vtbl
}, SWbemLocator_create
};
496 static struct factory winmgmts_cf
= { { &factory_vtbl
}, WinMGMTS_create
};
498 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
503 case DLL_WINE_PREATTACH
:
504 return FALSE
; /* prefer native version */
505 case DLL_PROCESS_ATTACH
:
507 DisableThreadLibraryCalls( hinst
);
513 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID iid
, LPVOID
*obj
)
515 IClassFactory
*cf
= NULL
;
517 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), obj
);
519 if (IsEqualGUID( rclsid
, &CLSID_SWbemLocator
))
520 cf
= &swbem_locator_cf
.IClassFactory_iface
;
521 else if (IsEqualGUID( rclsid
, &CLSID_WinMGMTS
))
522 cf
= &winmgmts_cf
.IClassFactory_iface
;
524 return CLASS_E_CLASSNOTAVAILABLE
;
526 return IClassFactory_QueryInterface( cf
, iid
, obj
);
529 /***********************************************************************
530 * DllCanUnloadNow (WBEMDISP.@)
532 HRESULT WINAPI
DllCanUnloadNow(void)
537 /***********************************************************************
538 * DllRegisterServer (WBEMDISP.@)
540 HRESULT WINAPI
DllRegisterServer(void)
542 return __wine_register_resources( instance
);
545 /***********************************************************************
546 * DllUnregisterServer (WBEMDISP.@)
548 HRESULT WINAPI
DllUnregisterServer(void)
550 return __wine_unregister_resources( instance
);