ntoskrnl.exe/tests: Add some IOCTL_HID_WRITE_REPORT tests.
[wine.git] / dlls / wbemdisp / locator.c
blob3e2566d52209ae7f744a7d40881e2b370a5e6c8f
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 #define COBJMACROS
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "initguid.h"
26 #include "objbase.h"
27 #include "wmiutils.h"
28 #include "wbemcli.h"
29 #include "wbemdisp.h"
31 #include "wine/debug.h"
32 #include "wine/heap.h"
33 #include "wbemdisp_private.h"
34 #include "wbemdisp_classes.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp);
38 struct namedvalueset
40 ISWbemNamedValueSet ISWbemNamedValueSet_iface;
41 LONG refs;
43 IWbemContext *context;
46 static struct namedvalueset *unsafe_valueset_impl_from_IDispatch(IDispatch *iface);
48 static IWbemContext * unsafe_get_context_from_namedvalueset( IDispatch *disp )
50 struct namedvalueset *valueset = unsafe_valueset_impl_from_IDispatch( disp );
51 return valueset ? valueset->context : NULL;
54 static WCHAR *heap_strdupW( const WCHAR *src )
56 WCHAR *dst;
57 if (!src) return NULL;
58 if ((dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) ))) lstrcpyW( dst, src );
59 return dst;
62 struct services;
64 static HRESULT EnumVARIANT_create( struct services *, IEnumWbemClassObject *, IEnumVARIANT ** );
65 static HRESULT ISWbemSecurity_create( ISWbemSecurity ** );
66 static HRESULT SWbemObject_create( struct services *, IWbemClassObject *, ISWbemObject ** );
68 enum type_id
70 ISWbemLocator_tid,
71 ISWbemObject_tid,
72 ISWbemObjectSet_tid,
73 ISWbemProperty_tid,
74 ISWbemPropertySet_tid,
75 ISWbemServices_tid,
76 ISWbemSecurity_tid,
77 ISWbemNamedValueSet_tid,
78 ISWbemNamedValue_tid,
79 ISWbemMethodSet_tid,
80 ISWbemMethod_tid,
81 last_tid
84 static ITypeLib *wbemdisp_typelib;
85 static ITypeInfo *wbemdisp_typeinfo[last_tid];
87 static REFIID wbemdisp_tid_id[] =
89 &IID_ISWbemLocator,
90 &IID_ISWbemObject,
91 &IID_ISWbemObjectSet,
92 &IID_ISWbemProperty,
93 &IID_ISWbemPropertySet,
94 &IID_ISWbemServices,
95 &IID_ISWbemSecurity,
96 &IID_ISWbemNamedValueSet,
97 &IID_ISWbemNamedValue,
98 &IID_ISWbemMethodSet,
99 &IID_ISWbemMethod,
102 static HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
104 HRESULT hr;
106 if (!wbemdisp_typelib)
108 ITypeLib *typelib;
110 hr = LoadRegTypeLib( &LIBID_WbemScripting, 1, 2, LOCALE_SYSTEM_DEFAULT, &typelib );
111 if (FAILED( hr ))
113 ERR( "LoadRegTypeLib failed: %08x\n", hr );
114 return hr;
116 if (InterlockedCompareExchangePointer( (void **)&wbemdisp_typelib, typelib, NULL ))
117 ITypeLib_Release( typelib );
119 if (!wbemdisp_typeinfo[tid])
121 ITypeInfo *typeinfo;
123 hr = ITypeLib_GetTypeInfoOfGuid( wbemdisp_typelib, wbemdisp_tid_id[tid], &typeinfo );
124 if (FAILED( hr ))
126 ERR( "GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(wbemdisp_tid_id[tid]), hr );
127 return hr;
129 if (InterlockedCompareExchangePointer( (void **)(wbemdisp_typeinfo + tid), typeinfo, NULL ))
130 ITypeInfo_Release( typeinfo );
132 *ret = wbemdisp_typeinfo[tid];
133 ITypeInfo_AddRef( *ret );
134 return S_OK;
137 struct property
139 ISWbemProperty ISWbemProperty_iface;
140 LONG refs;
141 IWbemClassObject *object;
142 BSTR name;
145 static inline struct property *impl_from_ISWbemProperty( ISWbemProperty *iface )
147 return CONTAINING_RECORD( iface, struct property, ISWbemProperty_iface );
150 static ULONG WINAPI property_AddRef( ISWbemProperty *iface )
152 struct property *property = impl_from_ISWbemProperty( iface );
153 return InterlockedIncrement( &property->refs );
156 static ULONG WINAPI property_Release( ISWbemProperty *iface )
158 struct property *property = impl_from_ISWbemProperty( iface );
159 LONG refs = InterlockedDecrement( &property->refs );
160 if (!refs)
162 TRACE( "destroying %p\n", property );
163 IWbemClassObject_Release( property->object );
164 SysFreeString( property->name );
165 heap_free( property );
167 return refs;
170 static HRESULT WINAPI property_QueryInterface( ISWbemProperty *iface, REFIID riid, void **obj )
172 struct property *property = impl_from_ISWbemProperty( iface );
174 TRACE( "%p %s %p\n", property, debugstr_guid(riid), obj );
176 if (IsEqualGUID( riid, &IID_ISWbemProperty ) ||
177 IsEqualGUID( riid, &IID_IDispatch ) ||
178 IsEqualGUID( riid, &IID_IUnknown ))
180 *obj = iface;
182 else
184 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
185 return E_NOINTERFACE;
187 ISWbemProperty_AddRef( iface );
188 return S_OK;
191 static HRESULT WINAPI property_GetTypeInfoCount( ISWbemProperty *iface, UINT *count )
193 struct property *property = impl_from_ISWbemProperty( iface );
194 TRACE( "%p, %p\n", property, count );
195 *count = 1;
196 return S_OK;
199 static HRESULT WINAPI property_GetTypeInfo( ISWbemProperty *iface, UINT index,
200 LCID lcid, ITypeInfo **info )
202 struct property *property = impl_from_ISWbemProperty( iface );
203 TRACE( "%p, %u, %u, %p\n", property, index, lcid, info );
205 return get_typeinfo( ISWbemProperty_tid, info );
208 static HRESULT WINAPI property_GetIDsOfNames( ISWbemProperty *iface, REFIID riid, LPOLESTR *names,
209 UINT count, LCID lcid, DISPID *dispid )
211 struct property *property = impl_from_ISWbemProperty( iface );
212 ITypeInfo *typeinfo;
213 HRESULT hr;
215 TRACE( "%p, %s, %p, %u, %u, %p\n", property, debugstr_guid(riid), names, count, lcid, dispid );
217 if (!names || !count || !dispid) return E_INVALIDARG;
219 hr = get_typeinfo( ISWbemProperty_tid, &typeinfo );
220 if (SUCCEEDED(hr))
222 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
223 ITypeInfo_Release( typeinfo );
225 return hr;
228 static HRESULT WINAPI property_Invoke( ISWbemProperty *iface, DISPID member, REFIID riid,
229 LCID lcid, WORD flags, DISPPARAMS *params,
230 VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
232 struct property *property = impl_from_ISWbemProperty( iface );
233 ITypeInfo *typeinfo;
234 HRESULT hr;
236 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", property, member, debugstr_guid(riid),
237 lcid, flags, params, result, excep_info, arg_err );
239 hr = get_typeinfo( ISWbemProperty_tid, &typeinfo );
240 if (SUCCEEDED(hr))
242 hr = ITypeInfo_Invoke( typeinfo, &property->ISWbemProperty_iface, member, flags,
243 params, result, excep_info, arg_err );
244 ITypeInfo_Release( typeinfo );
246 return hr;
249 static HRESULT WINAPI property_get_Value( ISWbemProperty *iface, VARIANT *value )
251 struct property *property = impl_from_ISWbemProperty( iface );
253 TRACE( "%p %p\n", property, value );
255 return IWbemClassObject_Get( property->object, property->name, 0, value, NULL, NULL );
258 static HRESULT WINAPI property_put_Value( ISWbemProperty *iface, VARIANT *varValue )
260 FIXME( "\n" );
261 return E_NOTIMPL;
264 static HRESULT WINAPI property_get_Name( ISWbemProperty *iface, BSTR *strName )
266 FIXME( "\n" );
267 return E_NOTIMPL;
270 static HRESULT WINAPI property_get_IsLocal( ISWbemProperty *iface, VARIANT_BOOL *bIsLocal )
272 FIXME( "\n" );
273 return E_NOTIMPL;
276 static HRESULT WINAPI property_get_Origin( ISWbemProperty *iface, BSTR *strOrigin )
278 FIXME( "\n" );
279 return E_NOTIMPL;
282 static HRESULT WINAPI property_get_CIMType( ISWbemProperty *iface, WbemCimtypeEnum *iCimType )
284 FIXME( "\n" );
285 return E_NOTIMPL;
288 static HRESULT WINAPI property_get_Qualifiers_( ISWbemProperty *iface, ISWbemQualifierSet **objWbemQualifierSet )
290 FIXME( "\n" );
291 return E_NOTIMPL;
294 static HRESULT WINAPI property_get_IsArray( ISWbemProperty *iface, VARIANT_BOOL *bIsArray )
296 FIXME( "\n" );
297 return E_NOTIMPL;
300 static const ISWbemPropertyVtbl property_vtbl =
302 property_QueryInterface,
303 property_AddRef,
304 property_Release,
305 property_GetTypeInfoCount,
306 property_GetTypeInfo,
307 property_GetIDsOfNames,
308 property_Invoke,
309 property_get_Value,
310 property_put_Value,
311 property_get_Name,
312 property_get_IsLocal,
313 property_get_Origin,
314 property_get_CIMType,
315 property_get_Qualifiers_,
316 property_get_IsArray
319 static HRESULT SWbemProperty_create( IWbemClassObject *wbem_object, BSTR name, ISWbemProperty **obj )
321 struct property *property;
323 TRACE( "%p, %p\n", obj, wbem_object );
325 if (!(property = heap_alloc( sizeof(*property) ))) return E_OUTOFMEMORY;
326 property->ISWbemProperty_iface.lpVtbl = &property_vtbl;
327 property->refs = 1;
328 property->object = wbem_object;
329 IWbemClassObject_AddRef( property->object );
330 property->name = SysAllocStringLen( name, SysStringLen( name ) );
331 *obj = &property->ISWbemProperty_iface;
332 TRACE( "returning iface %p\n", *obj );
333 return S_OK;
336 struct propertyset
338 ISWbemPropertySet ISWbemPropertySet_iface;
339 LONG refs;
340 IWbemClassObject *object;
343 static inline struct propertyset *impl_from_ISWbemPropertySet(
344 ISWbemPropertySet *iface )
346 return CONTAINING_RECORD( iface, struct propertyset, ISWbemPropertySet_iface );
349 static ULONG WINAPI propertyset_AddRef( ISWbemPropertySet *iface )
351 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
352 return InterlockedIncrement( &propertyset->refs );
355 static ULONG WINAPI propertyset_Release( ISWbemPropertySet *iface )
357 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
358 LONG refs = InterlockedDecrement( &propertyset->refs );
359 if (!refs)
361 TRACE( "destroying %p\n", propertyset );
362 IWbemClassObject_Release( propertyset->object );
363 heap_free( propertyset );
365 return refs;
368 static HRESULT WINAPI propertyset_QueryInterface( ISWbemPropertySet *iface,
369 REFIID riid, void **obj )
371 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
373 TRACE( "%p %s %p\n", propertyset, debugstr_guid(riid), obj );
375 if (IsEqualGUID( riid, &IID_ISWbemPropertySet ) ||
376 IsEqualGUID( riid, &IID_IDispatch ) ||
377 IsEqualGUID( riid, &IID_IUnknown ))
379 *obj = iface;
381 else
383 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
384 return E_NOINTERFACE;
386 ISWbemPropertySet_AddRef( iface );
387 return S_OK;
390 static HRESULT WINAPI propertyset_GetTypeInfoCount( ISWbemPropertySet *iface, UINT *count )
392 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
393 TRACE( "%p, %p\n", propertyset, count );
394 *count = 1;
395 return S_OK;
398 static HRESULT WINAPI propertyset_GetTypeInfo( ISWbemPropertySet *iface,
399 UINT index, LCID lcid, ITypeInfo **info )
401 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
402 TRACE( "%p, %u, %u, %p\n", propertyset, index, lcid, info );
404 return get_typeinfo( ISWbemPropertySet_tid, info );
407 static HRESULT WINAPI propertyset_GetIDsOfNames( ISWbemPropertySet *iface, REFIID riid, LPOLESTR *names,
408 UINT count, LCID lcid, DISPID *dispid )
410 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
411 ITypeInfo *typeinfo;
412 HRESULT hr;
414 TRACE( "%p, %s, %p, %u, %u, %p\n", propertyset, debugstr_guid(riid), names, count, lcid, dispid );
416 if (!names || !count || !dispid) return E_INVALIDARG;
418 hr = get_typeinfo( ISWbemPropertySet_tid, &typeinfo );
419 if (SUCCEEDED(hr))
421 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
422 ITypeInfo_Release( typeinfo );
424 return hr;
427 static HRESULT WINAPI propertyset_Invoke( ISWbemPropertySet *iface, DISPID member, REFIID riid,
428 LCID lcid, WORD flags, DISPPARAMS *params,
429 VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
431 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
432 ITypeInfo *typeinfo;
433 HRESULT hr;
435 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", propertyset, member, debugstr_guid(riid),
436 lcid, flags, params, result, excep_info, arg_err );
438 hr = get_typeinfo( ISWbemPropertySet_tid, &typeinfo );
439 if (SUCCEEDED(hr))
441 hr = ITypeInfo_Invoke( typeinfo, &propertyset->ISWbemPropertySet_iface, member, flags,
442 params, result, excep_info, arg_err );
443 ITypeInfo_Release( typeinfo );
445 return hr;
448 static HRESULT WINAPI propertyset_get__NewEnum( ISWbemPropertySet *iface, IUnknown **unk )
450 FIXME( "\n" );
451 return E_NOTIMPL;
454 static HRESULT WINAPI propertyset_Item( ISWbemPropertySet *iface, BSTR name,
455 LONG flags, ISWbemProperty **prop )
457 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
458 HRESULT hr;
459 VARIANT var;
461 TRACE( "%p, %s, %08x, %p\n", propertyset, debugstr_w(name), flags, prop );
463 hr = IWbemClassObject_Get( propertyset->object, name, 0, &var, NULL, NULL );
464 if (SUCCEEDED(hr))
466 hr = SWbemProperty_create( propertyset->object, name, prop );
467 VariantClear( &var );
469 return hr;
472 static HRESULT WINAPI propertyset_get_Count( ISWbemPropertySet *iface, LONG *count )
474 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
475 HRESULT hr;
476 VARIANT val;
478 TRACE( "%p, %p\n", propertyset, count );
480 hr = IWbemClassObject_Get( propertyset->object, L"__PROPERTY_COUNT", 0, &val, NULL, NULL );
481 if (SUCCEEDED(hr))
483 *count = V_I4( &val );
485 return hr;
488 static HRESULT WINAPI propertyset_Add( ISWbemPropertySet *iface, BSTR name, WbemCimtypeEnum type,
489 VARIANT_BOOL is_array, LONG flags, ISWbemProperty **prop )
491 FIXME( "\n" );
492 return E_NOTIMPL;
495 static HRESULT WINAPI propertyset_Remove( ISWbemPropertySet *iface, BSTR name, LONG flags )
497 FIXME( "\n" );
498 return E_NOTIMPL;
501 static const ISWbemPropertySetVtbl propertyset_vtbl =
503 propertyset_QueryInterface,
504 propertyset_AddRef,
505 propertyset_Release,
506 propertyset_GetTypeInfoCount,
507 propertyset_GetTypeInfo,
508 propertyset_GetIDsOfNames,
509 propertyset_Invoke,
510 propertyset_get__NewEnum,
511 propertyset_Item,
512 propertyset_get_Count,
513 propertyset_Add,
514 propertyset_Remove
517 static HRESULT SWbemPropertySet_create( IWbemClassObject *wbem_object, ISWbemPropertySet **obj )
519 struct propertyset *propertyset;
521 TRACE( "%p, %p\n", obj, wbem_object );
523 if (!(propertyset = heap_alloc( sizeof(*propertyset) ))) return E_OUTOFMEMORY;
524 propertyset->ISWbemPropertySet_iface.lpVtbl = &propertyset_vtbl;
525 propertyset->refs = 1;
526 propertyset->object = wbem_object;
527 IWbemClassObject_AddRef( propertyset->object );
528 *obj = &propertyset->ISWbemPropertySet_iface;
530 TRACE( "returning iface %p\n", *obj );
531 return S_OK;
534 struct services
536 ISWbemServices ISWbemServices_iface;
537 LONG refs;
538 IWbemServices *services;
541 struct member
543 BSTR name;
544 BOOL is_method;
545 DISPID dispid;
546 CIMTYPE type;
549 struct object
551 ISWbemObject ISWbemObject_iface;
552 LONG refs;
553 IWbemClassObject *object;
554 struct member *members;
555 UINT nb_members;
556 DISPID last_dispid;
557 DISPID last_dispid_method;
558 struct services *services;
561 struct methodset
563 ISWbemMethodSet ISWbemMethodSet_iface;
564 LONG refs;
565 struct object *object;
568 struct method
570 ISWbemMethod ISWbemMethod_iface;
571 LONG refs;
572 struct methodset *set;
573 WCHAR *name;
576 static struct method *impl_from_ISWbemMethod( ISWbemMethod *iface )
578 return CONTAINING_RECORD( iface, struct method, ISWbemMethod_iface );
581 static HRESULT WINAPI method_QueryInterface( ISWbemMethod *iface, REFIID riid, void **ppvObject )
583 struct method *method = impl_from_ISWbemMethod( iface );
585 TRACE( "%p %s %p\n", method, debugstr_guid(riid), ppvObject );
587 if (IsEqualGUID( riid, &IID_ISWbemMethod ) ||
588 IsEqualGUID( riid, &IID_IDispatch ) ||
589 IsEqualGUID( riid, &IID_IUnknown ))
591 *ppvObject = iface;
593 else
595 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
596 return E_NOINTERFACE;
598 ISWbemMethod_AddRef( iface );
599 return S_OK;
602 static ULONG WINAPI method_AddRef( ISWbemMethod *iface )
604 struct method *method = impl_from_ISWbemMethod( iface );
605 return InterlockedIncrement( &method->refs );
608 static ULONG WINAPI method_Release( ISWbemMethod *iface )
610 struct method *method = impl_from_ISWbemMethod( iface );
611 LONG refs = InterlockedDecrement( &method->refs );
612 if (!refs)
614 TRACE( "destroying %p\n", method );
615 ISWbemMethodSet_Release( &method->set->ISWbemMethodSet_iface );
616 heap_free( method->name );
617 heap_free( method );
619 return refs;
622 static HRESULT WINAPI method_GetTypeInfoCount(
623 ISWbemMethod *iface,
624 UINT *count )
626 struct method *method = impl_from_ISWbemMethod( iface );
628 TRACE( "%p, %p\n", method, count );
629 *count = 1;
630 return S_OK;
633 static HRESULT WINAPI method_GetTypeInfo(
634 ISWbemMethod *iface,
635 UINT index,
636 LCID lcid,
637 ITypeInfo **info )
639 struct method *method = impl_from_ISWbemMethod( iface );
641 TRACE( "%p, %u, %u, %p\n", method, index, lcid, info );
643 return get_typeinfo( ISWbemMethod_tid, info );
646 static HRESULT WINAPI method_GetIDsOfNames(
647 ISWbemMethod *iface,
648 REFIID riid,
649 LPOLESTR *names,
650 UINT count,
651 LCID lcid,
652 DISPID *dispid )
654 struct method *method = impl_from_ISWbemMethod( iface );
655 ITypeInfo *typeinfo;
656 HRESULT hr;
658 TRACE( "%p, %s, %p, %u, %u, %p\n", method, debugstr_guid(riid), names, count, lcid, dispid );
660 if (!names || !count || !dispid) return E_INVALIDARG;
662 hr = get_typeinfo( ISWbemMethod_tid, &typeinfo );
663 if (SUCCEEDED(hr))
665 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
666 ITypeInfo_Release( typeinfo );
668 return hr;
671 static HRESULT WINAPI method_Invoke(
672 ISWbemMethod *iface,
673 DISPID member,
674 REFIID riid,
675 LCID lcid,
676 WORD flags,
677 DISPPARAMS *params,
678 VARIANT *result,
679 EXCEPINFO *excep_info,
680 UINT *arg_err )
682 struct method *method = impl_from_ISWbemMethod( iface );
683 ITypeInfo *typeinfo;
684 HRESULT hr;
686 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", method, member, debugstr_guid(riid),
687 lcid, flags, params, result, excep_info, arg_err );
689 hr = get_typeinfo( ISWbemMethod_tid, &typeinfo );
690 if (SUCCEEDED(hr))
692 hr = ITypeInfo_Invoke( typeinfo, &method->ISWbemMethod_iface, member, flags,
693 params, result, excep_info, arg_err );
694 ITypeInfo_Release( typeinfo );
696 return hr;
699 static HRESULT WINAPI method_get_Name(
700 ISWbemMethod *iface,
701 BSTR *name )
703 FIXME("\n");
705 return E_NOTIMPL;
708 static HRESULT WINAPI method_get_Origin(
709 ISWbemMethod *iface,
710 BSTR *origin )
712 FIXME("\n");
714 return E_NOTIMPL;
717 static HRESULT WINAPI method_get_InParameters(
718 ISWbemMethod *iface,
719 ISWbemObject **params )
721 struct method *method = impl_from_ISWbemMethod( iface );
722 IWbemClassObject *in_sign = NULL, *instance;
723 HRESULT hr;
725 TRACE("%p, %p\n", method, params);
727 *params = NULL;
729 if (SUCCEEDED(hr = IWbemClassObject_GetMethod( method->set->object->object,
730 method->name, 0, &in_sign, NULL )) && in_sign != NULL)
732 hr = IWbemClassObject_SpawnInstance( in_sign, 0, &instance );
733 IWbemClassObject_Release( in_sign );
734 if (SUCCEEDED(hr))
736 hr = SWbemObject_create( method->set->object->services, instance, params );
737 IWbemClassObject_Release( instance );
741 return hr;
744 static HRESULT WINAPI method_get_OutParameters(
745 ISWbemMethod *iface,
746 ISWbemObject **params )
748 FIXME("\n");
750 return E_NOTIMPL;
753 static HRESULT WINAPI method_get_Qualifiers_(
754 ISWbemMethod *iface,
755 ISWbemQualifierSet **qualifiers )
757 FIXME("\n");
759 return E_NOTIMPL;
762 static const ISWbemMethodVtbl methodvtbl =
764 method_QueryInterface,
765 method_AddRef,
766 method_Release,
767 method_GetTypeInfoCount,
768 method_GetTypeInfo,
769 method_GetIDsOfNames,
770 method_Invoke,
771 method_get_Name,
772 method_get_Origin,
773 method_get_InParameters,
774 method_get_OutParameters,
775 method_get_Qualifiers_,
778 static HRESULT SWbemMethod_create( struct methodset *set, const WCHAR *name, ISWbemMethod **obj )
780 struct method *method;
782 if (!(method = heap_alloc(sizeof(*method))))
783 return E_OUTOFMEMORY;
785 method->ISWbemMethod_iface.lpVtbl = &methodvtbl;
786 method->refs = 1;
787 method->set = set;
788 ISWbemMethodSet_AddRef( &method->set->ISWbemMethodSet_iface );
789 if (!(method->name = heap_strdupW( name )))
791 ISWbemMethod_Release( &method->ISWbemMethod_iface );
792 return E_OUTOFMEMORY;
795 *obj = &method->ISWbemMethod_iface;
797 return S_OK;
800 static struct methodset *impl_from_ISWbemMethodSet( ISWbemMethodSet *iface )
802 return CONTAINING_RECORD( iface, struct methodset, ISWbemMethodSet_iface );
805 static HRESULT WINAPI methodset_QueryInterface( ISWbemMethodSet *iface, REFIID riid, void **ppvObject )
807 struct methodset *set = impl_from_ISWbemMethodSet( iface );
809 TRACE( "%p %s %p\n", set, debugstr_guid(riid), ppvObject );
811 if (IsEqualGUID( riid, &IID_ISWbemMethodSet ) ||
812 IsEqualGUID( riid, &IID_IDispatch ) ||
813 IsEqualGUID( riid, &IID_IUnknown ))
815 *ppvObject = iface;
817 else
819 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
820 return E_NOINTERFACE;
822 ISWbemMethodSet_AddRef( iface );
823 return S_OK;
826 static ULONG WINAPI methodset_AddRef( ISWbemMethodSet *iface )
828 struct methodset *set = impl_from_ISWbemMethodSet( iface );
829 return InterlockedIncrement( &set->refs );
832 static ULONG WINAPI methodset_Release( ISWbemMethodSet *iface )
834 struct methodset *set = impl_from_ISWbemMethodSet( iface );
835 LONG refs = InterlockedDecrement( &set->refs );
836 if (!refs)
838 TRACE( "destroying %p\n", set );
839 ISWbemObject_Release( &set->object->ISWbemObject_iface );
840 heap_free( set );
842 return refs;
845 static HRESULT WINAPI methodset_GetTypeInfoCount(
846 ISWbemMethodSet *iface,
847 UINT *count )
849 struct methodset *set = impl_from_ISWbemMethodSet( iface );
851 TRACE( "%p, %p\n", set, count );
852 *count = 1;
853 return S_OK;
856 static HRESULT WINAPI methodset_GetTypeInfo( ISWbemMethodSet *iface,
857 UINT index,
858 LCID lcid,
859 ITypeInfo **info )
861 struct methodset *set = impl_from_ISWbemMethodSet( iface );
863 TRACE( "%p, %u, %u, %p\n", set, index, lcid, info );
865 return get_typeinfo( ISWbemMethodSet_tid, info );
868 static HRESULT WINAPI methodset_GetIDsOfNames(
869 ISWbemMethodSet *iface,
870 REFIID riid,
871 LPOLESTR *names,
872 UINT count,
873 LCID lcid,
874 DISPID *dispid )
876 struct methodset *set = impl_from_ISWbemMethodSet( iface );
877 ITypeInfo *typeinfo;
878 HRESULT hr;
880 TRACE( "%p, %s, %p, %u, %u, %p\n", set, debugstr_guid(riid), names, count, lcid, dispid );
882 if (!names || !count || !dispid) return E_INVALIDARG;
884 hr = get_typeinfo( ISWbemMethodSet_tid, &typeinfo );
885 if (SUCCEEDED(hr))
887 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
888 ITypeInfo_Release( typeinfo );
890 return hr;
893 static HRESULT WINAPI methodset_Invoke(
894 ISWbemMethodSet *iface,
895 DISPID member,
896 REFIID riid,
897 LCID lcid,
898 WORD flags,
899 DISPPARAMS *params,
900 VARIANT *result,
901 EXCEPINFO *excep_info,
902 UINT *arg_err )
904 struct methodset *set = impl_from_ISWbemMethodSet( iface );
905 ITypeInfo *typeinfo;
906 HRESULT hr;
908 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
909 lcid, flags, params, result, excep_info, arg_err );
911 hr = get_typeinfo( ISWbemMethodSet_tid, &typeinfo );
912 if (SUCCEEDED(hr))
914 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemMethodSet_iface, member, flags,
915 params, result, excep_info, arg_err );
916 ITypeInfo_Release( typeinfo );
918 return hr;
921 static HRESULT WINAPI methodset_get__NewEnum(
922 ISWbemMethodSet *iface,
923 IUnknown **unk )
925 FIXME("\n");
927 return E_NOTIMPL;
930 static HRESULT WINAPI methodset_Item(
931 ISWbemMethodSet *iface,
932 BSTR name,
933 LONG flags,
934 ISWbemMethod **method )
936 struct methodset *set = impl_from_ISWbemMethodSet( iface );
937 IWbemClassObject *in_sign, *out_sign;
938 HRESULT hr;
940 TRACE("%p, %s, %#x, %p\n", set, debugstr_w(name), flags, method);
942 *method = NULL;
944 if (SUCCEEDED(hr = IWbemClassObject_GetMethod( set->object->object,
945 name, flags, &in_sign, &out_sign )))
947 if (in_sign)
948 IWbemClassObject_Release( in_sign );
949 if (out_sign)
950 IWbemClassObject_Release( out_sign );
952 return SWbemMethod_create( set, name, method );
955 return hr;
958 static HRESULT WINAPI methodset_get_Count(
959 ISWbemMethodSet *iface,
960 LONG *count )
962 FIXME("\n");
964 return E_NOTIMPL;
967 static const ISWbemMethodSetVtbl methodsetvtbl =
969 methodset_QueryInterface,
970 methodset_AddRef,
971 methodset_Release,
972 methodset_GetTypeInfoCount,
973 methodset_GetTypeInfo,
974 methodset_GetIDsOfNames,
975 methodset_Invoke,
976 methodset_get__NewEnum,
977 methodset_Item,
978 methodset_get_Count,
981 static HRESULT SWbemMethodSet_create( struct object *object, ISWbemMethodSet **obj )
983 struct methodset *set;
985 if (!(set = heap_alloc(sizeof(*set))))
986 return E_OUTOFMEMORY;
988 set->ISWbemMethodSet_iface.lpVtbl = &methodsetvtbl;
989 set->refs = 1;
990 set->object = object;
991 ISWbemObject_AddRef( &object->ISWbemObject_iface );
993 *obj = &set->ISWbemMethodSet_iface;
995 return S_OK;
998 #define DISPID_BASE 0x1800000
999 #define DISPID_BASE_METHOD 0x1000000
1001 static inline struct object *impl_from_ISWbemObject(
1002 ISWbemObject *iface )
1004 return CONTAINING_RECORD( iface, struct object, ISWbemObject_iface );
1007 static ULONG WINAPI object_AddRef(
1008 ISWbemObject *iface )
1010 struct object *object = impl_from_ISWbemObject( iface );
1011 return InterlockedIncrement( &object->refs );
1014 static ULONG WINAPI object_Release(
1015 ISWbemObject *iface )
1017 struct object *object = impl_from_ISWbemObject( iface );
1018 LONG refs = InterlockedDecrement( &object->refs );
1019 if (!refs)
1021 UINT i;
1023 TRACE( "destroying %p\n", object );
1024 IWbemClassObject_Release( object->object );
1025 ISWbemServices_Release( &object->services->ISWbemServices_iface );
1026 for (i = 0; i < object->nb_members; i++) SysFreeString( object->members[i].name );
1027 heap_free( object->members );
1028 heap_free( object );
1030 return refs;
1033 static HRESULT WINAPI object_QueryInterface(
1034 ISWbemObject *iface,
1035 REFIID riid,
1036 void **ppvObject )
1038 struct object *object = impl_from_ISWbemObject( iface );
1040 TRACE( "%p %s %p\n", object, debugstr_guid(riid), ppvObject );
1042 if (IsEqualGUID( riid, &IID_ISWbemObject ) ||
1043 IsEqualGUID( riid, &IID_IDispatch ) ||
1044 IsEqualGUID( riid, &IID_IUnknown ))
1046 *ppvObject = iface;
1048 else
1050 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
1051 return E_NOINTERFACE;
1053 ISWbemObject_AddRef( iface );
1054 return S_OK;
1057 static HRESULT WINAPI object_GetTypeInfoCount(
1058 ISWbemObject *iface,
1059 UINT *count )
1061 struct object *object = impl_from_ISWbemObject( iface );
1063 TRACE( "%p, %p\n", object, count );
1064 *count = 1;
1065 return S_OK;
1068 static HRESULT WINAPI object_GetTypeInfo(
1069 ISWbemObject *iface,
1070 UINT index,
1071 LCID lcid,
1072 ITypeInfo **info )
1074 struct object *object = impl_from_ISWbemObject( iface );
1075 FIXME( "%p, %u, %u, %p\n", object, index, lcid, info );
1076 return E_NOTIMPL;
1079 static BOOL object_reserve_member( struct object *object, unsigned int count, unsigned int *capacity )
1081 unsigned int new_capacity, max_capacity;
1082 struct member *new_members;
1084 if (count <= *capacity)
1085 return TRUE;
1087 max_capacity = ~0u / sizeof(*object->members);
1088 if (count > max_capacity)
1089 return FALSE;
1091 new_capacity = max(4, *capacity);
1092 while (new_capacity < count && new_capacity <= max_capacity / 2)
1093 new_capacity *= 2;
1094 if (new_capacity < count)
1095 new_capacity = max_capacity;
1097 if (!(new_members = heap_realloc( object->members, new_capacity * sizeof(*new_members) )))
1098 return FALSE;
1100 object->members = new_members;
1101 *capacity = new_capacity;
1103 return TRUE;
1106 static HRESULT init_members( struct object *object )
1108 IWbemClassObject *sig_in, *sig_out;
1109 unsigned int i, capacity = 0, count = 0;
1110 CIMTYPE type;
1111 HRESULT hr;
1112 BSTR name;
1114 if (object->members) return S_OK;
1116 hr = IWbemClassObject_BeginEnumeration( object->object, 0 );
1117 if (SUCCEEDED( hr ))
1119 while (IWbemClassObject_Next( object->object, 0, &name, NULL, &type, NULL ) == S_OK)
1121 if (!object_reserve_member( object, count + 1, &capacity )) goto error;
1122 object->members[count].name = name;
1123 object->members[count].is_method = FALSE;
1124 object->members[count].dispid = 0;
1125 object->members[count].type = type;
1126 count++;
1127 TRACE( "added property %s\n", debugstr_w(name) );
1129 IWbemClassObject_EndEnumeration( object->object );
1132 hr = IWbemClassObject_BeginMethodEnumeration( object->object, 0 );
1133 if (SUCCEEDED( hr ))
1135 while (IWbemClassObject_NextMethod( object->object, 0, &name, &sig_in, &sig_out ) == S_OK)
1137 if (!object_reserve_member( object, count + 1, &capacity )) goto error;
1138 object->members[count].name = name;
1139 object->members[count].is_method = TRUE;
1140 object->members[count].dispid = 0;
1141 count++;
1142 if (sig_in) IWbemClassObject_Release( sig_in );
1143 if (sig_out) IWbemClassObject_Release( sig_out );
1144 TRACE( "added method %s\n", debugstr_w(name) );
1146 IWbemClassObject_EndMethodEnumeration( object->object );
1149 object->nb_members = count;
1150 TRACE( "added %u members\n", object->nb_members );
1151 return S_OK;
1153 error:
1154 for (i = 0; i < count; ++i)
1155 SysFreeString( object->members[i].name );
1156 heap_free( object->members );
1157 object->members = NULL;
1158 object->nb_members = 0;
1159 return E_FAIL;
1162 static DISPID get_member_dispid( struct object *object, const WCHAR *name )
1164 UINT i;
1165 for (i = 0; i < object->nb_members; i++)
1167 if (!wcsicmp( object->members[i].name, name ))
1169 if (!object->members[i].dispid)
1171 if (object->members[i].is_method)
1172 object->members[i].dispid = ++object->last_dispid_method;
1173 else
1174 object->members[i].dispid = ++object->last_dispid;
1176 return object->members[i].dispid;
1179 return DISPID_UNKNOWN;
1182 static HRESULT WINAPI object_GetIDsOfNames(
1183 ISWbemObject *iface,
1184 REFIID riid,
1185 LPOLESTR *names,
1186 UINT count,
1187 LCID lcid,
1188 DISPID *dispid )
1190 struct object *object = impl_from_ISWbemObject( iface );
1191 HRESULT hr;
1192 UINT i;
1193 ITypeInfo *typeinfo;
1195 TRACE( "%p, %s, %p, %u, %u, %p\n", object, debugstr_guid(riid), names, count, lcid, dispid );
1197 if (!names || !count || !dispid) return E_INVALIDARG;
1199 hr = init_members( object );
1200 if (FAILED( hr )) return hr;
1202 hr = get_typeinfo( ISWbemObject_tid, &typeinfo );
1203 if (SUCCEEDED(hr))
1205 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
1206 ITypeInfo_Release( typeinfo );
1208 if (SUCCEEDED(hr)) return hr;
1210 for (i = 0; i < count; i++)
1212 if ((dispid[i] = get_member_dispid( object, names[i] )) == DISPID_UNKNOWN) break;
1214 if (i != count) return DISP_E_UNKNOWNNAME;
1215 return S_OK;
1218 static BSTR get_member_name( struct object *object, DISPID dispid, CIMTYPE *type )
1220 UINT i;
1221 for (i = 0; i < object->nb_members; i++)
1223 if (object->members[i].dispid == dispid)
1225 *type = object->members[i].type;
1226 return object->members[i].name;
1229 return NULL;
1232 static VARTYPE to_vartype( CIMTYPE type )
1234 switch (type)
1236 case CIM_BOOLEAN: return VT_BOOL;
1238 case CIM_STRING:
1239 case CIM_REFERENCE:
1240 case CIM_DATETIME: return VT_BSTR;
1242 case CIM_SINT8: return VT_I1;
1243 case CIM_UINT8: return VT_UI1;
1244 case CIM_SINT16: return VT_I2;
1246 case CIM_UINT16:
1247 case CIM_SINT32: return VT_I4;
1249 case CIM_UINT32: return VT_UI4;
1251 case CIM_SINT64: return VT_I8;
1252 case CIM_UINT64: return VT_UI8;
1254 case CIM_REAL32: return VT_R4;
1256 default:
1257 ERR("unhandled type %u\n", type);
1258 break;
1260 return 0;
1263 static HRESULT WINAPI object_Invoke(
1264 ISWbemObject *iface,
1265 DISPID member,
1266 REFIID riid,
1267 LCID lcid,
1268 WORD flags,
1269 DISPPARAMS *params,
1270 VARIANT *result,
1271 EXCEPINFO *excep_info,
1272 UINT *arg_err )
1274 struct object *object = impl_from_ISWbemObject( iface );
1275 BSTR name;
1276 ITypeInfo *typeinfo;
1277 VARTYPE vartype;
1278 VARIANT value;
1279 CIMTYPE type;
1280 HRESULT hr;
1282 TRACE( "%p, %x, %s, %u, %x, %p, %p, %p, %p\n", object, member, debugstr_guid(riid),
1283 lcid, flags, params, result, excep_info, arg_err );
1285 if (member <= DISPID_BASE_METHOD)
1287 hr = get_typeinfo( ISWbemObject_tid, &typeinfo );
1288 if (SUCCEEDED(hr))
1290 hr = ITypeInfo_Invoke( typeinfo, &object->ISWbemObject_iface, member, flags,
1291 params, result, excep_info, arg_err );
1292 ITypeInfo_Release( typeinfo );
1294 return hr;
1297 if (!(name = get_member_name( object, member, &type )))
1298 return DISP_E_MEMBERNOTFOUND;
1300 if (flags == (DISPATCH_METHOD|DISPATCH_PROPERTYGET))
1302 memset( params, 0, sizeof(*params) );
1303 return IWbemClassObject_Get( object->object, name, 0, result, NULL, NULL );
1305 else if (flags == DISPATCH_PROPERTYPUT)
1307 if (!params->cArgs || !params->rgvarg)
1309 WARN( "Missing put property value\n" );
1310 return E_INVALIDARG;
1313 vartype = to_vartype( type );
1314 V_VT( &value ) = VT_EMPTY;
1315 if (SUCCEEDED(hr = VariantChangeType( &value, params->rgvarg, 0, vartype )))
1317 hr = IWbemClassObject_Put( object->object, name, 0, &value, 0 );
1318 VariantClear( &value );
1320 return hr;
1322 else
1324 FIXME( "flags %x not supported\n", flags );
1325 return E_NOTIMPL;
1329 static HRESULT WINAPI object_Put_(
1330 ISWbemObject *iface,
1331 LONG iFlags,
1332 IDispatch *objWbemNamedValueSet,
1333 ISWbemObjectPath **objWbemObjectPath )
1335 FIXME( "\n" );
1336 return E_NOTIMPL;
1339 static HRESULT WINAPI object_PutAsync_(
1340 ISWbemObject *iface,
1341 IDispatch *objWbemSink,
1342 LONG iFlags,
1343 IDispatch *objWbemNamedValueSet,
1344 IDispatch *objWbemAsyncContext )
1346 FIXME( "\n" );
1347 return E_NOTIMPL;
1350 static HRESULT WINAPI object_Delete_(
1351 ISWbemObject *iface,
1352 LONG iFlags,
1353 IDispatch *objWbemNamedValueSet )
1355 FIXME( "\n" );
1356 return E_NOTIMPL;
1359 static HRESULT WINAPI object_DeleteAsync_(
1360 ISWbemObject *iface,
1361 IDispatch *objWbemSink,
1362 LONG iFlags,
1363 IDispatch *objWbemNamedValueSet,
1364 IDispatch *objWbemAsyncContext )
1366 FIXME( "\n" );
1367 return E_NOTIMPL;
1370 static HRESULT WINAPI object_Instances_(
1371 ISWbemObject *iface,
1372 LONG iFlags,
1373 IDispatch *objWbemNamedValueSet,
1374 ISWbemObjectSet **objWbemObjectSet )
1376 FIXME( "\n" );
1377 return E_NOTIMPL;
1380 static HRESULT WINAPI object_InstancesAsync_(
1381 ISWbemObject *iface,
1382 IDispatch *objWbemSink,
1383 LONG iFlags,
1384 IDispatch *objWbemNamedValueSet,
1385 IDispatch *objWbemAsyncContext )
1387 FIXME( "\n" );
1388 return E_NOTIMPL;
1391 static HRESULT WINAPI object_Subclasses_(
1392 ISWbemObject *iface,
1393 LONG iFlags,
1394 IDispatch *objWbemNamedValueSet,
1395 ISWbemObjectSet **objWbemObjectSet )
1397 FIXME( "\n" );
1398 return E_NOTIMPL;
1401 static HRESULT WINAPI object_SubclassesAsync_(
1402 ISWbemObject *iface,
1403 IDispatch *objWbemSink,
1404 LONG iFlags,
1405 IDispatch *objWbemNamedValueSet,
1406 IDispatch *objWbemAsyncContext )
1408 FIXME( "\n" );
1409 return E_NOTIMPL;
1412 static HRESULT WINAPI object_Associators_(
1413 ISWbemObject *iface,
1414 BSTR strAssocClass,
1415 BSTR strResultClass,
1416 BSTR strResultRole,
1417 BSTR strRole,
1418 VARIANT_BOOL bClassesOnly,
1419 VARIANT_BOOL bSchemaOnly,
1420 BSTR strRequiredAssocQualifier,
1421 BSTR strRequiredQualifier,
1422 LONG iFlags,
1423 IDispatch *objWbemNamedValueSet,
1424 ISWbemObjectSet **objWbemObjectSet )
1426 FIXME( "\n" );
1427 return E_NOTIMPL;
1430 static HRESULT WINAPI object_AssociatorsAsync_(
1431 ISWbemObject *iface,
1432 IDispatch *objWbemSink,
1433 BSTR strAssocClass,
1434 BSTR strResultClass,
1435 BSTR strResultRole,
1436 BSTR strRole,
1437 VARIANT_BOOL bClassesOnly,
1438 VARIANT_BOOL bSchemaOnly,
1439 BSTR strRequiredAssocQualifier,
1440 BSTR strRequiredQualifier,
1441 LONG iFlags,
1442 IDispatch *objWbemNamedValueSet,
1443 IDispatch *objWbemAsyncContext )
1445 FIXME( "\n" );
1446 return E_NOTIMPL;
1449 static HRESULT WINAPI object_References_(
1450 ISWbemObject *iface,
1451 BSTR strResultClass,
1452 BSTR strRole,
1453 VARIANT_BOOL bClassesOnly,
1454 VARIANT_BOOL bSchemaOnly,
1455 BSTR strRequiredQualifier,
1456 LONG iFlags,
1457 IDispatch *objWbemNamedValueSet,
1458 ISWbemObjectSet **objWbemObjectSet )
1460 FIXME( "\n" );
1461 return E_NOTIMPL;
1464 static HRESULT WINAPI object_ReferencesAsync_(
1465 ISWbemObject *iface,
1466 IDispatch *objWbemSink,
1467 BSTR strResultClass,
1468 BSTR strRole,
1469 VARIANT_BOOL bClassesOnly,
1470 VARIANT_BOOL bSchemaOnly,
1471 BSTR strRequiredQualifier,
1472 LONG iFlags,
1473 IDispatch *objWbemNamedValueSet,
1474 IDispatch *objWbemAsyncContext )
1476 FIXME( "\n" );
1477 return E_NOTIMPL;
1480 static HRESULT WINAPI object_ExecMethod_(
1481 ISWbemObject *iface,
1482 BSTR method,
1483 IDispatch *in_params,
1484 LONG flags,
1485 IDispatch *valueset,
1486 ISWbemObject **out_params )
1488 struct object *object = impl_from_ISWbemObject( iface );
1489 VARIANT path;
1490 HRESULT hr;
1492 TRACE( "%p, %s, %p, %#x, %p, %p\n", object, debugstr_w(method), in_params, flags, valueset, out_params );
1494 V_VT( &path ) = VT_EMPTY;
1495 hr = IWbemClassObject_Get( object->object, L"__PATH", 0, &path, NULL, NULL );
1496 if (SUCCEEDED(hr))
1498 if (V_VT( &path ) != VT_BSTR)
1500 WARN( "Unexpected object path value type.\n" );
1501 VariantClear( &path );
1502 return E_UNEXPECTED;
1505 hr = ISWbemServices_ExecMethod( &object->services->ISWbemServices_iface, V_BSTR( &path ), method,
1506 in_params, flags, valueset, out_params );
1508 VariantClear( &path );
1511 return hr;
1514 static HRESULT WINAPI object_ExecMethodAsync_(
1515 ISWbemObject *iface,
1516 IDispatch *objWbemSink,
1517 BSTR strMethodName,
1518 IDispatch *objWbemInParameters,
1519 LONG iFlags,
1520 IDispatch *objWbemNamedValueSet,
1521 IDispatch *objWbemAsyncContext )
1523 FIXME( "\n" );
1524 return E_NOTIMPL;
1527 static HRESULT WINAPI object_Clone_(
1528 ISWbemObject *iface,
1529 ISWbemObject **objWbemObject )
1531 FIXME( "\n" );
1532 return E_NOTIMPL;
1535 static HRESULT WINAPI object_GetObjectText_(
1536 ISWbemObject *iface,
1537 LONG flags,
1538 BSTR *text )
1540 struct object *object = impl_from_ISWbemObject( iface );
1542 TRACE( "%p, %#x, %p\n", object, flags, text );
1544 return IWbemClassObject_GetObjectText( object->object, flags, text );
1547 static HRESULT WINAPI object_SpawnDerivedClass_(
1548 ISWbemObject *iface,
1549 LONG iFlags,
1550 ISWbemObject **objWbemObject )
1552 FIXME( "\n" );
1553 return E_NOTIMPL;
1556 static HRESULT WINAPI object_SpawnInstance_(
1557 ISWbemObject *iface,
1558 LONG iFlags,
1559 ISWbemObject **objWbemObject )
1561 FIXME( "\n" );
1562 return E_NOTIMPL;
1565 static HRESULT WINAPI object_CompareTo_(
1566 ISWbemObject *iface,
1567 IDispatch *objWbemObject,
1568 LONG iFlags,
1569 VARIANT_BOOL *bResult )
1571 FIXME( "\n" );
1572 return E_NOTIMPL;
1575 static HRESULT WINAPI object_get_Qualifiers_(
1576 ISWbemObject *iface,
1577 ISWbemQualifierSet **objWbemQualifierSet )
1579 FIXME( "\n" );
1580 return E_NOTIMPL;
1583 static HRESULT WINAPI object_get_Properties_( ISWbemObject *iface, ISWbemPropertySet **prop_set )
1585 struct object *object = impl_from_ISWbemObject( iface );
1587 TRACE( "%p, %p\n", object, prop_set );
1588 return SWbemPropertySet_create( object->object, prop_set );
1591 static HRESULT WINAPI object_get_Methods_(
1592 ISWbemObject *iface,
1593 ISWbemMethodSet **set )
1595 struct object *object = impl_from_ISWbemObject( iface );
1597 TRACE( "%p, %p\n", object, set );
1598 return SWbemMethodSet_create( object, set );
1601 static HRESULT WINAPI object_get_Derivation_(
1602 ISWbemObject *iface,
1603 VARIANT *strClassNameArray )
1605 FIXME( "\n" );
1606 return E_NOTIMPL;
1609 static HRESULT WINAPI object_get_Path_(
1610 ISWbemObject *iface,
1611 ISWbemObjectPath **objWbemObjectPath )
1613 FIXME( "\n" );
1614 return E_NOTIMPL;
1617 static HRESULT WINAPI object_get_Security_(
1618 ISWbemObject *iface,
1619 ISWbemSecurity **objWbemSecurity )
1621 FIXME( "\n" );
1622 return E_NOTIMPL;
1625 static const ISWbemObjectVtbl object_vtbl =
1627 object_QueryInterface,
1628 object_AddRef,
1629 object_Release,
1630 object_GetTypeInfoCount,
1631 object_GetTypeInfo,
1632 object_GetIDsOfNames,
1633 object_Invoke,
1634 object_Put_,
1635 object_PutAsync_,
1636 object_Delete_,
1637 object_DeleteAsync_,
1638 object_Instances_,
1639 object_InstancesAsync_,
1640 object_Subclasses_,
1641 object_SubclassesAsync_,
1642 object_Associators_,
1643 object_AssociatorsAsync_,
1644 object_References_,
1645 object_ReferencesAsync_,
1646 object_ExecMethod_,
1647 object_ExecMethodAsync_,
1648 object_Clone_,
1649 object_GetObjectText_,
1650 object_SpawnDerivedClass_,
1651 object_SpawnInstance_,
1652 object_CompareTo_,
1653 object_get_Qualifiers_,
1654 object_get_Properties_,
1655 object_get_Methods_,
1656 object_get_Derivation_,
1657 object_get_Path_,
1658 object_get_Security_
1661 static struct object *unsafe_object_impl_from_IDispatch(IDispatch *iface)
1663 if (!iface)
1664 return NULL;
1665 if (iface->lpVtbl != (IDispatchVtbl *)&object_vtbl)
1667 FIXME( "External implementations are not supported.\n" );
1668 return NULL;
1670 return CONTAINING_RECORD(iface, struct object, ISWbemObject_iface);
1673 static HRESULT SWbemObject_create( struct services *services, IWbemClassObject *wbem_object,
1674 ISWbemObject **obj )
1676 struct object *object;
1678 TRACE( "%p, %p\n", obj, wbem_object );
1680 if (!(object = heap_alloc( sizeof(*object) ))) return E_OUTOFMEMORY;
1681 object->ISWbemObject_iface.lpVtbl = &object_vtbl;
1682 object->refs = 1;
1683 object->object = wbem_object;
1684 IWbemClassObject_AddRef( object->object );
1685 object->members = NULL;
1686 object->nb_members = 0;
1687 object->last_dispid = DISPID_BASE;
1688 object->last_dispid_method = DISPID_BASE_METHOD;
1689 object->services = services;
1690 ISWbemServices_AddRef( &object->services->ISWbemServices_iface );
1692 *obj = &object->ISWbemObject_iface;
1693 TRACE( "returning iface %p\n", *obj );
1694 return S_OK;
1697 struct objectset
1699 ISWbemObjectSet ISWbemObjectSet_iface;
1700 LONG refs;
1701 IEnumWbemClassObject *objectenum;
1702 LONG count;
1703 struct services *services;
1706 static inline struct objectset *impl_from_ISWbemObjectSet(
1707 ISWbemObjectSet *iface )
1709 return CONTAINING_RECORD( iface, struct objectset, ISWbemObjectSet_iface );
1712 static ULONG WINAPI objectset_AddRef(
1713 ISWbemObjectSet *iface )
1715 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1716 return InterlockedIncrement( &objectset->refs );
1719 static ULONG WINAPI objectset_Release(
1720 ISWbemObjectSet *iface )
1722 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1723 LONG refs = InterlockedDecrement( &objectset->refs );
1724 if (!refs)
1726 TRACE( "destroying %p\n", objectset );
1727 IEnumWbemClassObject_Release( objectset->objectenum );
1728 ISWbemServices_Release( &objectset->services->ISWbemServices_iface );
1729 heap_free( objectset );
1731 return refs;
1734 static HRESULT WINAPI objectset_QueryInterface(
1735 ISWbemObjectSet *iface,
1736 REFIID riid,
1737 void **ppvObject )
1739 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1741 TRACE( "%p %s %p\n", objectset, debugstr_guid(riid), ppvObject );
1743 if (IsEqualGUID( riid, &IID_ISWbemObjectSet ) ||
1744 IsEqualGUID( riid, &IID_IDispatch ) ||
1745 IsEqualGUID( riid, &IID_IUnknown ))
1747 *ppvObject = iface;
1749 else
1751 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
1752 return E_NOINTERFACE;
1754 ISWbemObjectSet_AddRef( iface );
1755 return S_OK;
1758 static HRESULT WINAPI objectset_GetTypeInfoCount(
1759 ISWbemObjectSet *iface,
1760 UINT *count )
1762 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1763 TRACE( "%p, %p\n", objectset, count );
1764 *count = 1;
1765 return S_OK;
1768 static HRESULT WINAPI objectset_GetTypeInfo(
1769 ISWbemObjectSet *iface,
1770 UINT index,
1771 LCID lcid,
1772 ITypeInfo **info )
1774 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1775 TRACE( "%p, %u, %u, %p\n", objectset, index, lcid, info );
1777 return get_typeinfo( ISWbemObjectSet_tid, info );
1780 static HRESULT WINAPI objectset_GetIDsOfNames(
1781 ISWbemObjectSet *iface,
1782 REFIID riid,
1783 LPOLESTR *names,
1784 UINT count,
1785 LCID lcid,
1786 DISPID *dispid )
1788 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1789 ITypeInfo *typeinfo;
1790 HRESULT hr;
1792 TRACE( "%p, %s, %p, %u, %u, %p\n", objectset, debugstr_guid(riid), names, count, lcid, dispid );
1794 if (!names || !count || !dispid) return E_INVALIDARG;
1796 hr = get_typeinfo( ISWbemObjectSet_tid, &typeinfo );
1797 if (SUCCEEDED(hr))
1799 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
1800 ITypeInfo_Release( typeinfo );
1802 return hr;
1805 static HRESULT WINAPI objectset_Invoke(
1806 ISWbemObjectSet *iface,
1807 DISPID member,
1808 REFIID riid,
1809 LCID lcid,
1810 WORD flags,
1811 DISPPARAMS *params,
1812 VARIANT *result,
1813 EXCEPINFO *excep_info,
1814 UINT *arg_err )
1816 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1817 ITypeInfo *typeinfo;
1818 HRESULT hr;
1820 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", objectset, member, debugstr_guid(riid),
1821 lcid, flags, params, result, excep_info, arg_err );
1823 hr = get_typeinfo( ISWbemObjectSet_tid, &typeinfo );
1824 if (SUCCEEDED(hr))
1826 hr = ITypeInfo_Invoke( typeinfo, &objectset->ISWbemObjectSet_iface, member, flags,
1827 params, result, excep_info, arg_err );
1828 ITypeInfo_Release( typeinfo );
1830 return hr;
1833 static HRESULT WINAPI objectset_get__NewEnum(
1834 ISWbemObjectSet *iface,
1835 IUnknown **pUnk )
1837 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1838 IEnumWbemClassObject *objectenum;
1839 HRESULT hr;
1841 TRACE( "%p, %p\n", objectset, pUnk );
1843 hr = IEnumWbemClassObject_Clone( objectset->objectenum, &objectenum );
1844 if (FAILED( hr )) return hr;
1846 hr = EnumVARIANT_create( objectset->services, objectenum, (IEnumVARIANT **)pUnk );
1847 IEnumWbemClassObject_Release( objectenum );
1848 return hr;
1851 static HRESULT WINAPI objectset_Item(
1852 ISWbemObjectSet *iface,
1853 BSTR strObjectPath,
1854 LONG iFlags,
1855 ISWbemObject **objWbemObject )
1857 FIXME( "\n" );
1858 return E_NOTIMPL;
1861 static HRESULT WINAPI objectset_get_Count(
1862 ISWbemObjectSet *iface,
1863 LONG *iCount )
1865 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1867 TRACE( "%p, %p\n", objectset, iCount );
1869 *iCount = objectset->count;
1870 return S_OK;
1873 static HRESULT WINAPI objectset_get_Security_(
1874 ISWbemObjectSet *iface,
1875 ISWbemSecurity **objWbemSecurity )
1877 FIXME( "\n" );
1878 return E_NOTIMPL;
1881 static HRESULT WINAPI objectset_ItemIndex(
1882 ISWbemObjectSet *iface,
1883 LONG lIndex,
1884 ISWbemObject **objWbemObject )
1886 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1887 LONG count;
1888 HRESULT hr;
1889 IEnumVARIANT *enum_var;
1890 VARIANT var;
1892 TRACE( "%p, %d, %p\n", objectset, lIndex, objWbemObject );
1894 *objWbemObject = NULL;
1895 hr = ISWbemObjectSet_get_Count( iface, &count );
1896 if (FAILED(hr)) return hr;
1898 if (lIndex >= count) return WBEM_E_NOT_FOUND;
1900 hr = ISWbemObjectSet_get__NewEnum( iface, (IUnknown **)&enum_var );
1901 if (FAILED(hr)) return hr;
1903 IEnumVARIANT_Reset( enum_var );
1904 hr = IEnumVARIANT_Skip( enum_var, lIndex );
1905 if (SUCCEEDED(hr))
1906 hr = IEnumVARIANT_Next( enum_var, 1, &var, NULL );
1907 IEnumVARIANT_Release( enum_var );
1909 if (SUCCEEDED(hr))
1911 if (V_VT( &var ) == VT_DISPATCH)
1912 hr = IDispatch_QueryInterface( V_DISPATCH( &var ), &IID_ISWbemObject, (void **)objWbemObject );
1913 else
1914 hr = WBEM_E_NOT_FOUND;
1915 VariantClear( &var );
1918 return hr;
1921 static const ISWbemObjectSetVtbl objectset_vtbl =
1923 objectset_QueryInterface,
1924 objectset_AddRef,
1925 objectset_Release,
1926 objectset_GetTypeInfoCount,
1927 objectset_GetTypeInfo,
1928 objectset_GetIDsOfNames,
1929 objectset_Invoke,
1930 objectset_get__NewEnum,
1931 objectset_Item,
1932 objectset_get_Count,
1933 objectset_get_Security_,
1934 objectset_ItemIndex
1937 static LONG get_object_count( IEnumWbemClassObject *iter )
1939 LONG count = 0;
1940 while (IEnumWbemClassObject_Skip( iter, WBEM_INFINITE, 1 ) == S_OK) count++;
1941 IEnumWbemClassObject_Reset( iter );
1942 return count;
1945 static HRESULT SWbemObjectSet_create( struct services *services, IEnumWbemClassObject *wbem_objectenum,
1946 ISWbemObjectSet **obj )
1948 struct objectset *objectset;
1950 TRACE( "%p, %p\n", obj, wbem_objectenum );
1952 if (!(objectset = heap_alloc( sizeof(*objectset) ))) return E_OUTOFMEMORY;
1953 objectset->ISWbemObjectSet_iface.lpVtbl = &objectset_vtbl;
1954 objectset->refs = 1;
1955 objectset->objectenum = wbem_objectenum;
1956 IEnumWbemClassObject_AddRef( objectset->objectenum );
1957 objectset->count = get_object_count( objectset->objectenum );
1958 objectset->services = services;
1959 ISWbemServices_AddRef( &services->ISWbemServices_iface );
1961 *obj = &objectset->ISWbemObjectSet_iface;
1962 TRACE( "returning iface %p\n", *obj );
1963 return S_OK;
1966 struct enumvar
1968 IEnumVARIANT IEnumVARIANT_iface;
1969 LONG refs;
1970 IEnumWbemClassObject *objectenum;
1971 struct services *services;
1974 static inline struct enumvar *impl_from_IEnumVARIANT(
1975 IEnumVARIANT *iface )
1977 return CONTAINING_RECORD( iface, struct enumvar, IEnumVARIANT_iface );
1980 static ULONG WINAPI enumvar_AddRef(
1981 IEnumVARIANT *iface )
1983 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
1984 return InterlockedIncrement( &enumvar->refs );
1987 static ULONG WINAPI enumvar_Release(
1988 IEnumVARIANT *iface )
1990 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
1991 LONG refs = InterlockedDecrement( &enumvar->refs );
1992 if (!refs)
1994 TRACE( "destroying %p\n", enumvar );
1995 IEnumWbemClassObject_Release( enumvar->objectenum );
1996 ISWbemServices_Release( &enumvar->services->ISWbemServices_iface );
1997 heap_free( enumvar );
1999 return refs;
2002 static HRESULT WINAPI enumvar_QueryInterface(
2003 IEnumVARIANT *iface,
2004 REFIID riid,
2005 void **ppvObject )
2007 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2009 TRACE( "%p %s %p\n", enumvar, debugstr_guid(riid), ppvObject );
2011 if (IsEqualGUID( riid, &IID_IEnumVARIANT ) ||
2012 IsEqualGUID( riid, &IID_IUnknown ))
2014 *ppvObject = iface;
2016 else
2018 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2019 return E_NOINTERFACE;
2021 IEnumVARIANT_AddRef( iface );
2022 return S_OK;
2025 static HRESULT WINAPI enumvar_Next( IEnumVARIANT *iface, ULONG celt, VARIANT *var, ULONG *fetched )
2027 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2028 IWbemClassObject *obj;
2029 ULONG count = 0;
2031 TRACE( "%p, %u, %p, %p\n", iface, celt, var, fetched );
2033 if (celt) IEnumWbemClassObject_Next( enumvar->objectenum, WBEM_INFINITE, 1, &obj, &count );
2034 if (count)
2036 ISWbemObject *sobj;
2037 HRESULT hr;
2039 hr = SWbemObject_create( enumvar->services, obj, &sobj );
2040 IWbemClassObject_Release( obj );
2041 if (FAILED( hr )) return hr;
2043 V_VT( var ) = VT_DISPATCH;
2044 V_DISPATCH( var ) = (IDispatch *)sobj;
2046 if (fetched) *fetched = count;
2047 return (count < celt) ? S_FALSE : S_OK;
2050 static HRESULT WINAPI enumvar_Skip( IEnumVARIANT *iface, ULONG celt )
2052 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2054 TRACE( "%p, %u\n", iface, celt );
2056 return IEnumWbemClassObject_Skip( enumvar->objectenum, WBEM_INFINITE, celt );
2059 static HRESULT WINAPI enumvar_Reset( IEnumVARIANT *iface )
2061 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2063 TRACE( "%p\n", iface );
2065 return IEnumWbemClassObject_Reset( enumvar->objectenum );
2068 static HRESULT WINAPI enumvar_Clone( IEnumVARIANT *iface, IEnumVARIANT **penum )
2070 FIXME( "%p, %p\n", iface, penum );
2071 return E_NOTIMPL;
2074 static const struct IEnumVARIANTVtbl enumvar_vtbl =
2076 enumvar_QueryInterface,
2077 enumvar_AddRef,
2078 enumvar_Release,
2079 enumvar_Next,
2080 enumvar_Skip,
2081 enumvar_Reset,
2082 enumvar_Clone
2085 static HRESULT EnumVARIANT_create( struct services *services, IEnumWbemClassObject *objectenum,
2086 IEnumVARIANT **obj )
2088 struct enumvar *enumvar;
2090 if (!(enumvar = heap_alloc( sizeof(*enumvar) ))) return E_OUTOFMEMORY;
2091 enumvar->IEnumVARIANT_iface.lpVtbl = &enumvar_vtbl;
2092 enumvar->refs = 1;
2093 enumvar->objectenum = objectenum;
2094 IEnumWbemClassObject_AddRef( enumvar->objectenum );
2095 enumvar->services = services;
2096 ISWbemServices_AddRef( &services->ISWbemServices_iface );
2098 *obj = &enumvar->IEnumVARIANT_iface;
2099 TRACE( "returning iface %p\n", *obj );
2100 return S_OK;
2103 static inline struct services *impl_from_ISWbemServices(
2104 ISWbemServices *iface )
2106 return CONTAINING_RECORD( iface, struct services, ISWbemServices_iface );
2109 static ULONG WINAPI services_AddRef(
2110 ISWbemServices *iface )
2112 struct services *services = impl_from_ISWbemServices( iface );
2113 return InterlockedIncrement( &services->refs );
2116 static ULONG WINAPI services_Release(
2117 ISWbemServices *iface )
2119 struct services *services = impl_from_ISWbemServices( iface );
2120 LONG refs = InterlockedDecrement( &services->refs );
2121 if (!refs)
2123 TRACE( "destroying %p\n", services );
2124 IWbemServices_Release( services->services );
2125 heap_free( services );
2127 return refs;
2130 static HRESULT WINAPI services_QueryInterface(
2131 ISWbemServices *iface,
2132 REFIID riid,
2133 void **ppvObject )
2135 struct services *services = impl_from_ISWbemServices( iface );
2137 TRACE( "%p %s %p\n", services, debugstr_guid(riid), ppvObject );
2139 if (IsEqualGUID( riid, &IID_ISWbemServices ) ||
2140 IsEqualGUID( riid, &IID_IDispatch ) ||
2141 IsEqualGUID( riid, &IID_IUnknown ))
2143 *ppvObject = iface;
2145 else
2147 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2148 return E_NOINTERFACE;
2150 ISWbemServices_AddRef( iface );
2151 return S_OK;
2154 static HRESULT WINAPI services_GetTypeInfoCount(
2155 ISWbemServices *iface,
2156 UINT *count )
2158 struct services *services = impl_from_ISWbemServices( iface );
2159 TRACE( "%p, %p\n", services, count );
2161 *count = 1;
2162 return S_OK;
2165 static HRESULT WINAPI services_GetTypeInfo(
2166 ISWbemServices *iface,
2167 UINT index,
2168 LCID lcid,
2169 ITypeInfo **info )
2171 struct services *services = impl_from_ISWbemServices( iface );
2172 TRACE( "%p, %u, %u, %p\n", services, index, lcid, info );
2174 return get_typeinfo( ISWbemServices_tid, info );
2177 static HRESULT WINAPI services_GetIDsOfNames(
2178 ISWbemServices *iface,
2179 REFIID riid,
2180 LPOLESTR *names,
2181 UINT count,
2182 LCID lcid,
2183 DISPID *dispid )
2185 struct services *services = impl_from_ISWbemServices( iface );
2186 ITypeInfo *typeinfo;
2187 HRESULT hr;
2189 TRACE( "%p, %s, %p, %u, %u, %p\n", services, debugstr_guid(riid), names, count, lcid, dispid );
2191 if (!names || !count || !dispid) return E_INVALIDARG;
2193 hr = get_typeinfo( ISWbemServices_tid, &typeinfo );
2194 if (SUCCEEDED(hr))
2196 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2197 ITypeInfo_Release( typeinfo );
2199 return hr;
2202 static HRESULT WINAPI services_Invoke(
2203 ISWbemServices *iface,
2204 DISPID member,
2205 REFIID riid,
2206 LCID lcid,
2207 WORD flags,
2208 DISPPARAMS *params,
2209 VARIANT *result,
2210 EXCEPINFO *excep_info,
2211 UINT *arg_err )
2213 struct services *services = impl_from_ISWbemServices( iface );
2214 ITypeInfo *typeinfo;
2215 HRESULT hr;
2217 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", services, member, debugstr_guid(riid),
2218 lcid, flags, params, result, excep_info, arg_err );
2220 hr = get_typeinfo( ISWbemServices_tid, &typeinfo );
2221 if (SUCCEEDED(hr))
2223 hr = ITypeInfo_Invoke( typeinfo, &services->ISWbemServices_iface, member, flags,
2224 params, result, excep_info, arg_err );
2225 ITypeInfo_Release( typeinfo );
2227 return hr;
2230 static HRESULT WINAPI services_Get(
2231 ISWbemServices *iface,
2232 BSTR strObjectPath,
2233 LONG iFlags,
2234 IDispatch *objWbemNamedValueSet,
2235 ISWbemObject **objWbemObject )
2237 struct services *services = impl_from_ISWbemServices( iface );
2238 IWbemClassObject *obj;
2239 HRESULT hr;
2241 TRACE( "%p, %s, %d, %p, %p\n", iface, debugstr_w(strObjectPath), iFlags, objWbemNamedValueSet,
2242 objWbemObject );
2244 if (objWbemNamedValueSet) FIXME( "ignoring context\n" );
2246 hr = IWbemServices_GetObject( services->services, strObjectPath, iFlags, NULL, &obj, NULL );
2247 if (hr != S_OK) return hr;
2249 hr = SWbemObject_create( services, obj, objWbemObject );
2250 IWbemClassObject_Release( obj );
2251 return hr;
2254 static HRESULT WINAPI services_GetAsync(
2255 ISWbemServices *iface,
2256 IDispatch *objWbemSink,
2257 BSTR strObjectPath,
2258 LONG iFlags,
2259 IDispatch *objWbemNamedValueSet,
2260 IDispatch *objWbemAsyncContext )
2262 FIXME( "\n" );
2263 return E_NOTIMPL;
2266 static HRESULT WINAPI services_Delete(
2267 ISWbemServices *iface,
2268 BSTR strObjectPath,
2269 LONG iFlags,
2270 IDispatch *objWbemNamedValueSet )
2272 FIXME( "\n" );
2273 return E_NOTIMPL;
2276 static HRESULT WINAPI services_DeleteAsync(
2277 ISWbemServices* This,
2278 IDispatch *objWbemSink,
2279 BSTR strObjectPath,
2280 LONG iFlags,
2281 IDispatch *objWbemNamedValueSet,
2282 IDispatch *objWbemAsyncContext )
2284 FIXME( "\n" );
2285 return E_NOTIMPL;
2288 static BSTR build_query_string( const WCHAR *class )
2290 UINT len = lstrlenW(class) + ARRAY_SIZE(L"SELECT * FROM ");
2291 BSTR ret;
2293 if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
2294 lstrcpyW( ret, L"SELECT * FROM " );
2295 lstrcatW( ret, class );
2296 return ret;
2299 static HRESULT WINAPI services_InstancesOf(
2300 ISWbemServices *iface,
2301 BSTR strClass,
2302 LONG iFlags,
2303 IDispatch *objWbemNamedValueSet,
2304 ISWbemObjectSet **objWbemObjectSet )
2306 BSTR query, wql = SysAllocString( L"WQL" );
2307 HRESULT hr;
2309 TRACE( "%p, %s, %x, %p, %p\n", iface, debugstr_w(strClass), iFlags, objWbemNamedValueSet,
2310 objWbemObjectSet );
2312 if (!(query = build_query_string( strClass )))
2314 SysFreeString( wql );
2315 return E_OUTOFMEMORY;
2317 hr = ISWbemServices_ExecQuery( iface, query, wql, iFlags, objWbemNamedValueSet, objWbemObjectSet );
2318 SysFreeString( wql );
2319 SysFreeString( query );
2320 return hr;
2323 static HRESULT WINAPI services_InstancesOfAsync(
2324 ISWbemServices *iface,
2325 IDispatch *objWbemSink,
2326 BSTR strClass,
2327 LONG iFlags,
2328 IDispatch *objWbemNamedValueSet,
2329 IDispatch *objWbemAsyncContext )
2331 FIXME( "\n" );
2332 return E_NOTIMPL;
2335 static HRESULT WINAPI services_SubclassesOf(
2336 ISWbemServices *iface,
2337 BSTR strSuperclass,
2338 LONG iFlags,
2339 IDispatch *objWbemNamedValueSet,
2340 ISWbemObjectSet **objWbemObjectSet )
2342 FIXME( "\n" );
2343 return E_NOTIMPL;
2346 static HRESULT WINAPI services_SubclassesOfAsync(
2347 ISWbemServices *iface,
2348 IDispatch *objWbemSink,
2349 BSTR strSuperclass,
2350 LONG iFlags,
2351 IDispatch *objWbemNamedValueSet,
2352 IDispatch *objWbemAsyncContext )
2354 FIXME( "\n" );
2355 return E_NOTIMPL;
2358 static HRESULT WINAPI services_ExecQuery(
2359 ISWbemServices *iface,
2360 BSTR strQuery,
2361 BSTR strQueryLanguage,
2362 LONG iFlags,
2363 IDispatch *objWbemNamedValueSet,
2364 ISWbemObjectSet **objWbemObjectSet )
2366 struct services *services = impl_from_ISWbemServices( iface );
2367 IEnumWbemClassObject *iter;
2368 HRESULT hr;
2370 TRACE( "%p, %s, %s, %x, %p, %p\n", iface, debugstr_w(strQuery), debugstr_w(strQueryLanguage),
2371 iFlags, objWbemNamedValueSet, objWbemObjectSet );
2373 if (objWbemNamedValueSet) FIXME( "ignoring context\n" );
2375 hr = IWbemServices_ExecQuery( services->services, strQueryLanguage, strQuery, iFlags, NULL, &iter );
2376 if (hr != S_OK) return hr;
2378 hr = SWbemObjectSet_create( services, iter, objWbemObjectSet );
2379 IEnumWbemClassObject_Release( iter );
2380 return hr;
2383 static HRESULT WINAPI services_ExecQueryAsync(
2384 ISWbemServices *iface,
2385 IDispatch *objWbemSink,
2386 BSTR strQuery,
2387 BSTR strQueryLanguage,
2388 LONG lFlags,
2389 IDispatch *objWbemNamedValueSet,
2390 IDispatch *objWbemAsyncContext )
2392 FIXME( "\n" );
2393 return E_NOTIMPL;
2396 static HRESULT WINAPI services_AssociatorsOf(
2397 ISWbemServices *iface,
2398 BSTR strObjectPath,
2399 BSTR strAssocClass,
2400 BSTR strResultClass,
2401 BSTR strResultRole,
2402 BSTR strRole,
2403 VARIANT_BOOL bClassesOnly,
2404 VARIANT_BOOL bSchemaOnly,
2405 BSTR strRequiredAssocQualifier,
2406 BSTR strRequiredQualifier,
2407 LONG iFlags,
2408 IDispatch *objWbemNamedValueSet,
2409 ISWbemObjectSet **objWbemObjectSet )
2411 FIXME( "\n" );
2412 return E_NOTIMPL;
2415 static HRESULT WINAPI services_AssociatorsOfAsync(
2416 ISWbemServices *iface,
2417 IDispatch *objWbemSink,
2418 BSTR strObjectPath,
2419 BSTR strAssocClass,
2420 BSTR strResultClass,
2421 BSTR strResultRole,
2422 BSTR strRole,
2423 VARIANT_BOOL bClassesOnly,
2424 VARIANT_BOOL bSchemaOnly,
2425 BSTR strRequiredAssocQualifier,
2426 BSTR strRequiredQualifier,
2427 LONG iFlags,
2428 IDispatch *objWbemNamedValueSet,
2429 IDispatch *objWbemAsyncContext )
2431 FIXME( "\n" );
2432 return E_NOTIMPL;
2435 static HRESULT WINAPI services_ReferencesTo(
2436 ISWbemServices *iface,
2437 BSTR strObjectPath,
2438 BSTR strResultClass,
2439 BSTR strRole,
2440 VARIANT_BOOL bClassesOnly,
2441 VARIANT_BOOL bSchemaOnly,
2442 BSTR strRequiredQualifier,
2443 LONG iFlags,
2444 IDispatch *objWbemNamedValueSet,
2445 ISWbemObjectSet **objWbemObjectSet )
2447 FIXME( "\n" );
2448 return E_NOTIMPL;
2451 static HRESULT WINAPI services_ReferencesToAsync(
2452 ISWbemServices *iface,
2453 IDispatch *objWbemSink,
2454 BSTR strObjectPath,
2455 BSTR strResultClass,
2456 BSTR strRole,
2457 VARIANT_BOOL bClassesOnly,
2458 VARIANT_BOOL bSchemaOnly,
2459 BSTR strRequiredQualifier,
2460 LONG iFlags,
2461 IDispatch *objWbemNamedValueSet,
2462 IDispatch *objWbemAsyncContext )
2464 FIXME( "\n" );
2465 return E_NOTIMPL;
2468 static HRESULT WINAPI services_ExecNotificationQuery(
2469 ISWbemServices *iface,
2470 BSTR strQuery,
2471 BSTR strQueryLanguage,
2472 LONG iFlags,
2473 IDispatch *objWbemNamedValueSet,
2474 ISWbemEventSource **objWbemEventSource )
2476 FIXME( "\n" );
2477 return E_NOTIMPL;
2480 static HRESULT WINAPI services_ExecNotificationQueryAsync(
2481 ISWbemServices *iface,
2482 IDispatch *objWbemSink,
2483 BSTR strQuery,
2484 BSTR strQueryLanguage,
2485 LONG iFlags,
2486 IDispatch *objWbemNamedValueSet,
2487 IDispatch *objWbemAsyncContext )
2489 FIXME( "\n" );
2490 return E_NOTIMPL;
2493 static HRESULT WINAPI services_ExecMethod(
2494 ISWbemServices *iface,
2495 BSTR path,
2496 BSTR method,
2497 IDispatch *in_sparams,
2498 LONG flags,
2499 IDispatch *valueset,
2500 ISWbemObject **out_sparams )
2502 struct services *services = impl_from_ISWbemServices( iface );
2503 IWbemClassObject *out_params = NULL;
2504 struct object *in_params;
2505 IWbemContext *context;
2506 HRESULT hr;
2508 TRACE( "%p, %s, %s, %p, %#x, %p, %p\n", services, debugstr_w(path), debugstr_w(method), in_sparams,
2509 flags, valueset, out_sparams );
2511 in_params = unsafe_object_impl_from_IDispatch( in_sparams );
2512 out_params = NULL;
2514 context = unsafe_get_context_from_namedvalueset( valueset );
2516 hr = IWbemServices_ExecMethod( services->services, path, method, flags, context, in_params ? in_params->object : NULL,
2517 out_sparams ? &out_params : NULL, NULL );
2519 if (SUCCEEDED(hr) && out_params)
2521 hr = SWbemObject_create( services, out_params, out_sparams );
2522 IWbemClassObject_Release( out_params );
2525 return hr;
2528 static HRESULT WINAPI services_ExecMethodAsync(
2529 ISWbemServices *iface,
2530 IDispatch *objWbemSink,
2531 BSTR strObjectPath,
2532 BSTR strMethodName,
2533 IDispatch *objWbemInParameters,
2534 LONG iFlags,
2535 IDispatch *objWbemNamedValueSet,
2536 IDispatch *objWbemAsyncContext )
2538 FIXME( "\n" );
2539 return E_NOTIMPL;
2542 static HRESULT WINAPI services_get_Security_(
2543 ISWbemServices *iface,
2544 ISWbemSecurity **objWbemSecurity )
2546 TRACE( "%p, %p\n", iface, objWbemSecurity );
2548 if (!objWbemSecurity)
2549 return E_INVALIDARG;
2551 return ISWbemSecurity_create( objWbemSecurity );
2554 static const ISWbemServicesVtbl services_vtbl =
2556 services_QueryInterface,
2557 services_AddRef,
2558 services_Release,
2559 services_GetTypeInfoCount,
2560 services_GetTypeInfo,
2561 services_GetIDsOfNames,
2562 services_Invoke,
2563 services_Get,
2564 services_GetAsync,
2565 services_Delete,
2566 services_DeleteAsync,
2567 services_InstancesOf,
2568 services_InstancesOfAsync,
2569 services_SubclassesOf,
2570 services_SubclassesOfAsync,
2571 services_ExecQuery,
2572 services_ExecQueryAsync,
2573 services_AssociatorsOf,
2574 services_AssociatorsOfAsync,
2575 services_ReferencesTo,
2576 services_ReferencesToAsync,
2577 services_ExecNotificationQuery,
2578 services_ExecNotificationQueryAsync,
2579 services_ExecMethod,
2580 services_ExecMethodAsync,
2581 services_get_Security_
2584 static HRESULT SWbemServices_create( IWbemServices *wbem_services, ISWbemServices **obj )
2586 struct services *services;
2588 TRACE( "%p, %p\n", obj, wbem_services );
2590 if (!(services = heap_alloc( sizeof(*services) ))) return E_OUTOFMEMORY;
2591 services->ISWbemServices_iface.lpVtbl = &services_vtbl;
2592 services->refs = 1;
2593 services->services = wbem_services;
2594 IWbemServices_AddRef( services->services );
2596 *obj = &services->ISWbemServices_iface;
2597 TRACE( "returning iface %p\n", *obj );
2598 return S_OK;
2601 struct locator
2603 ISWbemLocator ISWbemLocator_iface;
2604 LONG refs;
2605 IWbemLocator *locator;
2608 static inline struct locator *impl_from_ISWbemLocator( ISWbemLocator *iface )
2610 return CONTAINING_RECORD( iface, struct locator, ISWbemLocator_iface );
2613 static ULONG WINAPI locator_AddRef(
2614 ISWbemLocator *iface )
2616 struct locator *locator = impl_from_ISWbemLocator( iface );
2617 return InterlockedIncrement( &locator->refs );
2620 static ULONG WINAPI locator_Release(
2621 ISWbemLocator *iface )
2623 struct locator *locator = impl_from_ISWbemLocator( iface );
2624 LONG refs = InterlockedDecrement( &locator->refs );
2625 if (!refs)
2627 TRACE( "destroying %p\n", locator );
2628 if (locator->locator)
2629 IWbemLocator_Release( locator->locator );
2630 heap_free( locator );
2632 return refs;
2635 static HRESULT WINAPI locator_QueryInterface(
2636 ISWbemLocator *iface,
2637 REFIID riid,
2638 void **ppvObject )
2640 struct locator *locator = impl_from_ISWbemLocator( iface );
2642 TRACE( "%p, %s, %p\n", locator, debugstr_guid( riid ), ppvObject );
2644 if (IsEqualGUID( riid, &IID_ISWbemLocator ) ||
2645 IsEqualGUID( riid, &IID_IDispatch ) ||
2646 IsEqualGUID( riid, &IID_IUnknown ))
2648 *ppvObject = iface;
2650 else
2652 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2653 return E_NOINTERFACE;
2655 ISWbemLocator_AddRef( iface );
2656 return S_OK;
2659 static HRESULT WINAPI locator_GetTypeInfoCount(
2660 ISWbemLocator *iface,
2661 UINT *count )
2663 struct locator *locator = impl_from_ISWbemLocator( iface );
2665 TRACE( "%p, %p\n", locator, count );
2666 *count = 1;
2667 return S_OK;
2670 static HRESULT WINAPI locator_GetTypeInfo(
2671 ISWbemLocator *iface,
2672 UINT index,
2673 LCID lcid,
2674 ITypeInfo **info )
2676 struct locator *locator = impl_from_ISWbemLocator( iface );
2677 TRACE( "%p, %u, %u, %p\n", locator, index, lcid, info );
2679 return get_typeinfo( ISWbemLocator_tid, info );
2682 static HRESULT WINAPI locator_GetIDsOfNames(
2683 ISWbemLocator *iface,
2684 REFIID riid,
2685 LPOLESTR *names,
2686 UINT count,
2687 LCID lcid,
2688 DISPID *dispid )
2690 struct locator *locator = impl_from_ISWbemLocator( iface );
2691 ITypeInfo *typeinfo;
2692 HRESULT hr;
2694 TRACE( "%p, %s, %p, %u, %u, %p\n", locator, debugstr_guid(riid), names, count, lcid, dispid );
2696 if (!names || !count || !dispid) return E_INVALIDARG;
2698 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
2699 if (SUCCEEDED(hr))
2701 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2702 ITypeInfo_Release( typeinfo );
2704 return hr;
2707 static HRESULT WINAPI locator_Invoke(
2708 ISWbemLocator *iface,
2709 DISPID member,
2710 REFIID riid,
2711 LCID lcid,
2712 WORD flags,
2713 DISPPARAMS *params,
2714 VARIANT *result,
2715 EXCEPINFO *excep_info,
2716 UINT *arg_err )
2718 struct locator *locator = impl_from_ISWbemLocator( iface );
2719 ITypeInfo *typeinfo;
2720 HRESULT hr;
2722 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", locator, member, debugstr_guid(riid),
2723 lcid, flags, params, result, excep_info, arg_err );
2725 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
2726 if (SUCCEEDED(hr))
2728 hr = ITypeInfo_Invoke( typeinfo, &locator->ISWbemLocator_iface, member, flags,
2729 params, result, excep_info, arg_err );
2730 ITypeInfo_Release( typeinfo );
2732 return hr;
2735 static BSTR build_resource_string( BSTR server, BSTR namespace )
2737 ULONG len, len_server = 0, len_namespace = 0;
2738 BSTR ret;
2740 if (server && *server) len_server = lstrlenW( server );
2741 else len_server = 1;
2742 if (namespace && *namespace) len_namespace = lstrlenW( namespace );
2743 else len_namespace = ARRAY_SIZE(L"root\\default") - 1;
2745 if (!(ret = SysAllocStringLen( NULL, 2 + len_server + 1 + len_namespace ))) return NULL;
2747 ret[0] = ret[1] = '\\';
2748 if (server && *server) lstrcpyW( ret + 2, server );
2749 else ret[2] = '.';
2751 len = len_server + 2;
2752 ret[len++] = '\\';
2754 if (namespace && *namespace) lstrcpyW( ret + len, namespace );
2755 else lstrcpyW( ret + len, L"root\\default" );
2756 return ret;
2759 static HRESULT WINAPI locator_ConnectServer(
2760 ISWbemLocator *iface,
2761 BSTR strServer,
2762 BSTR strNamespace,
2763 BSTR strUser,
2764 BSTR strPassword,
2765 BSTR strLocale,
2766 BSTR strAuthority,
2767 LONG iSecurityFlags,
2768 IDispatch *objWbemNamedValueSet,
2769 ISWbemServices **objWbemServices )
2771 struct locator *locator = impl_from_ISWbemLocator( iface );
2772 IWbemServices *services;
2773 IWbemContext *context;
2774 BSTR resource;
2775 HRESULT hr;
2777 TRACE( "%p, %s, %s, %s, %p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strServer),
2778 debugstr_w(strNamespace), debugstr_w(strUser), strPassword, debugstr_w(strLocale),
2779 debugstr_w(strAuthority), iSecurityFlags, objWbemNamedValueSet, objWbemServices );
2781 if (!locator->locator)
2783 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
2784 (void **)&locator->locator );
2785 if (hr != S_OK) return hr;
2788 context = unsafe_get_context_from_namedvalueset( objWbemNamedValueSet );
2790 if (!(resource = build_resource_string( strServer, strNamespace ))) return E_OUTOFMEMORY;
2791 hr = IWbemLocator_ConnectServer( locator->locator, resource, strUser, strPassword, strLocale,
2792 iSecurityFlags, strAuthority, context, &services );
2793 SysFreeString( resource );
2794 if (hr != S_OK) return hr;
2796 hr = SWbemServices_create( services, objWbemServices );
2797 IWbemServices_Release( services );
2798 return hr;
2801 static HRESULT WINAPI locator_get_Security_(
2802 ISWbemLocator *iface,
2803 ISWbemSecurity **objWbemSecurity )
2805 TRACE( "%p, %p\n", iface, objWbemSecurity );
2807 if (!objWbemSecurity)
2808 return E_INVALIDARG;
2810 return ISWbemSecurity_create( objWbemSecurity );
2813 static const ISWbemLocatorVtbl locator_vtbl =
2815 locator_QueryInterface,
2816 locator_AddRef,
2817 locator_Release,
2818 locator_GetTypeInfoCount,
2819 locator_GetTypeInfo,
2820 locator_GetIDsOfNames,
2821 locator_Invoke,
2822 locator_ConnectServer,
2823 locator_get_Security_
2826 HRESULT SWbemLocator_create( void **obj )
2828 struct locator *locator;
2830 TRACE( "%p\n", obj );
2832 if (!(locator = heap_alloc( sizeof(*locator) ))) return E_OUTOFMEMORY;
2833 locator->ISWbemLocator_iface.lpVtbl = &locator_vtbl;
2834 locator->refs = 1;
2835 locator->locator = NULL;
2837 *obj = &locator->ISWbemLocator_iface;
2838 TRACE( "returning iface %p\n", *obj );
2839 return S_OK;
2842 struct security
2844 ISWbemSecurity ISWbemSecurity_iface;
2845 LONG refs;
2846 WbemImpersonationLevelEnum implevel;
2847 WbemAuthenticationLevelEnum authlevel;
2850 static inline struct security *impl_from_ISWbemSecurity( ISWbemSecurity *iface )
2852 return CONTAINING_RECORD( iface, struct security, ISWbemSecurity_iface );
2855 static ULONG WINAPI security_AddRef(
2856 ISWbemSecurity *iface )
2858 struct security *security = impl_from_ISWbemSecurity( iface );
2859 return InterlockedIncrement( &security->refs );
2862 static ULONG WINAPI security_Release(
2863 ISWbemSecurity *iface )
2865 struct security *security = impl_from_ISWbemSecurity( iface );
2866 LONG refs = InterlockedDecrement( &security->refs );
2867 if (!refs)
2869 TRACE( "destroying %p\n", security );
2870 heap_free( security );
2872 return refs;
2875 static HRESULT WINAPI security_QueryInterface(
2876 ISWbemSecurity *iface,
2877 REFIID riid,
2878 void **ppvObject )
2880 struct security *security = impl_from_ISWbemSecurity( iface );
2881 TRACE( "%p, %s, %p\n", security, debugstr_guid( riid ), ppvObject );
2883 if (IsEqualGUID( riid, &IID_ISWbemSecurity ) ||
2884 IsEqualGUID( riid, &IID_IDispatch ) ||
2885 IsEqualGUID( riid, &IID_IUnknown ))
2887 *ppvObject = iface;
2889 else
2891 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2892 return E_NOINTERFACE;
2894 ISWbemSecurity_AddRef( iface );
2895 return S_OK;
2898 static HRESULT WINAPI security_GetTypeInfoCount(
2899 ISWbemSecurity *iface,
2900 UINT *count )
2902 struct security *security = impl_from_ISWbemSecurity( iface );
2903 TRACE( "%p, %p\n", security, count );
2905 *count = 1;
2906 return S_OK;
2909 static HRESULT WINAPI security_GetTypeInfo(
2910 ISWbemSecurity *iface,
2911 UINT index,
2912 LCID lcid,
2913 ITypeInfo **info )
2915 struct security *security = impl_from_ISWbemSecurity( iface );
2916 TRACE( "%p, %u, %u, %p\n", security, index, lcid, info );
2918 return get_typeinfo( ISWbemSecurity_tid, info );
2921 static HRESULT WINAPI security_GetIDsOfNames(
2922 ISWbemSecurity *iface,
2923 REFIID riid,
2924 LPOLESTR *names,
2925 UINT count,
2926 LCID lcid,
2927 DISPID *dispid )
2929 struct security *security = impl_from_ISWbemSecurity( iface );
2930 ITypeInfo *typeinfo;
2931 HRESULT hr;
2933 TRACE( "%p, %s, %p, %u, %u, %p\n", security, debugstr_guid(riid), names, count, lcid, dispid );
2935 if (!names || !count || !dispid) return E_INVALIDARG;
2937 hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo );
2938 if (SUCCEEDED(hr))
2940 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2941 ITypeInfo_Release( typeinfo );
2943 return hr;
2946 static HRESULT WINAPI security_Invoke(
2947 ISWbemSecurity *iface,
2948 DISPID member,
2949 REFIID riid,
2950 LCID lcid,
2951 WORD flags,
2952 DISPPARAMS *params,
2953 VARIANT *result,
2954 EXCEPINFO *excep_info,
2955 UINT *arg_err )
2957 struct security *security = impl_from_ISWbemSecurity( iface );
2958 ITypeInfo *typeinfo;
2959 HRESULT hr;
2961 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", security, member, debugstr_guid(riid),
2962 lcid, flags, params, result, excep_info, arg_err );
2964 hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo );
2965 if (SUCCEEDED(hr))
2967 hr = ITypeInfo_Invoke( typeinfo, &security->ISWbemSecurity_iface, member, flags,
2968 params, result, excep_info, arg_err );
2969 ITypeInfo_Release( typeinfo );
2971 return hr;
2974 static HRESULT WINAPI security_get_ImpersonationLevel(
2975 ISWbemSecurity *iface,
2976 WbemImpersonationLevelEnum *impersonation_level )
2978 struct security *security = impl_from_ISWbemSecurity( iface );
2979 FIXME( "%p, %p: stub\n", security, impersonation_level );
2981 if (!impersonation_level)
2982 return E_INVALIDARG;
2984 *impersonation_level = security->implevel;
2985 return S_OK;
2988 static HRESULT WINAPI security_put_ImpersonationLevel(
2989 ISWbemSecurity *iface,
2990 WbemImpersonationLevelEnum impersonation_level )
2992 struct security *security = impl_from_ISWbemSecurity( iface );
2993 FIXME( "%p, %d: stub\n", security, impersonation_level );
2995 security->implevel = impersonation_level;
2996 return S_OK;
2999 static HRESULT WINAPI security_get_AuthenticationLevel(
3000 ISWbemSecurity *iface,
3001 WbemAuthenticationLevelEnum *authentication_level )
3003 struct security *security = impl_from_ISWbemSecurity( iface );
3004 FIXME( "%p, %p: stub\n", security, authentication_level );
3006 if (!authentication_level)
3007 return E_INVALIDARG;
3009 *authentication_level = security->authlevel;
3010 return S_OK;
3013 static HRESULT WINAPI security_put_AuthenticationLevel(
3014 ISWbemSecurity *iface,
3015 WbemAuthenticationLevelEnum authentication_level )
3017 struct security *security = impl_from_ISWbemSecurity( iface );
3018 FIXME( "%p, %d: stub\n", security, authentication_level );
3020 security->authlevel = authentication_level;
3021 return S_OK;
3024 static HRESULT WINAPI security_get_Privileges(
3025 ISWbemSecurity *iface,
3026 ISWbemPrivilegeSet **privilege_set )
3028 struct security *security = impl_from_ISWbemSecurity( iface );
3029 FIXME( "%p, %p: stub\n", security, privilege_set );
3031 if (!privilege_set)
3032 return E_INVALIDARG;
3034 return E_NOTIMPL;
3037 static const ISWbemSecurityVtbl security_vtbl =
3039 security_QueryInterface,
3040 security_AddRef,
3041 security_Release,
3042 security_GetTypeInfoCount,
3043 security_GetTypeInfo,
3044 security_GetIDsOfNames,
3045 security_Invoke,
3046 security_get_ImpersonationLevel,
3047 security_put_ImpersonationLevel,
3048 security_get_AuthenticationLevel,
3049 security_put_AuthenticationLevel,
3050 security_get_Privileges
3053 static HRESULT ISWbemSecurity_create( ISWbemSecurity **obj )
3055 struct security *security;
3057 TRACE( "%p\n", obj );
3059 if (!(security = heap_alloc( sizeof(*security) ))) return E_OUTOFMEMORY;
3060 security->ISWbemSecurity_iface.lpVtbl = &security_vtbl;
3061 security->refs = 1;
3062 security->implevel = wbemImpersonationLevelImpersonate;
3063 security->authlevel = wbemAuthenticationLevelPktPrivacy;
3065 *obj = &security->ISWbemSecurity_iface;
3066 TRACE( "returning iface %p\n", *obj );
3067 return S_OK;
3070 struct namedvalue
3072 ISWbemNamedValue ISWbemNamedValue_iface;
3073 LONG refs;
3076 static struct namedvalueset *impl_from_ISWbemNamedValueSet( ISWbemNamedValueSet *iface )
3078 return CONTAINING_RECORD( iface, struct namedvalueset, ISWbemNamedValueSet_iface );
3081 static struct namedvalue *impl_from_ISWbemNamedValue( ISWbemNamedValue *iface )
3083 return CONTAINING_RECORD( iface, struct namedvalue, ISWbemNamedValue_iface );
3086 static HRESULT WINAPI namedvalue_QueryInterface(
3087 ISWbemNamedValue *iface,
3088 REFIID riid,
3089 void **ppvObject )
3091 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3093 TRACE( "%p, %s, %p\n", value, debugstr_guid( riid ), ppvObject );
3095 if (IsEqualGUID( riid, &IID_ISWbemNamedValue ) ||
3096 IsEqualGUID( riid, &IID_IDispatch ) ||
3097 IsEqualGUID( riid, &IID_IUnknown ))
3099 *ppvObject = iface;
3101 else
3103 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
3104 return E_NOINTERFACE;
3106 ISWbemNamedValue_AddRef( iface );
3107 return S_OK;
3110 static ULONG WINAPI namedvalue_AddRef(
3111 ISWbemNamedValue *iface )
3113 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3114 return InterlockedIncrement( &value->refs );
3117 static ULONG WINAPI namedvalue_Release(
3118 ISWbemNamedValue *iface )
3120 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3121 LONG refs = InterlockedDecrement( &value->refs );
3122 if (!refs)
3124 TRACE( "destroying %p\n", value );
3125 heap_free( value );
3127 return refs;
3130 static HRESULT WINAPI namedvalue_GetTypeInfoCount(
3131 ISWbemNamedValue *iface,
3132 UINT *count )
3134 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3135 TRACE( "%p, %p\n", value, count );
3137 *count = 1;
3138 return S_OK;
3141 static HRESULT WINAPI namedvalue_GetTypeInfo(
3142 ISWbemNamedValue *iface,
3143 UINT index,
3144 LCID lcid,
3145 ITypeInfo **info )
3147 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3149 TRACE( "%p, %u, %u, %p\n", value, index, lcid, info );
3151 return get_typeinfo( ISWbemNamedValue_tid, info );
3154 static HRESULT WINAPI namedvalue_GetIDsOfNames(
3155 ISWbemNamedValue *iface,
3156 REFIID riid,
3157 LPOLESTR *names,
3158 UINT count,
3159 LCID lcid,
3160 DISPID *dispid )
3162 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3163 ITypeInfo *typeinfo;
3164 HRESULT hr;
3166 TRACE( "%p, %s, %p, %u, %u, %p\n", value, debugstr_guid(riid), names, count, lcid, dispid );
3168 if (!names || !count || !dispid) return E_INVALIDARG;
3170 hr = get_typeinfo( ISWbemNamedValue_tid, &typeinfo );
3171 if (SUCCEEDED(hr))
3173 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
3174 ITypeInfo_Release( typeinfo );
3176 return hr;
3179 static HRESULT WINAPI namedvalue_Invoke(
3180 ISWbemNamedValue *iface,
3181 DISPID member,
3182 REFIID riid,
3183 LCID lcid,
3184 WORD flags,
3185 DISPPARAMS *params,
3186 VARIANT *result,
3187 EXCEPINFO *excep_info,
3188 UINT *arg_err )
3190 struct namedvalue *set = impl_from_ISWbemNamedValue( iface );
3191 ITypeInfo *typeinfo;
3192 HRESULT hr;
3194 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
3195 lcid, flags, params, result, excep_info, arg_err );
3197 hr = get_typeinfo( ISWbemNamedValue_tid, &typeinfo );
3198 if (SUCCEEDED(hr))
3200 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemNamedValue_iface, member, flags,
3201 params, result, excep_info, arg_err );
3202 ITypeInfo_Release( typeinfo );
3204 return hr;
3207 static HRESULT WINAPI namedvalue_get_Value(
3208 ISWbemNamedValue *iface,
3209 VARIANT *var )
3211 FIXME("\n");
3213 return E_NOTIMPL;
3216 static HRESULT WINAPI namedvalue_put_Value(
3217 ISWbemNamedValue *iface,
3218 VARIANT *var )
3220 FIXME("\n");
3222 return E_NOTIMPL;
3225 static HRESULT WINAPI namedvalue_get_Name(
3226 ISWbemNamedValue *iface,
3227 BSTR *name )
3229 FIXME("\n");
3231 return E_NOTIMPL;
3234 static const ISWbemNamedValueVtbl namedvaluevtbl =
3236 namedvalue_QueryInterface,
3237 namedvalue_AddRef,
3238 namedvalue_Release,
3239 namedvalue_GetTypeInfoCount,
3240 namedvalue_GetTypeInfo,
3241 namedvalue_GetIDsOfNames,
3242 namedvalue_Invoke,
3243 namedvalue_get_Value,
3244 namedvalue_put_Value,
3245 namedvalue_get_Name
3248 static HRESULT namedvalue_create( ISWbemNamedValue **value )
3250 struct namedvalue *object;
3252 if (!(object = heap_alloc(sizeof(*object))))
3253 return E_OUTOFMEMORY;
3255 object->ISWbemNamedValue_iface.lpVtbl = &namedvaluevtbl;
3256 object->refs = 1;
3258 *value = &object->ISWbemNamedValue_iface;
3260 return S_OK;
3263 static HRESULT WINAPI namedvalueset_QueryInterface(
3264 ISWbemNamedValueSet *iface,
3265 REFIID riid,
3266 void **ppvObject )
3268 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3270 TRACE( "%p, %s, %p\n", set, debugstr_guid( riid ), ppvObject );
3272 if (IsEqualGUID( riid, &IID_ISWbemNamedValueSet ) ||
3273 IsEqualGUID( riid, &IID_IDispatch ) ||
3274 IsEqualGUID( riid, &IID_IUnknown ))
3276 *ppvObject = iface;
3278 else
3280 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
3281 return E_NOINTERFACE;
3283 ISWbemNamedValueSet_AddRef( iface );
3284 return S_OK;
3287 static ULONG WINAPI namedvalueset_AddRef(
3288 ISWbemNamedValueSet *iface )
3290 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3291 return InterlockedIncrement( &set->refs );
3294 static ULONG WINAPI namedvalueset_Release(
3295 ISWbemNamedValueSet *iface )
3297 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3298 LONG refs = InterlockedDecrement( &set->refs );
3299 if (!refs)
3301 TRACE( "destroying %p\n", set );
3302 if (set->context)
3303 IWbemContext_Release( set->context );
3304 heap_free( set );
3306 return refs;
3309 static HRESULT WINAPI namedvalueset_GetTypeInfoCount(
3310 ISWbemNamedValueSet *iface,
3311 UINT *count )
3313 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3314 TRACE( "%p, %p\n", set, count );
3316 *count = 1;
3317 return S_OK;
3320 static HRESULT WINAPI namedvalueset_GetTypeInfo(
3321 ISWbemNamedValueSet *iface,
3322 UINT index,
3323 LCID lcid,
3324 ITypeInfo **info )
3326 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3328 TRACE( "%p, %u, %u, %p\n", set, index, lcid, info );
3330 return get_typeinfo( ISWbemNamedValueSet_tid, info );
3333 static HRESULT WINAPI namedvalueset_GetIDsOfNames(
3334 ISWbemNamedValueSet *iface,
3335 REFIID riid,
3336 LPOLESTR *names,
3337 UINT count,
3338 LCID lcid,
3339 DISPID *dispid )
3341 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3342 ITypeInfo *typeinfo;
3343 HRESULT hr;
3345 TRACE( "%p, %s, %p, %u, %u, %p\n", set, debugstr_guid(riid), names, count, lcid, dispid );
3347 if (!names || !count || !dispid) return E_INVALIDARG;
3349 hr = get_typeinfo( ISWbemNamedValueSet_tid, &typeinfo );
3350 if (SUCCEEDED(hr))
3352 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
3353 ITypeInfo_Release( typeinfo );
3355 return hr;
3358 static HRESULT WINAPI namedvalueset_Invoke(
3359 ISWbemNamedValueSet *iface,
3360 DISPID member,
3361 REFIID riid,
3362 LCID lcid,
3363 WORD flags,
3364 DISPPARAMS *params,
3365 VARIANT *result,
3366 EXCEPINFO *excep_info,
3367 UINT *arg_err )
3369 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3370 ITypeInfo *typeinfo;
3371 HRESULT hr;
3373 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
3374 lcid, flags, params, result, excep_info, arg_err );
3376 hr = get_typeinfo( ISWbemNamedValueSet_tid, &typeinfo );
3377 if (SUCCEEDED(hr))
3379 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemNamedValueSet_iface, member, flags,
3380 params, result, excep_info, arg_err );
3381 ITypeInfo_Release( typeinfo );
3383 return hr;
3386 static HRESULT WINAPI namedvalueset_get__NewEnum(
3387 ISWbemNamedValueSet *iface,
3388 IUnknown **unk )
3390 FIXME("\n");
3392 return E_NOTIMPL;
3395 static HRESULT WINAPI namedvalueset_Item(
3396 ISWbemNamedValueSet *iface,
3397 BSTR name,
3398 LONG flags,
3399 ISWbemNamedValue **value )
3401 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3402 VARIANT var;
3403 HRESULT hr;
3405 TRACE("%p, %s, %#x, %p\n", set, debugstr_w(name), flags, value);
3407 if (SUCCEEDED(hr = IWbemContext_GetValue( set->context, name, flags, &var )))
3409 VariantClear( &var );
3410 hr = namedvalue_create( value );
3413 return hr;
3416 static HRESULT WINAPI namedvalueset_get_Count(
3417 ISWbemNamedValueSet *iface,
3418 LONG *count )
3420 FIXME("\n");
3422 return E_NOTIMPL;
3425 static HRESULT WINAPI namedvalueset_Add(
3426 ISWbemNamedValueSet *iface,
3427 BSTR name,
3428 VARIANT *var,
3429 LONG flags,
3430 ISWbemNamedValue **value )
3432 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3433 HRESULT hr;
3435 TRACE("%p, %s, %s, %#x, %p\n", set, debugstr_w(name), debugstr_variant(var), flags, value);
3437 if (!name || !var || !value)
3438 return WBEM_E_INVALID_PARAMETER;
3440 if (SUCCEEDED(hr = IWbemContext_SetValue( set->context, name, flags, var )))
3442 hr = namedvalue_create( value );
3445 return hr;
3448 static HRESULT WINAPI namedvalueset_Remove(
3449 ISWbemNamedValueSet *iface,
3450 BSTR name,
3451 LONG flags )
3453 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3455 TRACE("%p, %s, %#x\n", set, debugstr_w(name), flags);
3457 return IWbemContext_DeleteValue( set->context, name, flags );
3460 static HRESULT WINAPI namedvalueset_Clone(
3461 ISWbemNamedValueSet *iface,
3462 ISWbemNamedValueSet **valueset )
3464 FIXME("\n");
3466 return E_NOTIMPL;
3469 static HRESULT WINAPI namedvalueset_DeleteAll(
3470 ISWbemNamedValueSet *iface )
3472 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3474 TRACE("%p\n", set);
3476 return IWbemContext_DeleteAll( set->context );
3479 static const ISWbemNamedValueSetVtbl namedvalueset_vtbl =
3481 namedvalueset_QueryInterface,
3482 namedvalueset_AddRef,
3483 namedvalueset_Release,
3484 namedvalueset_GetTypeInfoCount,
3485 namedvalueset_GetTypeInfo,
3486 namedvalueset_GetIDsOfNames,
3487 namedvalueset_Invoke,
3488 namedvalueset_get__NewEnum,
3489 namedvalueset_Item,
3490 namedvalueset_get_Count,
3491 namedvalueset_Add,
3492 namedvalueset_Remove,
3493 namedvalueset_Clone,
3494 namedvalueset_DeleteAll,
3497 static struct namedvalueset *unsafe_valueset_impl_from_IDispatch(IDispatch *iface)
3499 if (!iface)
3500 return NULL;
3501 if (iface->lpVtbl != (IDispatchVtbl *)&namedvalueset_vtbl)
3503 FIXME( "External implementations are not supported.\n" );
3504 return NULL;
3506 return CONTAINING_RECORD(iface, struct namedvalueset, ISWbemNamedValueSet_iface);
3509 HRESULT SWbemNamedValueSet_create( void **obj )
3511 struct namedvalueset *set;
3512 HRESULT hr;
3514 TRACE( "%p\n", obj );
3516 if (!(set = heap_alloc_zero( sizeof(*set) ))) return E_OUTOFMEMORY;
3517 set->ISWbemNamedValueSet_iface.lpVtbl = &namedvalueset_vtbl;
3518 set->refs = 1;
3520 if (FAILED(hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext,
3521 (void **)&set->context )))
3523 ISWbemNamedValueSet_Release( &set->ISWbemNamedValueSet_iface );
3524 return hr;
3527 *obj = &set->ISWbemNamedValueSet_iface;
3528 TRACE( "returning iface %p\n", *obj );
3529 return hr;