msvcp110: Add tr2_sys__Remove_dir_wchar implementation and test.
[wine/multimedia.git] / dlls / wbemdisp / main.c
blob97cd1e7d2f995f1d7b448ce55dff1a14763e4dd4
1 /*
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 "config.h"
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wmiutils.h"
28 #include "wbemdisp.h"
29 #include "rpcproxy.h"
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;
40 struct moniker
42 IMoniker IMoniker_iface;
43 LONG refs;
44 IUnknown *obj;
47 static inline struct moniker *impl_from_IMoniker(
48 IMoniker *iface )
50 return CONTAINING_RECORD( iface, struct moniker, IMoniker_iface );
53 static ULONG WINAPI moniker_AddRef(
54 IMoniker *iface )
56 struct moniker *moniker = impl_from_IMoniker( iface );
57 return InterlockedIncrement( &moniker->refs );
60 static ULONG WINAPI moniker_Release(
61 IMoniker *iface )
63 struct moniker *moniker = impl_from_IMoniker( iface );
64 LONG refs = InterlockedDecrement( &moniker->refs );
65 if (!refs)
67 TRACE( "destroying %p\n", moniker );
68 IUnknown_Release( moniker->obj );
69 heap_free( moniker );
71 return refs;
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 ))
84 *ppvObject = iface;
86 else
88 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
89 return E_NOINTERFACE;
91 IMoniker_AddRef( iface );
92 return S_OK;
95 static HRESULT WINAPI moniker_GetClassID(
96 IMoniker *iface, CLSID *pClassID )
98 FIXME( "\n" );
99 return E_NOTIMPL;
102 static HRESULT WINAPI moniker_IsDirty(
103 IMoniker *iface )
105 FIXME( "\n" );
106 return E_NOTIMPL;
109 static HRESULT WINAPI moniker_Load(
110 IMoniker *iface, IStream *pStm )
112 FIXME( "\n" );
113 return E_NOTIMPL;
116 static HRESULT WINAPI moniker_Save(
117 IMoniker *iface, IStream *pStm, BOOL fClearDirty )
119 FIXME( "\n" );
120 return E_NOTIMPL;
123 static HRESULT WINAPI moniker_GetSizeMax(
124 IMoniker *iface, ULARGE_INTEGER *pcbSize )
126 FIXME( "\n" );
127 return E_NOTIMPL;
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 )
142 FIXME( "\n" );
143 return E_NOTIMPL;
146 static HRESULT WINAPI moniker_Reduce(
147 IMoniker *iface, IBindCtx *pbc, DWORD dwReduceHowFar, IMoniker **ppmkToLeft, IMoniker **ppmkReduced )
149 FIXME( "\n" );
150 return E_NOTIMPL;
153 static HRESULT WINAPI moniker_ComposeWith(
154 IMoniker *iface, IMoniker *pmkRight, BOOL fOnlyIfNotGeneric, IMoniker **ppmkComposite )
156 FIXME( "\n" );
157 return E_NOTIMPL;
160 static HRESULT WINAPI moniker_Enum(
161 IMoniker *iface, BOOL fForward, IEnumMoniker **ppenumMoniker )
163 FIXME( "\n" );
164 return E_NOTIMPL;
167 static HRESULT WINAPI moniker_IsEqual(
168 IMoniker *iface, IMoniker *pmkOtherMoniker )
170 FIXME( "\n" );
171 return E_NOTIMPL;
174 static HRESULT WINAPI moniker_Hash(
175 IMoniker *iface, DWORD *pdwHash )
177 FIXME( "\n" );
178 return E_NOTIMPL;
181 static HRESULT WINAPI moniker_IsRunning(
182 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, IMoniker *pmkNewlyRunning )
184 FIXME( "\n" );
185 return E_NOTIMPL;
188 static HRESULT WINAPI moniker_GetTimeOfLastChange(
189 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, FILETIME *pFileTime )
191 FIXME( "\n" );
192 return E_NOTIMPL;
195 static HRESULT WINAPI moniker_Inverse(
196 IMoniker *iface, IMoniker **ppmk )
198 FIXME( "\n" );
199 return E_NOTIMPL;
202 static HRESULT WINAPI moniker_CommonPrefixWith(
203 IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkPrefix )
205 FIXME( "\n" );
206 return E_NOTIMPL;
209 static HRESULT WINAPI moniker_RelativePathTo(
210 IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkRelPath )
212 FIXME( "\n" );
213 return E_NOTIMPL;
216 static HRESULT WINAPI moniker_GetDisplayName(
217 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, LPOLESTR *ppszDisplayName )
219 FIXME( "\n" );
220 return E_NOTIMPL;
223 static HRESULT WINAPI moniker_ParseDisplayName(
224 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, LPOLESTR pszDisplayName, ULONG *pchEaten,
225 IMoniker **ppmkOut )
227 FIXME( "\n" );
228 return E_NOTIMPL;
231 static HRESULT WINAPI moniker_IsSystemMoniker(
232 IMoniker *iface, DWORD *pdwMksys )
234 FIXME( "\n" );
235 return E_NOTIMPL;
238 static const IMonikerVtbl moniker_vtbl =
240 moniker_QueryInterface,
241 moniker_AddRef,
242 moniker_Release,
243 moniker_GetClassID,
244 moniker_IsDirty,
245 moniker_Load,
246 moniker_Save,
247 moniker_GetSizeMax,
248 moniker_BindToObject,
249 moniker_BindToStorage,
250 moniker_Reduce,
251 moniker_ComposeWith,
252 moniker_Enum,
253 moniker_IsEqual,
254 moniker_Hash,
255 moniker_IsRunning,
256 moniker_GetTimeOfLastChange,
257 moniker_Inverse,
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;
273 moniker->refs = 1;
274 moniker->obj = unk;
275 IUnknown_AddRef( moniker->obj );
277 *obj = &moniker->IMoniker_iface;
278 TRACE( "returning iface %p\n", *obj );
279 return S_OK;
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);
286 *ppv = iface;
287 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
288 TRACE("(IID_IParseDisplayName %p)\n", ppv);
289 *ppv = iface;
290 }else {
291 WARN("Unsupported riid %s\n", debugstr_guid(riid));
292 *ppv = NULL;
293 return E_NOINTERFACE;
296 IUnknown_AddRef((IUnknown*)*ppv);
297 return S_OK;
300 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
302 return 2;
305 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
307 return 1;
310 static HRESULT parse_path( const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative )
312 IWbemPath *path;
313 ULONG len;
314 HRESULT hr;
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;
324 len = 0;
325 hr = IWbemPath_GetServer( path, &len, NULL );
326 if (hr == S_OK)
328 if (!(*server = SysAllocStringLen( NULL, len )))
330 hr = E_OUTOFMEMORY;
331 goto done;
333 hr = IWbemPath_GetServer( path, &len, *server );
334 if (hr != S_OK) goto done;
337 len = 0;
338 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, NULL );
339 if (hr == S_OK)
341 if (!(*namespace = SysAllocStringLen( NULL, len )))
343 hr = E_OUTOFMEMORY;
344 goto done;
346 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, *namespace );
347 if (hr != S_OK) goto done;
349 len = 0;
350 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, NULL );
351 if (hr == S_OK)
353 if (!(*relative = SysAllocStringLen( NULL, len )))
355 hr = E_OUTOFMEMORY;
356 goto done;
358 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, *relative );
361 done:
362 IWbemPath_Release( path );
363 if (hr != S_OK)
365 SysFreeString( *server );
366 SysFreeString( *namespace );
367 SysFreeString( *relative );
369 return hr;
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;
381 WCHAR *p;
382 HRESULT hr;
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;
389 if (*p == '{')
391 FIXME( "ignoring security settings\n" );
392 while (*p && *p != '}') p++;
393 if (*p == '}') p++;
394 if (*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 );
406 else
408 hr = ISWbemServices_Get( services, relative, 0, NULL, &obj );
409 if (hr != S_OK) goto done;
410 hr = Moniker_create( (IUnknown *)obj, ppmkOut );
413 done:
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 );
421 return hr;
424 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
425 WinMGMTS_QueryInterface,
426 WinMGMTS_AddRef,
427 WinMGMTS_Release,
428 WinMGMTS_ParseDisplayName
431 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
433 static HRESULT WinMGMTS_create(void **ppv)
435 *ppv = &winmgmts;
436 return S_OK;
439 struct factory
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 );
455 *obj = iface;
456 return S_OK;
458 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
459 return E_NOINTERFACE;
462 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
464 return 2;
467 static ULONG WINAPI factory_Release( IClassFactory *iface )
469 return 1;
472 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
473 LPVOID *obj )
475 struct factory *factory = impl_from_IClassFactory( iface );
476 IUnknown *unk;
477 HRESULT hr;
479 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
481 *obj = NULL;
482 if (outer) return CLASS_E_NOAGGREGATION;
484 hr = factory->fnCreateInstance( (LPVOID *)&unk );
485 if (FAILED( hr ))
486 return hr;
488 hr = IUnknown_QueryInterface( unk, riid, obj );
489 IUnknown_Release( unk );
490 return hr;
493 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
495 FIXME( "%p, %d\n", iface, lock );
496 return S_OK;
499 static const struct IClassFactoryVtbl factory_vtbl =
501 factory_QueryInterface,
502 factory_AddRef,
503 factory_Release,
504 factory_CreateInstance,
505 factory_LockServer
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 )
514 switch (reason)
516 case DLL_WINE_PREATTACH:
517 return FALSE; /* prefer native version */
518 case DLL_PROCESS_ATTACH:
519 instance = hinst;
520 DisableThreadLibraryCalls( hinst );
521 break;
523 return TRUE;
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;
536 else
537 return CLASS_E_CLASSNOTAVAILABLE;
539 return IClassFactory_QueryInterface( cf, iid, obj );
542 /***********************************************************************
543 * DllCanUnloadNow (WBEMDISP.@)
545 HRESULT WINAPI DllCanUnloadNow(void)
547 return S_FALSE;
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 );