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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "wbemdisp_private.h"
34 #include "wbemdisp_classes.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp
);
38 static HINSTANCE instance
;
42 IMoniker IMoniker_iface
;
47 static inline struct moniker
*impl_from_IMoniker(
50 return CONTAINING_RECORD( iface
, struct moniker
, IMoniker_iface
);
53 static ULONG WINAPI
moniker_AddRef(
56 struct moniker
*moniker
= impl_from_IMoniker( iface
);
57 return InterlockedIncrement( &moniker
->refs
);
60 static ULONG WINAPI
moniker_Release(
63 struct moniker
*moniker
= impl_from_IMoniker( iface
);
64 LONG refs
= InterlockedDecrement( &moniker
->refs
);
67 TRACE( "destroying %p\n", moniker
);
68 IUnknown_Release( moniker
->obj
);
74 static HRESULT WINAPI
moniker_QueryInterface(
75 IMoniker
*iface
, REFIID riid
, void **ppvObject
)
77 struct moniker
*moniker
= impl_from_IMoniker( iface
);
79 TRACE( "%p, %s, %p\n", moniker
, debugstr_guid( riid
), ppvObject
);
81 if (IsEqualGUID( riid
, &IID_IMoniker
) ||
82 IsEqualGUID( riid
, &IID_IUnknown
))
88 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
91 IMoniker_AddRef( iface
);
95 static HRESULT WINAPI
moniker_GetClassID(
96 IMoniker
*iface
, CLSID
*pClassID
)
102 static HRESULT WINAPI
moniker_IsDirty(
109 static HRESULT WINAPI
moniker_Load(
110 IMoniker
*iface
, IStream
*pStm
)
116 static HRESULT WINAPI
moniker_Save(
117 IMoniker
*iface
, IStream
*pStm
, BOOL fClearDirty
)
123 static HRESULT WINAPI
moniker_GetSizeMax(
124 IMoniker
*iface
, ULARGE_INTEGER
*pcbSize
)
130 static HRESULT WINAPI
moniker_BindToObject(
131 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riidResult
, void **ppvResult
)
133 struct moniker
*moniker
= impl_from_IMoniker( iface
);
135 TRACE( "%p, %p, %p, %s, %p\n", iface
, pbc
, pmkToLeft
, debugstr_guid(riidResult
), ppvResult
);
136 return IUnknown_QueryInterface( moniker
->obj
, riidResult
, ppvResult
);
139 static HRESULT WINAPI
moniker_BindToStorage(
140 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riid
, void **ppvObj
)
146 static HRESULT WINAPI
moniker_Reduce(
147 IMoniker
*iface
, IBindCtx
*pbc
, DWORD dwReduceHowFar
, IMoniker
**ppmkToLeft
, IMoniker
**ppmkReduced
)
153 static HRESULT WINAPI
moniker_ComposeWith(
154 IMoniker
*iface
, IMoniker
*pmkRight
, BOOL fOnlyIfNotGeneric
, IMoniker
**ppmkComposite
)
160 static HRESULT WINAPI
moniker_Enum(
161 IMoniker
*iface
, BOOL fForward
, IEnumMoniker
**ppenumMoniker
)
167 static HRESULT WINAPI
moniker_IsEqual(
168 IMoniker
*iface
, IMoniker
*pmkOtherMoniker
)
174 static HRESULT WINAPI
moniker_Hash(
175 IMoniker
*iface
, DWORD
*pdwHash
)
181 static HRESULT WINAPI
moniker_IsRunning(
182 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, IMoniker
*pmkNewlyRunning
)
188 static HRESULT WINAPI
moniker_GetTimeOfLastChange(
189 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, FILETIME
*pFileTime
)
195 static HRESULT WINAPI
moniker_Inverse(
196 IMoniker
*iface
, IMoniker
**ppmk
)
202 static HRESULT WINAPI
moniker_CommonPrefixWith(
203 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkPrefix
)
209 static HRESULT WINAPI
moniker_RelativePathTo(
210 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkRelPath
)
216 static HRESULT WINAPI
moniker_GetDisplayName(
217 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR
*ppszDisplayName
)
223 static HRESULT WINAPI
moniker_ParseDisplayName(
224 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
*pchEaten
,
231 static HRESULT WINAPI
moniker_IsSystemMoniker(
232 IMoniker
*iface
, DWORD
*pdwMksys
)
238 static const IMonikerVtbl moniker_vtbl
=
240 moniker_QueryInterface
,
248 moniker_BindToObject
,
249 moniker_BindToStorage
,
256 moniker_GetTimeOfLastChange
,
258 moniker_CommonPrefixWith
,
259 moniker_RelativePathTo
,
260 moniker_GetDisplayName
,
261 moniker_ParseDisplayName
,
262 moniker_IsSystemMoniker
265 static HRESULT
Moniker_create( IUnknown
*unk
, IMoniker
**obj
)
267 struct moniker
*moniker
;
269 TRACE( "%p, %p\n", unk
, obj
);
271 if (!(moniker
= heap_alloc( sizeof(*moniker
) ))) return E_OUTOFMEMORY
;
272 moniker
->IMoniker_iface
.lpVtbl
= &moniker_vtbl
;
275 IUnknown_AddRef( moniker
->obj
);
277 *obj
= &moniker
->IMoniker_iface
;
278 TRACE( "returning iface %p\n", *obj
);
282 static HRESULT WINAPI
WinMGMTS_QueryInterface(IParseDisplayName
*iface
, REFIID riid
, void **ppv
)
284 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
285 TRACE("(IID_IUnknown %p)\n", ppv
);
287 }else if(IsEqualGUID(riid
, &IID_IParseDisplayName
)) {
288 TRACE("(IID_IParseDisplayName %p)\n", ppv
);
291 WARN("Unsupported riid %s\n", debugstr_guid(riid
));
293 return E_NOINTERFACE
;
296 IUnknown_AddRef((IUnknown
*)*ppv
);
300 static ULONG WINAPI
WinMGMTS_AddRef(IParseDisplayName
*iface
)
305 static ULONG WINAPI
WinMGMTS_Release(IParseDisplayName
*iface
)
310 static HRESULT
parse_path( const WCHAR
*str
, BSTR
*server
, BSTR
*namespace, BSTR
*relative
)
316 *server
= *namespace = *relative
= NULL
;
318 hr
= CoCreateInstance( &CLSID_WbemDefPath
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWbemPath
, (void **)&path
);
319 if (hr
!= S_OK
) return hr
;
321 hr
= IWbemPath_SetText( path
, WBEMPATH_CREATE_ACCEPT_ALL
, str
);
322 if (hr
!= S_OK
) goto done
;
325 hr
= IWbemPath_GetServer( path
, &len
, NULL
);
328 if (!(*server
= SysAllocStringLen( NULL
, len
)))
333 hr
= IWbemPath_GetServer( path
, &len
, *server
);
334 if (hr
!= S_OK
) goto done
;
338 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, NULL
);
341 if (!(*namespace = SysAllocStringLen( NULL
, len
)))
346 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, *namespace );
347 if (hr
!= S_OK
) goto done
;
350 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, NULL
);
353 if (!(*relative
= SysAllocStringLen( NULL
, len
)))
358 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, *relative
);
362 IWbemPath_Release( path
);
365 SysFreeString( *server
);
366 SysFreeString( *namespace );
367 SysFreeString( *relative
);
372 static HRESULT WINAPI
WinMGMTS_ParseDisplayName(IParseDisplayName
*iface
, IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
373 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
375 static const WCHAR prefixW
[] = {'w','i','n','m','g','m','t','s',':',0};
376 const DWORD prefix_len
= sizeof(prefixW
) / sizeof(prefixW
[0]) - 1;
377 ISWbemLocator
*locator
= NULL
;
378 ISWbemServices
*services
= NULL
;
379 ISWbemObject
*obj
= NULL
;
380 BSTR server
, namespace, relative
;
384 TRACE( "%p, %p, %s, %p, %p\n", iface
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
386 if (strncmpiW( pszDisplayName
, prefixW
, prefix_len
)) return MK_E_SYNTAX
;
388 p
= pszDisplayName
+ prefix_len
;
391 FIXME( "ignoring security settings\n" );
392 while (*p
&& *p
!= '}') p
++;
396 hr
= parse_path( p
, &server
, &namespace, &relative
);
397 if (hr
!= S_OK
) return hr
;
399 hr
= SWbemLocator_create( (void **)&locator
);
400 if (hr
!= S_OK
) goto done
;
402 hr
= ISWbemLocator_ConnectServer( locator
, server
, namespace, NULL
, NULL
, NULL
, NULL
, 0, NULL
, &services
);
403 if (hr
!= S_OK
) goto done
;
405 if (!relative
|| !*relative
) Moniker_create( (IUnknown
*)services
, ppmkOut
);
408 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
409 if (hr
!= S_OK
) goto done
;
410 hr
= Moniker_create( (IUnknown
*)obj
, ppmkOut
);
414 if (obj
) ISWbemObject_Release( obj
);
415 if (services
) ISWbemServices_Release( services
);
416 if (locator
) ISWbemLocator_Release( locator
);
417 SysFreeString( server
);
418 SysFreeString( namespace );
419 SysFreeString( relative
);
420 if (hr
== S_OK
) *pchEaten
= strlenW( pszDisplayName
);
424 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
425 WinMGMTS_QueryInterface
,
428 WinMGMTS_ParseDisplayName
431 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
433 static HRESULT
WinMGMTS_create(void **ppv
)
441 IClassFactory IClassFactory_iface
;
442 HRESULT (*fnCreateInstance
)( LPVOID
* );
445 static inline struct factory
*impl_from_IClassFactory( IClassFactory
*iface
)
447 return CONTAINING_RECORD( iface
, struct factory
, IClassFactory_iface
);
450 static HRESULT WINAPI
factory_QueryInterface( IClassFactory
*iface
, REFIID riid
, LPVOID
*obj
)
452 if (IsEqualGUID( riid
, &IID_IUnknown
) || IsEqualGUID( riid
, &IID_IClassFactory
))
454 IClassFactory_AddRef( iface
);
458 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
459 return E_NOINTERFACE
;
462 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
467 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
472 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
475 struct factory
*factory
= impl_from_IClassFactory( iface
);
479 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
482 if (outer
) return CLASS_E_NOAGGREGATION
;
484 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
488 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
489 IUnknown_Release( unk
);
493 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
495 FIXME( "%p, %d\n", iface
, lock
);
499 static const struct IClassFactoryVtbl factory_vtbl
=
501 factory_QueryInterface
,
504 factory_CreateInstance
,
508 static struct factory swbem_locator_cf
= { { &factory_vtbl
}, SWbemLocator_create
};
509 static struct factory winmgmts_cf
= { { &factory_vtbl
}, WinMGMTS_create
};
511 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
516 case DLL_WINE_PREATTACH
:
517 return FALSE
; /* prefer native version */
518 case DLL_PROCESS_ATTACH
:
520 DisableThreadLibraryCalls( hinst
);
526 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID iid
, LPVOID
*obj
)
528 IClassFactory
*cf
= NULL
;
530 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), obj
);
532 if (IsEqualGUID( rclsid
, &CLSID_SWbemLocator
))
533 cf
= &swbem_locator_cf
.IClassFactory_iface
;
534 else if (IsEqualGUID( rclsid
, &CLSID_WinMGMTS
))
535 cf
= &winmgmts_cf
.IClassFactory_iface
;
537 return CLASS_E_CLASSNOTAVAILABLE
;
539 return IClassFactory_QueryInterface( cf
, iid
, obj
);
542 /***********************************************************************
543 * DllCanUnloadNow (WBEMDISP.@)
545 HRESULT WINAPI
DllCanUnloadNow(void)
550 /***********************************************************************
551 * DllRegisterServer (WBEMDISP.@)
553 HRESULT WINAPI
DllRegisterServer(void)
555 return __wine_register_resources( instance
);
558 /***********************************************************************
559 * DllUnregisterServer (WBEMDISP.@)
561 HRESULT WINAPI
DllUnregisterServer(void)
563 return __wine_unregister_resources( instance
);