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
30 #include "wine/debug.h"
31 #include "wine/heap.h"
32 #include "wbemdisp_private.h"
33 #include "wbemdisp_classes.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp
);
37 static HINSTANCE instance
;
41 IMoniker IMoniker_iface
;
46 static inline struct moniker
*impl_from_IMoniker(
49 return CONTAINING_RECORD( iface
, struct moniker
, IMoniker_iface
);
52 static ULONG WINAPI
moniker_AddRef(
55 struct moniker
*moniker
= impl_from_IMoniker( iface
);
56 return InterlockedIncrement( &moniker
->refs
);
59 static ULONG WINAPI
moniker_Release(
62 struct moniker
*moniker
= impl_from_IMoniker( iface
);
63 LONG refs
= InterlockedDecrement( &moniker
->refs
);
66 TRACE( "destroying %p\n", moniker
);
67 IUnknown_Release( moniker
->obj
);
73 static HRESULT WINAPI
moniker_QueryInterface(
74 IMoniker
*iface
, REFIID riid
, void **ppvObject
)
76 struct moniker
*moniker
= impl_from_IMoniker( iface
);
78 TRACE( "%p, %s, %p\n", moniker
, debugstr_guid( riid
), ppvObject
);
80 if (IsEqualGUID( riid
, &IID_IMoniker
) ||
81 IsEqualGUID( riid
, &IID_IUnknown
))
87 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
90 IMoniker_AddRef( iface
);
94 static HRESULT WINAPI
moniker_GetClassID(
95 IMoniker
*iface
, CLSID
*pClassID
)
101 static HRESULT WINAPI
moniker_IsDirty(
108 static HRESULT WINAPI
moniker_Load(
109 IMoniker
*iface
, IStream
*pStm
)
115 static HRESULT WINAPI
moniker_Save(
116 IMoniker
*iface
, IStream
*pStm
, BOOL fClearDirty
)
122 static HRESULT WINAPI
moniker_GetSizeMax(
123 IMoniker
*iface
, ULARGE_INTEGER
*pcbSize
)
129 static HRESULT WINAPI
moniker_BindToObject(
130 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riidResult
, void **ppvResult
)
132 struct moniker
*moniker
= impl_from_IMoniker( iface
);
134 TRACE( "%p, %p, %p, %s, %p\n", iface
, pbc
, pmkToLeft
, debugstr_guid(riidResult
), ppvResult
);
135 return IUnknown_QueryInterface( moniker
->obj
, riidResult
, ppvResult
);
138 static HRESULT WINAPI
moniker_BindToStorage(
139 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, REFIID riid
, void **ppvObj
)
145 static HRESULT WINAPI
moniker_Reduce(
146 IMoniker
*iface
, IBindCtx
*pbc
, DWORD dwReduceHowFar
, IMoniker
**ppmkToLeft
, IMoniker
**ppmkReduced
)
152 static HRESULT WINAPI
moniker_ComposeWith(
153 IMoniker
*iface
, IMoniker
*pmkRight
, BOOL fOnlyIfNotGeneric
, IMoniker
**ppmkComposite
)
159 static HRESULT WINAPI
moniker_Enum(
160 IMoniker
*iface
, BOOL fForward
, IEnumMoniker
**ppenumMoniker
)
166 static HRESULT WINAPI
moniker_IsEqual(
167 IMoniker
*iface
, IMoniker
*pmkOtherMoniker
)
173 static HRESULT WINAPI
moniker_Hash(
174 IMoniker
*iface
, DWORD
*pdwHash
)
180 static HRESULT WINAPI
moniker_IsRunning(
181 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, IMoniker
*pmkNewlyRunning
)
187 static HRESULT WINAPI
moniker_GetTimeOfLastChange(
188 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, FILETIME
*pFileTime
)
194 static HRESULT WINAPI
moniker_Inverse(
195 IMoniker
*iface
, IMoniker
**ppmk
)
201 static HRESULT WINAPI
moniker_CommonPrefixWith(
202 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkPrefix
)
208 static HRESULT WINAPI
moniker_RelativePathTo(
209 IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkRelPath
)
215 static HRESULT WINAPI
moniker_GetDisplayName(
216 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR
*ppszDisplayName
)
222 static HRESULT WINAPI
moniker_ParseDisplayName(
223 IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
*pchEaten
,
230 static HRESULT WINAPI
moniker_IsSystemMoniker(
231 IMoniker
*iface
, DWORD
*pdwMksys
)
237 static const IMonikerVtbl moniker_vtbl
=
239 moniker_QueryInterface
,
247 moniker_BindToObject
,
248 moniker_BindToStorage
,
255 moniker_GetTimeOfLastChange
,
257 moniker_CommonPrefixWith
,
258 moniker_RelativePathTo
,
259 moniker_GetDisplayName
,
260 moniker_ParseDisplayName
,
261 moniker_IsSystemMoniker
264 static HRESULT
Moniker_create( IUnknown
*unk
, IMoniker
**obj
)
266 struct moniker
*moniker
;
268 TRACE( "%p, %p\n", unk
, obj
);
270 if (!(moniker
= heap_alloc( sizeof(*moniker
) ))) return E_OUTOFMEMORY
;
271 moniker
->IMoniker_iface
.lpVtbl
= &moniker_vtbl
;
274 IUnknown_AddRef( moniker
->obj
);
276 *obj
= &moniker
->IMoniker_iface
;
277 TRACE( "returning iface %p\n", *obj
);
281 static HRESULT WINAPI
WinMGMTS_QueryInterface(IParseDisplayName
*iface
, REFIID riid
, void **ppv
)
283 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
284 TRACE("(IID_IUnknown %p)\n", ppv
);
286 }else if(IsEqualGUID(riid
, &IID_IParseDisplayName
)) {
287 TRACE("(IID_IParseDisplayName %p)\n", ppv
);
290 WARN("Unsupported riid %s\n", debugstr_guid(riid
));
292 return E_NOINTERFACE
;
295 IUnknown_AddRef((IUnknown
*)*ppv
);
299 static ULONG WINAPI
WinMGMTS_AddRef(IParseDisplayName
*iface
)
304 static ULONG WINAPI
WinMGMTS_Release(IParseDisplayName
*iface
)
309 static HRESULT
parse_path( const WCHAR
*str
, BSTR
*server
, BSTR
*namespace, BSTR
*relative
)
315 *server
= *namespace = *relative
= NULL
;
317 hr
= CoCreateInstance( &CLSID_WbemDefPath
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWbemPath
, (void **)&path
);
318 if (hr
!= S_OK
) return hr
;
320 hr
= IWbemPath_SetText( path
, WBEMPATH_CREATE_ACCEPT_ALL
, str
);
321 if (hr
!= S_OK
) goto done
;
324 hr
= IWbemPath_GetServer( path
, &len
, NULL
);
327 if (!(*server
= SysAllocStringLen( NULL
, len
)))
332 hr
= IWbemPath_GetServer( path
, &len
, *server
);
333 if (hr
!= S_OK
) goto done
;
337 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, NULL
);
340 if (!(*namespace = SysAllocStringLen( NULL
, len
)))
345 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, *namespace );
346 if (hr
!= S_OK
) goto done
;
349 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, NULL
);
352 if (!(*relative
= SysAllocStringLen( NULL
, len
)))
357 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, *relative
);
361 IWbemPath_Release( path
);
364 SysFreeString( *server
);
365 SysFreeString( *namespace );
366 SysFreeString( *relative
);
371 static HRESULT WINAPI
WinMGMTS_ParseDisplayName(IParseDisplayName
*iface
, IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
372 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
374 static const WCHAR prefixW
[] = {'w','i','n','m','g','m','t','s',':',0};
375 const DWORD prefix_len
= ARRAY_SIZE(prefixW
) - 1;
376 ISWbemLocator
*locator
= NULL
;
377 ISWbemServices
*services
= NULL
;
378 ISWbemObject
*obj
= NULL
;
379 BSTR server
, namespace, relative
;
383 TRACE( "%p, %p, %s, %p, %p\n", iface
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
385 if (_wcsnicmp( pszDisplayName
, prefixW
, prefix_len
)) return MK_E_SYNTAX
;
387 p
= pszDisplayName
+ prefix_len
;
390 FIXME( "ignoring security settings\n" );
391 while (*p
&& *p
!= '}') p
++;
395 hr
= parse_path( p
, &server
, &namespace, &relative
);
396 if (hr
!= S_OK
) return hr
;
398 hr
= SWbemLocator_create( (void **)&locator
);
399 if (hr
!= S_OK
) goto done
;
401 hr
= ISWbemLocator_ConnectServer( locator
, server
, namespace, NULL
, NULL
, NULL
, NULL
, 0, NULL
, &services
);
402 if (hr
!= S_OK
) goto done
;
404 if (!relative
|| !*relative
) Moniker_create( (IUnknown
*)services
, ppmkOut
);
407 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
408 if (hr
!= S_OK
) goto done
;
409 hr
= Moniker_create( (IUnknown
*)obj
, ppmkOut
);
413 if (obj
) ISWbemObject_Release( obj
);
414 if (services
) ISWbemServices_Release( services
);
415 if (locator
) ISWbemLocator_Release( locator
);
416 SysFreeString( server
);
417 SysFreeString( namespace );
418 SysFreeString( relative
);
419 if (hr
== S_OK
) *pchEaten
= lstrlenW( pszDisplayName
);
423 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
424 WinMGMTS_QueryInterface
,
427 WinMGMTS_ParseDisplayName
430 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
432 static HRESULT
WinMGMTS_create(void **ppv
)
440 IClassFactory IClassFactory_iface
;
441 HRESULT (*fnCreateInstance
)( LPVOID
* );
444 static inline struct factory
*impl_from_IClassFactory( IClassFactory
*iface
)
446 return CONTAINING_RECORD( iface
, struct factory
, IClassFactory_iface
);
449 static HRESULT WINAPI
factory_QueryInterface( IClassFactory
*iface
, REFIID riid
, LPVOID
*obj
)
451 if (IsEqualGUID( riid
, &IID_IUnknown
) || IsEqualGUID( riid
, &IID_IClassFactory
))
453 IClassFactory_AddRef( iface
);
457 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
458 return E_NOINTERFACE
;
461 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
466 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
471 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
474 struct factory
*factory
= impl_from_IClassFactory( iface
);
478 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
481 if (outer
) return CLASS_E_NOAGGREGATION
;
483 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
487 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
488 IUnknown_Release( unk
);
492 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
494 FIXME( "%p, %d\n", iface
, lock
);
498 static const struct IClassFactoryVtbl factory_vtbl
=
500 factory_QueryInterface
,
503 factory_CreateInstance
,
507 static struct factory swbem_locator_cf
= { { &factory_vtbl
}, SWbemLocator_create
};
508 static struct factory winmgmts_cf
= { { &factory_vtbl
}, WinMGMTS_create
};
510 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
515 case DLL_WINE_PREATTACH
:
516 return FALSE
; /* prefer native version */
517 case DLL_PROCESS_ATTACH
:
519 DisableThreadLibraryCalls( hinst
);
525 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID iid
, LPVOID
*obj
)
527 IClassFactory
*cf
= NULL
;
529 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), obj
);
531 if (IsEqualGUID( rclsid
, &CLSID_SWbemLocator
))
532 cf
= &swbem_locator_cf
.IClassFactory_iface
;
533 else if (IsEqualGUID( rclsid
, &CLSID_WinMGMTS
))
534 cf
= &winmgmts_cf
.IClassFactory_iface
;
536 return CLASS_E_CLASSNOTAVAILABLE
;
538 return IClassFactory_QueryInterface( cf
, iid
, obj
);
541 /***********************************************************************
542 * DllCanUnloadNow (WBEMDISP.@)
544 HRESULT WINAPI
DllCanUnloadNow(void)
549 /***********************************************************************
550 * DllRegisterServer (WBEMDISP.@)
552 HRESULT WINAPI
DllRegisterServer(void)
554 return __wine_register_resources( instance
);
557 /***********************************************************************
558 * DllUnregisterServer (WBEMDISP.@)
560 HRESULT WINAPI
DllUnregisterServer(void)
562 return __wine_unregister_resources( instance
);