vbscript: Handle index read access to array properties.
[wine.git] / dlls / wbemdisp / locator.c
blob6880a503e1de6f2c0ffa4145429525b7c5186b13
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 "wbemdisp_private.h"
33 #include "wbemdisp_classes.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp);
37 struct namedvalueset
39 ISWbemNamedValueSet ISWbemNamedValueSet_iface;
40 LONG refs;
42 IWbemContext *context;
45 static struct namedvalueset *unsafe_valueset_impl_from_IDispatch(IDispatch *iface);
47 static IWbemContext * unsafe_get_context_from_namedvalueset( IDispatch *disp )
49 struct namedvalueset *valueset = unsafe_valueset_impl_from_IDispatch( disp );
50 return valueset ? valueset->context : NULL;
53 struct services;
55 static HRESULT EnumVARIANT_create( struct services *, IEnumWbemClassObject *, IEnumVARIANT ** );
56 static HRESULT ISWbemSecurity_create( ISWbemSecurity ** );
57 static HRESULT SWbemObject_create( struct services *, IWbemClassObject *, ISWbemObject ** );
59 enum type_id
61 ISWbemLocator_tid,
62 ISWbemObject_tid,
63 ISWbemObjectSet_tid,
64 ISWbemProperty_tid,
65 ISWbemPropertySet_tid,
66 ISWbemServices_tid,
67 ISWbemSecurity_tid,
68 ISWbemNamedValueSet_tid,
69 ISWbemNamedValue_tid,
70 ISWbemMethodSet_tid,
71 ISWbemMethod_tid,
72 last_tid
75 static ITypeLib *wbemdisp_typelib;
76 static ITypeInfo *wbemdisp_typeinfo[last_tid];
78 static REFIID wbemdisp_tid_id[] =
80 &IID_ISWbemLocator,
81 &IID_ISWbemObject,
82 &IID_ISWbemObjectSet,
83 &IID_ISWbemProperty,
84 &IID_ISWbemPropertySet,
85 &IID_ISWbemServices,
86 &IID_ISWbemSecurity,
87 &IID_ISWbemNamedValueSet,
88 &IID_ISWbemNamedValue,
89 &IID_ISWbemMethodSet,
90 &IID_ISWbemMethod,
93 static HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
95 HRESULT hr;
97 if (!wbemdisp_typelib)
99 ITypeLib *typelib;
101 hr = LoadRegTypeLib( &LIBID_WbemScripting, 1, 2, LOCALE_SYSTEM_DEFAULT, &typelib );
102 if (FAILED( hr ))
104 ERR( "LoadRegTypeLib failed: %#lx\n", hr );
105 return hr;
107 if (InterlockedCompareExchangePointer( (void **)&wbemdisp_typelib, typelib, NULL ))
108 ITypeLib_Release( typelib );
110 if (!wbemdisp_typeinfo[tid])
112 ITypeInfo *typeinfo;
114 hr = ITypeLib_GetTypeInfoOfGuid( wbemdisp_typelib, wbemdisp_tid_id[tid], &typeinfo );
115 if (FAILED( hr ))
117 ERR( "GetTypeInfoOfGuid(%s) failed: %#lx\n", debugstr_guid(wbemdisp_tid_id[tid]), hr );
118 return hr;
120 if (InterlockedCompareExchangePointer( (void **)(wbemdisp_typeinfo + tid), typeinfo, NULL ))
121 ITypeInfo_Release( typeinfo );
123 *ret = wbemdisp_typeinfo[tid];
124 ITypeInfo_AddRef( *ret );
125 return S_OK;
128 struct property
130 ISWbemProperty ISWbemProperty_iface;
131 LONG refs;
132 IWbemClassObject *object;
133 BSTR name;
136 static inline struct property *impl_from_ISWbemProperty( ISWbemProperty *iface )
138 return CONTAINING_RECORD( iface, struct property, ISWbemProperty_iface );
141 static ULONG WINAPI property_AddRef( ISWbemProperty *iface )
143 struct property *property = impl_from_ISWbemProperty( iface );
144 return InterlockedIncrement( &property->refs );
147 static ULONG WINAPI property_Release( ISWbemProperty *iface )
149 struct property *property = impl_from_ISWbemProperty( iface );
150 LONG refs = InterlockedDecrement( &property->refs );
151 if (!refs)
153 TRACE( "destroying %p\n", property );
154 IWbemClassObject_Release( property->object );
155 SysFreeString( property->name );
156 free( property );
158 return refs;
161 static HRESULT WINAPI property_QueryInterface( ISWbemProperty *iface, REFIID riid, void **obj )
163 struct property *property = impl_from_ISWbemProperty( iface );
165 TRACE( "%p %s %p\n", property, debugstr_guid(riid), obj );
167 if (IsEqualGUID( riid, &IID_ISWbemProperty ) ||
168 IsEqualGUID( riid, &IID_IDispatch ) ||
169 IsEqualGUID( riid, &IID_IUnknown ))
171 *obj = iface;
173 else
175 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
176 return E_NOINTERFACE;
178 ISWbemProperty_AddRef( iface );
179 return S_OK;
182 static HRESULT WINAPI property_GetTypeInfoCount( ISWbemProperty *iface, UINT *count )
184 struct property *property = impl_from_ISWbemProperty( iface );
185 TRACE( "%p, %p\n", property, count );
186 *count = 1;
187 return S_OK;
190 static HRESULT WINAPI property_GetTypeInfo( ISWbemProperty *iface, UINT index,
191 LCID lcid, ITypeInfo **info )
193 struct property *property = impl_from_ISWbemProperty( iface );
194 TRACE( "%p, %u, %#lx, %p\n", property, index, lcid, info );
196 return get_typeinfo( ISWbemProperty_tid, info );
199 static HRESULT WINAPI property_GetIDsOfNames( ISWbemProperty *iface, REFIID riid, LPOLESTR *names,
200 UINT count, LCID lcid, DISPID *dispid )
202 struct property *property = impl_from_ISWbemProperty( iface );
203 ITypeInfo *typeinfo;
204 HRESULT hr;
206 TRACE( "%p, %s, %p, %u, %#lx, %p\n", property, debugstr_guid(riid), names, count, lcid, dispid );
208 if (!names || !count || !dispid) return E_INVALIDARG;
210 hr = get_typeinfo( ISWbemProperty_tid, &typeinfo );
211 if (SUCCEEDED(hr))
213 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
214 ITypeInfo_Release( typeinfo );
216 return hr;
219 static HRESULT WINAPI property_Invoke( ISWbemProperty *iface, DISPID member, REFIID riid,
220 LCID lcid, WORD flags, DISPPARAMS *params,
221 VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
223 struct property *property = impl_from_ISWbemProperty( iface );
224 ITypeInfo *typeinfo;
225 HRESULT hr;
227 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", property, member, debugstr_guid(riid),
228 lcid, flags, params, result, excep_info, arg_err );
230 hr = get_typeinfo( ISWbemProperty_tid, &typeinfo );
231 if (SUCCEEDED(hr))
233 hr = ITypeInfo_Invoke( typeinfo, &property->ISWbemProperty_iface, member, flags,
234 params, result, excep_info, arg_err );
235 ITypeInfo_Release( typeinfo );
237 return hr;
240 static HRESULT WINAPI property_get_Value( ISWbemProperty *iface, VARIANT *value )
242 struct property *property = impl_from_ISWbemProperty( iface );
244 TRACE( "%p %p\n", property, value );
246 return IWbemClassObject_Get( property->object, property->name, 0, value, NULL, NULL );
249 static HRESULT WINAPI property_put_Value( ISWbemProperty *iface, VARIANT *varValue )
251 FIXME( "\n" );
252 return E_NOTIMPL;
255 static HRESULT WINAPI property_get_Name( ISWbemProperty *iface, BSTR *strName )
257 FIXME( "\n" );
258 return E_NOTIMPL;
261 static HRESULT WINAPI property_get_IsLocal( ISWbemProperty *iface, VARIANT_BOOL *bIsLocal )
263 FIXME( "\n" );
264 return E_NOTIMPL;
267 static HRESULT WINAPI property_get_Origin( ISWbemProperty *iface, BSTR *strOrigin )
269 FIXME( "\n" );
270 return E_NOTIMPL;
273 static HRESULT WINAPI property_get_CIMType( ISWbemProperty *iface, WbemCimtypeEnum *iCimType )
275 FIXME( "\n" );
276 return E_NOTIMPL;
279 static HRESULT WINAPI property_get_Qualifiers_( ISWbemProperty *iface, ISWbemQualifierSet **objWbemQualifierSet )
281 FIXME( "\n" );
282 return E_NOTIMPL;
285 static HRESULT WINAPI property_get_IsArray( ISWbemProperty *iface, VARIANT_BOOL *bIsArray )
287 FIXME( "\n" );
288 return E_NOTIMPL;
291 static const ISWbemPropertyVtbl property_vtbl =
293 property_QueryInterface,
294 property_AddRef,
295 property_Release,
296 property_GetTypeInfoCount,
297 property_GetTypeInfo,
298 property_GetIDsOfNames,
299 property_Invoke,
300 property_get_Value,
301 property_put_Value,
302 property_get_Name,
303 property_get_IsLocal,
304 property_get_Origin,
305 property_get_CIMType,
306 property_get_Qualifiers_,
307 property_get_IsArray
310 static HRESULT SWbemProperty_create( IWbemClassObject *wbem_object, BSTR name, ISWbemProperty **obj )
312 struct property *property;
314 TRACE( "%p, %p\n", obj, wbem_object );
316 if (!(property = malloc( sizeof(*property) ))) return E_OUTOFMEMORY;
317 property->ISWbemProperty_iface.lpVtbl = &property_vtbl;
318 property->refs = 1;
319 property->object = wbem_object;
320 IWbemClassObject_AddRef( property->object );
321 property->name = SysAllocStringLen( name, SysStringLen( name ) );
322 *obj = &property->ISWbemProperty_iface;
323 TRACE( "returning iface %p\n", *obj );
324 return S_OK;
327 struct propertyset
329 ISWbemPropertySet ISWbemPropertySet_iface;
330 LONG refs;
331 IWbemClassObject *object;
334 static inline struct propertyset *impl_from_ISWbemPropertySet(
335 ISWbemPropertySet *iface )
337 return CONTAINING_RECORD( iface, struct propertyset, ISWbemPropertySet_iface );
340 static ULONG WINAPI propertyset_AddRef( ISWbemPropertySet *iface )
342 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
343 return InterlockedIncrement( &propertyset->refs );
346 static ULONG WINAPI propertyset_Release( ISWbemPropertySet *iface )
348 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
349 LONG refs = InterlockedDecrement( &propertyset->refs );
350 if (!refs)
352 TRACE( "destroying %p\n", propertyset );
353 IWbemClassObject_Release( propertyset->object );
354 free( propertyset );
356 return refs;
359 static HRESULT WINAPI propertyset_QueryInterface( ISWbemPropertySet *iface,
360 REFIID riid, void **obj )
362 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
364 TRACE( "%p %s %p\n", propertyset, debugstr_guid(riid), obj );
366 if (IsEqualGUID( riid, &IID_ISWbemPropertySet ) ||
367 IsEqualGUID( riid, &IID_IDispatch ) ||
368 IsEqualGUID( riid, &IID_IUnknown ))
370 *obj = iface;
372 else
374 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
375 return E_NOINTERFACE;
377 ISWbemPropertySet_AddRef( iface );
378 return S_OK;
381 static HRESULT WINAPI propertyset_GetTypeInfoCount( ISWbemPropertySet *iface, UINT *count )
383 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
384 TRACE( "%p, %p\n", propertyset, count );
385 *count = 1;
386 return S_OK;
389 static HRESULT WINAPI propertyset_GetTypeInfo( ISWbemPropertySet *iface,
390 UINT index, LCID lcid, ITypeInfo **info )
392 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
393 TRACE( "%p, %u, %#lx, %p\n", propertyset, index, lcid, info );
395 return get_typeinfo( ISWbemPropertySet_tid, info );
398 static HRESULT WINAPI propertyset_GetIDsOfNames( ISWbemPropertySet *iface, REFIID riid, LPOLESTR *names,
399 UINT count, LCID lcid, DISPID *dispid )
401 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
402 ITypeInfo *typeinfo;
403 HRESULT hr;
405 TRACE( "%p, %s, %p, %u, %#lx, %p\n", propertyset, debugstr_guid(riid), names, count, lcid, dispid );
407 if (!names || !count || !dispid) return E_INVALIDARG;
409 hr = get_typeinfo( ISWbemPropertySet_tid, &typeinfo );
410 if (SUCCEEDED(hr))
412 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
413 ITypeInfo_Release( typeinfo );
415 return hr;
418 static HRESULT WINAPI propertyset_Invoke( ISWbemPropertySet *iface, DISPID member, REFIID riid,
419 LCID lcid, WORD flags, DISPPARAMS *params,
420 VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
422 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
423 ITypeInfo *typeinfo;
424 HRESULT hr;
426 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", propertyset, member, debugstr_guid(riid),
427 lcid, flags, params, result, excep_info, arg_err );
429 hr = get_typeinfo( ISWbemPropertySet_tid, &typeinfo );
430 if (SUCCEEDED(hr))
432 hr = ITypeInfo_Invoke( typeinfo, &propertyset->ISWbemPropertySet_iface, member, flags,
433 params, result, excep_info, arg_err );
434 ITypeInfo_Release( typeinfo );
436 return hr;
439 static HRESULT WINAPI propertyset_get__NewEnum( ISWbemPropertySet *iface, IUnknown **unk )
441 FIXME( "\n" );
442 return E_NOTIMPL;
445 static HRESULT WINAPI propertyset_Item( ISWbemPropertySet *iface, BSTR name,
446 LONG flags, ISWbemProperty **prop )
448 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
449 HRESULT hr;
450 VARIANT var;
452 TRACE( "%p, %s, %#lx, %p\n", propertyset, debugstr_w(name), flags, prop );
454 hr = IWbemClassObject_Get( propertyset->object, name, 0, &var, NULL, NULL );
455 if (SUCCEEDED(hr))
457 hr = SWbemProperty_create( propertyset->object, name, prop );
458 VariantClear( &var );
460 return hr;
463 static HRESULT WINAPI propertyset_get_Count( ISWbemPropertySet *iface, LONG *count )
465 struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
466 HRESULT hr;
467 VARIANT val;
469 TRACE( "%p, %p\n", propertyset, count );
471 hr = IWbemClassObject_Get( propertyset->object, L"__PROPERTY_COUNT", 0, &val, NULL, NULL );
472 if (SUCCEEDED(hr))
474 *count = V_I4( &val );
476 return hr;
479 static HRESULT WINAPI propertyset_Add( ISWbemPropertySet *iface, BSTR name, WbemCimtypeEnum type,
480 VARIANT_BOOL is_array, LONG flags, ISWbemProperty **prop )
482 FIXME( "\n" );
483 return E_NOTIMPL;
486 static HRESULT WINAPI propertyset_Remove( ISWbemPropertySet *iface, BSTR name, LONG flags )
488 FIXME( "\n" );
489 return E_NOTIMPL;
492 static const ISWbemPropertySetVtbl propertyset_vtbl =
494 propertyset_QueryInterface,
495 propertyset_AddRef,
496 propertyset_Release,
497 propertyset_GetTypeInfoCount,
498 propertyset_GetTypeInfo,
499 propertyset_GetIDsOfNames,
500 propertyset_Invoke,
501 propertyset_get__NewEnum,
502 propertyset_Item,
503 propertyset_get_Count,
504 propertyset_Add,
505 propertyset_Remove
508 static HRESULT SWbemPropertySet_create( IWbemClassObject *wbem_object, ISWbemPropertySet **obj )
510 struct propertyset *propertyset;
512 TRACE( "%p, %p\n", obj, wbem_object );
514 if (!(propertyset = malloc( sizeof(*propertyset) ))) return E_OUTOFMEMORY;
515 propertyset->ISWbemPropertySet_iface.lpVtbl = &propertyset_vtbl;
516 propertyset->refs = 1;
517 propertyset->object = wbem_object;
518 IWbemClassObject_AddRef( propertyset->object );
519 *obj = &propertyset->ISWbemPropertySet_iface;
521 TRACE( "returning iface %p\n", *obj );
522 return S_OK;
525 struct services
527 ISWbemServices ISWbemServices_iface;
528 LONG refs;
529 IWbemServices *services;
532 struct member
534 BSTR name;
535 BOOL is_method;
536 DISPID dispid;
537 CIMTYPE type;
540 struct object
542 ISWbemObject ISWbemObject_iface;
543 LONG refs;
544 IWbemClassObject *object;
545 struct member *members;
546 UINT nb_members;
547 DISPID last_dispid;
548 DISPID last_dispid_method;
549 struct services *services;
552 struct methodset
554 ISWbemMethodSet ISWbemMethodSet_iface;
555 LONG refs;
556 struct object *object;
559 struct method
561 ISWbemMethod ISWbemMethod_iface;
562 LONG refs;
563 struct methodset *set;
564 WCHAR *name;
567 static struct method *impl_from_ISWbemMethod( ISWbemMethod *iface )
569 return CONTAINING_RECORD( iface, struct method, ISWbemMethod_iface );
572 static HRESULT WINAPI method_QueryInterface( ISWbemMethod *iface, REFIID riid, void **ppvObject )
574 struct method *method = impl_from_ISWbemMethod( iface );
576 TRACE( "%p %s %p\n", method, debugstr_guid(riid), ppvObject );
578 if (IsEqualGUID( riid, &IID_ISWbemMethod ) ||
579 IsEqualGUID( riid, &IID_IDispatch ) ||
580 IsEqualGUID( riid, &IID_IUnknown ))
582 *ppvObject = iface;
584 else
586 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
587 return E_NOINTERFACE;
589 ISWbemMethod_AddRef( iface );
590 return S_OK;
593 static ULONG WINAPI method_AddRef( ISWbemMethod *iface )
595 struct method *method = impl_from_ISWbemMethod( iface );
596 return InterlockedIncrement( &method->refs );
599 static ULONG WINAPI method_Release( ISWbemMethod *iface )
601 struct method *method = impl_from_ISWbemMethod( iface );
602 LONG refs = InterlockedDecrement( &method->refs );
603 if (!refs)
605 TRACE( "destroying %p\n", method );
606 ISWbemMethodSet_Release( &method->set->ISWbemMethodSet_iface );
607 free( method->name );
608 free( method );
610 return refs;
613 static HRESULT WINAPI method_GetTypeInfoCount(
614 ISWbemMethod *iface,
615 UINT *count )
617 struct method *method = impl_from_ISWbemMethod( iface );
619 TRACE( "%p, %p\n", method, count );
620 *count = 1;
621 return S_OK;
624 static HRESULT WINAPI method_GetTypeInfo(
625 ISWbemMethod *iface,
626 UINT index,
627 LCID lcid,
628 ITypeInfo **info )
630 struct method *method = impl_from_ISWbemMethod( iface );
632 TRACE( "%p, %u, %#lx, %p\n", method, index, lcid, info );
634 return get_typeinfo( ISWbemMethod_tid, info );
637 static HRESULT WINAPI method_GetIDsOfNames(
638 ISWbemMethod *iface,
639 REFIID riid,
640 LPOLESTR *names,
641 UINT count,
642 LCID lcid,
643 DISPID *dispid )
645 struct method *method = impl_from_ISWbemMethod( iface );
646 ITypeInfo *typeinfo;
647 HRESULT hr;
649 TRACE( "%p, %s, %p, %u, %#lx, %p\n", method, debugstr_guid(riid), names, count, lcid, dispid );
651 if (!names || !count || !dispid) return E_INVALIDARG;
653 hr = get_typeinfo( ISWbemMethod_tid, &typeinfo );
654 if (SUCCEEDED(hr))
656 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
657 ITypeInfo_Release( typeinfo );
659 return hr;
662 static HRESULT WINAPI method_Invoke(
663 ISWbemMethod *iface,
664 DISPID member,
665 REFIID riid,
666 LCID lcid,
667 WORD flags,
668 DISPPARAMS *params,
669 VARIANT *result,
670 EXCEPINFO *excep_info,
671 UINT *arg_err )
673 struct method *method = impl_from_ISWbemMethod( iface );
674 ITypeInfo *typeinfo;
675 HRESULT hr;
677 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", method, member, debugstr_guid(riid),
678 lcid, flags, params, result, excep_info, arg_err );
680 hr = get_typeinfo( ISWbemMethod_tid, &typeinfo );
681 if (SUCCEEDED(hr))
683 hr = ITypeInfo_Invoke( typeinfo, &method->ISWbemMethod_iface, member, flags,
684 params, result, excep_info, arg_err );
685 ITypeInfo_Release( typeinfo );
687 return hr;
690 static HRESULT WINAPI method_get_Name(
691 ISWbemMethod *iface,
692 BSTR *name )
694 FIXME("\n");
696 return E_NOTIMPL;
699 static HRESULT WINAPI method_get_Origin(
700 ISWbemMethod *iface,
701 BSTR *origin )
703 FIXME("\n");
705 return E_NOTIMPL;
708 static HRESULT WINAPI method_get_InParameters(
709 ISWbemMethod *iface,
710 ISWbemObject **params )
712 struct method *method = impl_from_ISWbemMethod( iface );
713 IWbemClassObject *in_sign = NULL, *instance;
714 HRESULT hr;
716 TRACE("%p, %p\n", method, params);
718 *params = NULL;
720 if (SUCCEEDED(hr = IWbemClassObject_GetMethod( method->set->object->object,
721 method->name, 0, &in_sign, NULL )) && in_sign != NULL)
723 hr = IWbemClassObject_SpawnInstance( in_sign, 0, &instance );
724 IWbemClassObject_Release( in_sign );
725 if (SUCCEEDED(hr))
727 hr = SWbemObject_create( method->set->object->services, instance, params );
728 IWbemClassObject_Release( instance );
732 return hr;
735 static HRESULT WINAPI method_get_OutParameters(
736 ISWbemMethod *iface,
737 ISWbemObject **params )
739 FIXME("\n");
741 return E_NOTIMPL;
744 static HRESULT WINAPI method_get_Qualifiers_(
745 ISWbemMethod *iface,
746 ISWbemQualifierSet **qualifiers )
748 FIXME("\n");
750 return E_NOTIMPL;
753 static const ISWbemMethodVtbl methodvtbl =
755 method_QueryInterface,
756 method_AddRef,
757 method_Release,
758 method_GetTypeInfoCount,
759 method_GetTypeInfo,
760 method_GetIDsOfNames,
761 method_Invoke,
762 method_get_Name,
763 method_get_Origin,
764 method_get_InParameters,
765 method_get_OutParameters,
766 method_get_Qualifiers_,
769 static HRESULT SWbemMethod_create( struct methodset *set, const WCHAR *name, ISWbemMethod **obj )
771 struct method *method;
773 if (!(method = malloc( sizeof(*method) ))) return E_OUTOFMEMORY;
775 method->ISWbemMethod_iface.lpVtbl = &methodvtbl;
776 method->refs = 1;
777 method->set = set;
778 ISWbemMethodSet_AddRef( &method->set->ISWbemMethodSet_iface );
779 if (!(method->name = wcsdup( name )))
781 ISWbemMethod_Release( &method->ISWbemMethod_iface );
782 return E_OUTOFMEMORY;
785 *obj = &method->ISWbemMethod_iface;
787 return S_OK;
790 static struct methodset *impl_from_ISWbemMethodSet( ISWbemMethodSet *iface )
792 return CONTAINING_RECORD( iface, struct methodset, ISWbemMethodSet_iface );
795 static HRESULT WINAPI methodset_QueryInterface( ISWbemMethodSet *iface, REFIID riid, void **ppvObject )
797 struct methodset *set = impl_from_ISWbemMethodSet( iface );
799 TRACE( "%p %s %p\n", set, debugstr_guid(riid), ppvObject );
801 if (IsEqualGUID( riid, &IID_ISWbemMethodSet ) ||
802 IsEqualGUID( riid, &IID_IDispatch ) ||
803 IsEqualGUID( riid, &IID_IUnknown ))
805 *ppvObject = iface;
807 else
809 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
810 return E_NOINTERFACE;
812 ISWbemMethodSet_AddRef( iface );
813 return S_OK;
816 static ULONG WINAPI methodset_AddRef( ISWbemMethodSet *iface )
818 struct methodset *set = impl_from_ISWbemMethodSet( iface );
819 return InterlockedIncrement( &set->refs );
822 static ULONG WINAPI methodset_Release( ISWbemMethodSet *iface )
824 struct methodset *set = impl_from_ISWbemMethodSet( iface );
825 LONG refs = InterlockedDecrement( &set->refs );
826 if (!refs)
828 TRACE( "destroying %p\n", set );
829 ISWbemObject_Release( &set->object->ISWbemObject_iface );
830 free( set );
832 return refs;
835 static HRESULT WINAPI methodset_GetTypeInfoCount(
836 ISWbemMethodSet *iface,
837 UINT *count )
839 struct methodset *set = impl_from_ISWbemMethodSet( iface );
841 TRACE( "%p, %p\n", set, count );
842 *count = 1;
843 return S_OK;
846 static HRESULT WINAPI methodset_GetTypeInfo( ISWbemMethodSet *iface,
847 UINT index,
848 LCID lcid,
849 ITypeInfo **info )
851 struct methodset *set = impl_from_ISWbemMethodSet( iface );
853 TRACE( "%p, %u, %#lx, %p\n", set, index, lcid, info );
855 return get_typeinfo( ISWbemMethodSet_tid, info );
858 static HRESULT WINAPI methodset_GetIDsOfNames(
859 ISWbemMethodSet *iface,
860 REFIID riid,
861 LPOLESTR *names,
862 UINT count,
863 LCID lcid,
864 DISPID *dispid )
866 struct methodset *set = impl_from_ISWbemMethodSet( iface );
867 ITypeInfo *typeinfo;
868 HRESULT hr;
870 TRACE( "%p, %s, %p, %u, %#lx, %p\n", set, debugstr_guid(riid), names, count, lcid, dispid );
872 if (!names || !count || !dispid) return E_INVALIDARG;
874 hr = get_typeinfo( ISWbemMethodSet_tid, &typeinfo );
875 if (SUCCEEDED(hr))
877 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
878 ITypeInfo_Release( typeinfo );
880 return hr;
883 static HRESULT WINAPI methodset_Invoke(
884 ISWbemMethodSet *iface,
885 DISPID member,
886 REFIID riid,
887 LCID lcid,
888 WORD flags,
889 DISPPARAMS *params,
890 VARIANT *result,
891 EXCEPINFO *excep_info,
892 UINT *arg_err )
894 struct methodset *set = impl_from_ISWbemMethodSet( iface );
895 ITypeInfo *typeinfo;
896 HRESULT hr;
898 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
899 lcid, flags, params, result, excep_info, arg_err );
901 hr = get_typeinfo( ISWbemMethodSet_tid, &typeinfo );
902 if (SUCCEEDED(hr))
904 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemMethodSet_iface, member, flags,
905 params, result, excep_info, arg_err );
906 ITypeInfo_Release( typeinfo );
908 return hr;
911 static HRESULT WINAPI methodset_get__NewEnum(
912 ISWbemMethodSet *iface,
913 IUnknown **unk )
915 FIXME("\n");
917 return E_NOTIMPL;
920 static HRESULT WINAPI methodset_Item(
921 ISWbemMethodSet *iface,
922 BSTR name,
923 LONG flags,
924 ISWbemMethod **method )
926 struct methodset *set = impl_from_ISWbemMethodSet( iface );
927 IWbemClassObject *in_sign, *out_sign;
928 HRESULT hr;
930 TRACE("%p, %s, %#lx, %p\n", set, debugstr_w(name), flags, method);
932 *method = NULL;
934 if (SUCCEEDED(hr = IWbemClassObject_GetMethod( set->object->object,
935 name, flags, &in_sign, &out_sign )))
937 if (in_sign)
938 IWbemClassObject_Release( in_sign );
939 if (out_sign)
940 IWbemClassObject_Release( out_sign );
942 return SWbemMethod_create( set, name, method );
945 return hr;
948 static HRESULT WINAPI methodset_get_Count(
949 ISWbemMethodSet *iface,
950 LONG *count )
952 FIXME("\n");
954 return E_NOTIMPL;
957 static const ISWbemMethodSetVtbl methodsetvtbl =
959 methodset_QueryInterface,
960 methodset_AddRef,
961 methodset_Release,
962 methodset_GetTypeInfoCount,
963 methodset_GetTypeInfo,
964 methodset_GetIDsOfNames,
965 methodset_Invoke,
966 methodset_get__NewEnum,
967 methodset_Item,
968 methodset_get_Count,
971 static HRESULT SWbemMethodSet_create( struct object *object, ISWbemMethodSet **obj )
973 struct methodset *set;
975 if (!(set = malloc( sizeof(*set) ))) return E_OUTOFMEMORY;
977 set->ISWbemMethodSet_iface.lpVtbl = &methodsetvtbl;
978 set->refs = 1;
979 set->object = object;
980 ISWbemObject_AddRef( &object->ISWbemObject_iface );
982 *obj = &set->ISWbemMethodSet_iface;
984 return S_OK;
987 #define DISPID_BASE 0x1800000
988 #define DISPID_BASE_METHOD 0x1000000
990 static inline struct object *impl_from_ISWbemObject(
991 ISWbemObject *iface )
993 return CONTAINING_RECORD( iface, struct object, ISWbemObject_iface );
996 static ULONG WINAPI object_AddRef(
997 ISWbemObject *iface )
999 struct object *object = impl_from_ISWbemObject( iface );
1000 return InterlockedIncrement( &object->refs );
1003 static ULONG WINAPI object_Release(
1004 ISWbemObject *iface )
1006 struct object *object = impl_from_ISWbemObject( iface );
1007 LONG refs = InterlockedDecrement( &object->refs );
1008 if (!refs)
1010 UINT i;
1012 TRACE( "destroying %p\n", object );
1013 IWbemClassObject_Release( object->object );
1014 ISWbemServices_Release( &object->services->ISWbemServices_iface );
1015 for (i = 0; i < object->nb_members; i++) SysFreeString( object->members[i].name );
1016 free( object->members );
1017 free( object );
1019 return refs;
1022 static HRESULT WINAPI object_QueryInterface(
1023 ISWbemObject *iface,
1024 REFIID riid,
1025 void **ppvObject )
1027 struct object *object = impl_from_ISWbemObject( iface );
1029 TRACE( "%p %s %p\n", object, debugstr_guid(riid), ppvObject );
1031 if (IsEqualGUID( riid, &IID_ISWbemObject ) ||
1032 IsEqualGUID( riid, &IID_IDispatch ) ||
1033 IsEqualGUID( riid, &IID_IUnknown ))
1035 *ppvObject = iface;
1037 else
1039 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
1040 return E_NOINTERFACE;
1042 ISWbemObject_AddRef( iface );
1043 return S_OK;
1046 static HRESULT WINAPI object_GetTypeInfoCount(
1047 ISWbemObject *iface,
1048 UINT *count )
1050 struct object *object = impl_from_ISWbemObject( iface );
1052 TRACE( "%p, %p\n", object, count );
1053 *count = 1;
1054 return S_OK;
1057 static HRESULT WINAPI object_GetTypeInfo(
1058 ISWbemObject *iface,
1059 UINT index,
1060 LCID lcid,
1061 ITypeInfo **info )
1063 struct object *object = impl_from_ISWbemObject( iface );
1064 FIXME( "%p, %u, %#lx, %p\n", object, index, lcid, info );
1065 return E_NOTIMPL;
1068 static BOOL object_reserve_member( struct object *object, unsigned int count, unsigned int *capacity )
1070 unsigned int new_capacity, max_capacity;
1071 struct member *new_members;
1073 if (count <= *capacity)
1074 return TRUE;
1076 max_capacity = ~0u / sizeof(*object->members);
1077 if (count > max_capacity)
1078 return FALSE;
1080 new_capacity = max(4, *capacity);
1081 while (new_capacity < count && new_capacity <= max_capacity / 2)
1082 new_capacity *= 2;
1083 if (new_capacity < count)
1084 new_capacity = max_capacity;
1086 if (!(new_members = realloc( object->members, new_capacity * sizeof(*new_members) )))
1087 return FALSE;
1089 object->members = new_members;
1090 *capacity = new_capacity;
1092 return TRUE;
1095 static HRESULT init_members( struct object *object )
1097 IWbemClassObject *sig_in, *sig_out;
1098 unsigned int i, capacity = 0, count = 0;
1099 CIMTYPE type;
1100 HRESULT hr;
1101 BSTR name;
1103 if (object->members) return S_OK;
1105 hr = IWbemClassObject_BeginEnumeration( object->object, 0 );
1106 if (SUCCEEDED( hr ))
1108 while (IWbemClassObject_Next( object->object, 0, &name, NULL, &type, NULL ) == S_OK)
1110 if (!object_reserve_member( object, count + 1, &capacity )) goto error;
1111 object->members[count].name = name;
1112 object->members[count].is_method = FALSE;
1113 object->members[count].dispid = 0;
1114 object->members[count].type = type;
1115 count++;
1116 TRACE( "added property %s\n", debugstr_w(name) );
1118 IWbemClassObject_EndEnumeration( object->object );
1121 hr = IWbemClassObject_BeginMethodEnumeration( object->object, 0 );
1122 if (SUCCEEDED( hr ))
1124 while (IWbemClassObject_NextMethod( object->object, 0, &name, &sig_in, &sig_out ) == S_OK)
1126 if (!object_reserve_member( object, count + 1, &capacity )) goto error;
1127 object->members[count].name = name;
1128 object->members[count].is_method = TRUE;
1129 object->members[count].dispid = 0;
1130 count++;
1131 if (sig_in) IWbemClassObject_Release( sig_in );
1132 if (sig_out) IWbemClassObject_Release( sig_out );
1133 TRACE( "added method %s\n", debugstr_w(name) );
1135 IWbemClassObject_EndMethodEnumeration( object->object );
1138 object->nb_members = count;
1139 TRACE( "added %u members\n", object->nb_members );
1140 return S_OK;
1142 error:
1143 for (i = 0; i < count; ++i)
1144 SysFreeString( object->members[i].name );
1145 free( object->members );
1146 object->members = NULL;
1147 object->nb_members = 0;
1148 return E_FAIL;
1151 static DISPID get_member_dispid( struct object *object, const WCHAR *name )
1153 UINT i;
1154 for (i = 0; i < object->nb_members; i++)
1156 if (!wcsicmp( object->members[i].name, name ))
1158 if (!object->members[i].dispid)
1160 if (object->members[i].is_method)
1161 object->members[i].dispid = ++object->last_dispid_method;
1162 else
1163 object->members[i].dispid = ++object->last_dispid;
1165 return object->members[i].dispid;
1168 return DISPID_UNKNOWN;
1171 static HRESULT WINAPI object_GetIDsOfNames(
1172 ISWbemObject *iface,
1173 REFIID riid,
1174 LPOLESTR *names,
1175 UINT count,
1176 LCID lcid,
1177 DISPID *dispid )
1179 struct object *object = impl_from_ISWbemObject( iface );
1180 HRESULT hr;
1181 UINT i;
1182 ITypeInfo *typeinfo;
1184 TRACE( "%p, %s, %p, %u, %#lx, %p\n", object, debugstr_guid(riid), names, count, lcid, dispid );
1186 if (!names || !count || !dispid) return E_INVALIDARG;
1188 hr = init_members( object );
1189 if (FAILED( hr )) return hr;
1191 hr = get_typeinfo( ISWbemObject_tid, &typeinfo );
1192 if (SUCCEEDED(hr))
1194 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
1195 ITypeInfo_Release( typeinfo );
1197 if (SUCCEEDED(hr)) return hr;
1199 for (i = 0; i < count; i++)
1201 if ((dispid[i] = get_member_dispid( object, names[i] )) == DISPID_UNKNOWN) break;
1203 if (i != count) return DISP_E_UNKNOWNNAME;
1204 return S_OK;
1207 static BSTR get_member_name( struct object *object, DISPID dispid, CIMTYPE *type )
1209 UINT i;
1210 for (i = 0; i < object->nb_members; i++)
1212 if (object->members[i].dispid == dispid)
1214 *type = object->members[i].type;
1215 return object->members[i].name;
1218 return NULL;
1221 static VARTYPE to_vartype( CIMTYPE type )
1223 switch (type)
1225 case CIM_BOOLEAN: return VT_BOOL;
1227 case CIM_STRING:
1228 case CIM_REFERENCE:
1229 case CIM_DATETIME: return VT_BSTR;
1231 case CIM_SINT8: return VT_I1;
1232 case CIM_UINT8: return VT_UI1;
1233 case CIM_SINT16: return VT_I2;
1235 case CIM_UINT16:
1236 case CIM_SINT32: return VT_I4;
1238 case CIM_UINT32: return VT_UI4;
1240 case CIM_SINT64: return VT_I8;
1241 case CIM_UINT64: return VT_UI8;
1243 case CIM_REAL32: return VT_R4;
1245 default:
1246 ERR( "unhandled type %lu\n", type );
1247 break;
1249 return 0;
1252 static HRESULT WINAPI object_Invoke(
1253 ISWbemObject *iface,
1254 DISPID member,
1255 REFIID riid,
1256 LCID lcid,
1257 WORD flags,
1258 DISPPARAMS *params,
1259 VARIANT *result,
1260 EXCEPINFO *excep_info,
1261 UINT *arg_err )
1263 struct object *object = impl_from_ISWbemObject( iface );
1264 BSTR name;
1265 ITypeInfo *typeinfo;
1266 VARTYPE vartype;
1267 VARIANT value;
1268 CIMTYPE type;
1269 HRESULT hr;
1271 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", object, member, debugstr_guid(riid),
1272 lcid, flags, params, result, excep_info, arg_err );
1274 if (member <= DISPID_BASE_METHOD)
1276 hr = get_typeinfo( ISWbemObject_tid, &typeinfo );
1277 if (SUCCEEDED(hr))
1279 hr = ITypeInfo_Invoke( typeinfo, &object->ISWbemObject_iface, member, flags,
1280 params, result, excep_info, arg_err );
1281 ITypeInfo_Release( typeinfo );
1283 return hr;
1286 if (!(name = get_member_name( object, member, &type )))
1287 return DISP_E_MEMBERNOTFOUND;
1289 if (flags == (DISPATCH_METHOD|DISPATCH_PROPERTYGET))
1291 memset( params, 0, sizeof(*params) );
1292 return IWbemClassObject_Get( object->object, name, 0, result, NULL, NULL );
1294 else if (flags == DISPATCH_PROPERTYPUT)
1296 if (!params->cArgs || !params->rgvarg)
1298 WARN( "Missing put property value\n" );
1299 return E_INVALIDARG;
1302 vartype = to_vartype( type );
1303 V_VT( &value ) = VT_EMPTY;
1304 if (SUCCEEDED(hr = VariantChangeType( &value, params->rgvarg, 0, vartype )))
1306 hr = IWbemClassObject_Put( object->object, name, 0, &value, 0 );
1307 VariantClear( &value );
1309 return hr;
1311 else
1313 FIXME( "flags %#x not supported\n", flags );
1314 return E_NOTIMPL;
1318 static HRESULT WINAPI object_Put_(
1319 ISWbemObject *iface,
1320 LONG iFlags,
1321 IDispatch *objWbemNamedValueSet,
1322 ISWbemObjectPath **objWbemObjectPath )
1324 FIXME( "\n" );
1325 return E_NOTIMPL;
1328 static HRESULT WINAPI object_PutAsync_(
1329 ISWbemObject *iface,
1330 IDispatch *objWbemSink,
1331 LONG iFlags,
1332 IDispatch *objWbemNamedValueSet,
1333 IDispatch *objWbemAsyncContext )
1335 FIXME( "\n" );
1336 return E_NOTIMPL;
1339 static HRESULT WINAPI object_Delete_(
1340 ISWbemObject *iface,
1341 LONG iFlags,
1342 IDispatch *objWbemNamedValueSet )
1344 FIXME( "\n" );
1345 return E_NOTIMPL;
1348 static HRESULT WINAPI object_DeleteAsync_(
1349 ISWbemObject *iface,
1350 IDispatch *objWbemSink,
1351 LONG iFlags,
1352 IDispatch *objWbemNamedValueSet,
1353 IDispatch *objWbemAsyncContext )
1355 FIXME( "\n" );
1356 return E_NOTIMPL;
1359 static HRESULT WINAPI object_Instances_(
1360 ISWbemObject *iface,
1361 LONG iFlags,
1362 IDispatch *objWbemNamedValueSet,
1363 ISWbemObjectSet **objWbemObjectSet )
1365 FIXME( "\n" );
1366 return E_NOTIMPL;
1369 static HRESULT WINAPI object_InstancesAsync_(
1370 ISWbemObject *iface,
1371 IDispatch *objWbemSink,
1372 LONG iFlags,
1373 IDispatch *objWbemNamedValueSet,
1374 IDispatch *objWbemAsyncContext )
1376 FIXME( "\n" );
1377 return E_NOTIMPL;
1380 static HRESULT WINAPI object_Subclasses_(
1381 ISWbemObject *iface,
1382 LONG iFlags,
1383 IDispatch *objWbemNamedValueSet,
1384 ISWbemObjectSet **objWbemObjectSet )
1386 FIXME( "\n" );
1387 return E_NOTIMPL;
1390 static HRESULT WINAPI object_SubclassesAsync_(
1391 ISWbemObject *iface,
1392 IDispatch *objWbemSink,
1393 LONG iFlags,
1394 IDispatch *objWbemNamedValueSet,
1395 IDispatch *objWbemAsyncContext )
1397 FIXME( "\n" );
1398 return E_NOTIMPL;
1401 static HRESULT WINAPI object_Associators_(
1402 ISWbemObject *iface,
1403 BSTR strAssocClass,
1404 BSTR strResultClass,
1405 BSTR strResultRole,
1406 BSTR strRole,
1407 VARIANT_BOOL bClassesOnly,
1408 VARIANT_BOOL bSchemaOnly,
1409 BSTR strRequiredAssocQualifier,
1410 BSTR strRequiredQualifier,
1411 LONG iFlags,
1412 IDispatch *objWbemNamedValueSet,
1413 ISWbemObjectSet **objWbemObjectSet )
1415 FIXME( "\n" );
1416 return E_NOTIMPL;
1419 static HRESULT WINAPI object_AssociatorsAsync_(
1420 ISWbemObject *iface,
1421 IDispatch *objWbemSink,
1422 BSTR strAssocClass,
1423 BSTR strResultClass,
1424 BSTR strResultRole,
1425 BSTR strRole,
1426 VARIANT_BOOL bClassesOnly,
1427 VARIANT_BOOL bSchemaOnly,
1428 BSTR strRequiredAssocQualifier,
1429 BSTR strRequiredQualifier,
1430 LONG iFlags,
1431 IDispatch *objWbemNamedValueSet,
1432 IDispatch *objWbemAsyncContext )
1434 FIXME( "\n" );
1435 return E_NOTIMPL;
1438 static HRESULT WINAPI object_References_(
1439 ISWbemObject *iface,
1440 BSTR strResultClass,
1441 BSTR strRole,
1442 VARIANT_BOOL bClassesOnly,
1443 VARIANT_BOOL bSchemaOnly,
1444 BSTR strRequiredQualifier,
1445 LONG iFlags,
1446 IDispatch *objWbemNamedValueSet,
1447 ISWbemObjectSet **objWbemObjectSet )
1449 FIXME( "\n" );
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI object_ReferencesAsync_(
1454 ISWbemObject *iface,
1455 IDispatch *objWbemSink,
1456 BSTR strResultClass,
1457 BSTR strRole,
1458 VARIANT_BOOL bClassesOnly,
1459 VARIANT_BOOL bSchemaOnly,
1460 BSTR strRequiredQualifier,
1461 LONG iFlags,
1462 IDispatch *objWbemNamedValueSet,
1463 IDispatch *objWbemAsyncContext )
1465 FIXME( "\n" );
1466 return E_NOTIMPL;
1469 static HRESULT WINAPI object_ExecMethod_(
1470 ISWbemObject *iface,
1471 BSTR method,
1472 IDispatch *in_params,
1473 LONG flags,
1474 IDispatch *valueset,
1475 ISWbemObject **out_params )
1477 struct object *object = impl_from_ISWbemObject( iface );
1478 VARIANT path;
1479 HRESULT hr;
1481 TRACE( "%p, %s, %p, %#lx, %p, %p\n", object, debugstr_w(method), in_params, flags, valueset, out_params );
1483 V_VT( &path ) = VT_EMPTY;
1484 hr = IWbemClassObject_Get( object->object, L"__PATH", 0, &path, NULL, NULL );
1485 if (SUCCEEDED(hr))
1487 if (V_VT( &path ) != VT_BSTR)
1489 WARN( "Unexpected object path value type.\n" );
1490 VariantClear( &path );
1491 return E_UNEXPECTED;
1494 hr = ISWbemServices_ExecMethod( &object->services->ISWbemServices_iface, V_BSTR( &path ), method,
1495 in_params, flags, valueset, out_params );
1497 VariantClear( &path );
1500 return hr;
1503 static HRESULT WINAPI object_ExecMethodAsync_(
1504 ISWbemObject *iface,
1505 IDispatch *objWbemSink,
1506 BSTR strMethodName,
1507 IDispatch *objWbemInParameters,
1508 LONG iFlags,
1509 IDispatch *objWbemNamedValueSet,
1510 IDispatch *objWbemAsyncContext )
1512 FIXME( "\n" );
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI object_Clone_(
1517 ISWbemObject *iface,
1518 ISWbemObject **objWbemObject )
1520 FIXME( "\n" );
1521 return E_NOTIMPL;
1524 static HRESULT WINAPI object_GetObjectText_(
1525 ISWbemObject *iface,
1526 LONG flags,
1527 BSTR *text )
1529 struct object *object = impl_from_ISWbemObject( iface );
1531 TRACE( "%p, %#lx, %p\n", object, flags, text );
1533 return IWbemClassObject_GetObjectText( object->object, flags, text );
1536 static HRESULT WINAPI object_SpawnDerivedClass_(
1537 ISWbemObject *iface,
1538 LONG iFlags,
1539 ISWbemObject **objWbemObject )
1541 FIXME( "\n" );
1542 return E_NOTIMPL;
1545 static HRESULT WINAPI object_SpawnInstance_(
1546 ISWbemObject *iface,
1547 LONG iFlags,
1548 ISWbemObject **objWbemObject )
1550 FIXME( "\n" );
1551 return E_NOTIMPL;
1554 static HRESULT WINAPI object_CompareTo_(
1555 ISWbemObject *iface,
1556 IDispatch *objWbemObject,
1557 LONG iFlags,
1558 VARIANT_BOOL *bResult )
1560 FIXME( "\n" );
1561 return E_NOTIMPL;
1564 static HRESULT WINAPI object_get_Qualifiers_(
1565 ISWbemObject *iface,
1566 ISWbemQualifierSet **objWbemQualifierSet )
1568 FIXME( "\n" );
1569 return E_NOTIMPL;
1572 static HRESULT WINAPI object_get_Properties_( ISWbemObject *iface, ISWbemPropertySet **prop_set )
1574 struct object *object = impl_from_ISWbemObject( iface );
1576 TRACE( "%p, %p\n", object, prop_set );
1577 return SWbemPropertySet_create( object->object, prop_set );
1580 static HRESULT WINAPI object_get_Methods_(
1581 ISWbemObject *iface,
1582 ISWbemMethodSet **set )
1584 struct object *object = impl_from_ISWbemObject( iface );
1586 TRACE( "%p, %p\n", object, set );
1587 return SWbemMethodSet_create( object, set );
1590 static HRESULT WINAPI object_get_Derivation_(
1591 ISWbemObject *iface,
1592 VARIANT *strClassNameArray )
1594 FIXME( "\n" );
1595 return E_NOTIMPL;
1598 static HRESULT WINAPI object_get_Path_(
1599 ISWbemObject *iface,
1600 ISWbemObjectPath **objWbemObjectPath )
1602 FIXME( "\n" );
1603 return E_NOTIMPL;
1606 static HRESULT WINAPI object_get_Security_(
1607 ISWbemObject *iface,
1608 ISWbemSecurity **objWbemSecurity )
1610 FIXME( "\n" );
1611 return E_NOTIMPL;
1614 static const ISWbemObjectVtbl object_vtbl =
1616 object_QueryInterface,
1617 object_AddRef,
1618 object_Release,
1619 object_GetTypeInfoCount,
1620 object_GetTypeInfo,
1621 object_GetIDsOfNames,
1622 object_Invoke,
1623 object_Put_,
1624 object_PutAsync_,
1625 object_Delete_,
1626 object_DeleteAsync_,
1627 object_Instances_,
1628 object_InstancesAsync_,
1629 object_Subclasses_,
1630 object_SubclassesAsync_,
1631 object_Associators_,
1632 object_AssociatorsAsync_,
1633 object_References_,
1634 object_ReferencesAsync_,
1635 object_ExecMethod_,
1636 object_ExecMethodAsync_,
1637 object_Clone_,
1638 object_GetObjectText_,
1639 object_SpawnDerivedClass_,
1640 object_SpawnInstance_,
1641 object_CompareTo_,
1642 object_get_Qualifiers_,
1643 object_get_Properties_,
1644 object_get_Methods_,
1645 object_get_Derivation_,
1646 object_get_Path_,
1647 object_get_Security_
1650 static struct object *unsafe_object_impl_from_IDispatch(IDispatch *iface)
1652 if (!iface)
1653 return NULL;
1654 if (iface->lpVtbl != (IDispatchVtbl *)&object_vtbl)
1656 FIXME( "External implementations are not supported.\n" );
1657 return NULL;
1659 return CONTAINING_RECORD(iface, struct object, ISWbemObject_iface);
1662 static HRESULT SWbemObject_create( struct services *services, IWbemClassObject *wbem_object,
1663 ISWbemObject **obj )
1665 struct object *object;
1667 TRACE( "%p, %p\n", obj, wbem_object );
1669 if (!(object = malloc( sizeof(*object) ))) return E_OUTOFMEMORY;
1670 object->ISWbemObject_iface.lpVtbl = &object_vtbl;
1671 object->refs = 1;
1672 object->object = wbem_object;
1673 IWbemClassObject_AddRef( object->object );
1674 object->members = NULL;
1675 object->nb_members = 0;
1676 object->last_dispid = DISPID_BASE;
1677 object->last_dispid_method = DISPID_BASE_METHOD;
1678 object->services = services;
1679 ISWbemServices_AddRef( &object->services->ISWbemServices_iface );
1681 *obj = &object->ISWbemObject_iface;
1682 TRACE( "returning iface %p\n", *obj );
1683 return S_OK;
1686 struct objectset
1688 ISWbemObjectSet ISWbemObjectSet_iface;
1689 LONG refs;
1690 IEnumWbemClassObject *objectenum;
1691 LONG count;
1692 struct services *services;
1695 static inline struct objectset *impl_from_ISWbemObjectSet(
1696 ISWbemObjectSet *iface )
1698 return CONTAINING_RECORD( iface, struct objectset, ISWbemObjectSet_iface );
1701 static ULONG WINAPI objectset_AddRef(
1702 ISWbemObjectSet *iface )
1704 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1705 return InterlockedIncrement( &objectset->refs );
1708 static ULONG WINAPI objectset_Release(
1709 ISWbemObjectSet *iface )
1711 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1712 LONG refs = InterlockedDecrement( &objectset->refs );
1713 if (!refs)
1715 TRACE( "destroying %p\n", objectset );
1716 IEnumWbemClassObject_Release( objectset->objectenum );
1717 ISWbemServices_Release( &objectset->services->ISWbemServices_iface );
1718 free( objectset );
1720 return refs;
1723 static HRESULT WINAPI objectset_QueryInterface(
1724 ISWbemObjectSet *iface,
1725 REFIID riid,
1726 void **ppvObject )
1728 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1730 TRACE( "%p %s %p\n", objectset, debugstr_guid(riid), ppvObject );
1732 if (IsEqualGUID( riid, &IID_ISWbemObjectSet ) ||
1733 IsEqualGUID( riid, &IID_IDispatch ) ||
1734 IsEqualGUID( riid, &IID_IUnknown ))
1736 *ppvObject = iface;
1738 else
1740 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
1741 return E_NOINTERFACE;
1743 ISWbemObjectSet_AddRef( iface );
1744 return S_OK;
1747 static HRESULT WINAPI objectset_GetTypeInfoCount(
1748 ISWbemObjectSet *iface,
1749 UINT *count )
1751 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1752 TRACE( "%p, %p\n", objectset, count );
1753 *count = 1;
1754 return S_OK;
1757 static HRESULT WINAPI objectset_GetTypeInfo(
1758 ISWbemObjectSet *iface,
1759 UINT index,
1760 LCID lcid,
1761 ITypeInfo **info )
1763 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1764 TRACE( "%p, %u, %#lx, %p\n", objectset, index, lcid, info );
1766 return get_typeinfo( ISWbemObjectSet_tid, info );
1769 static HRESULT WINAPI objectset_GetIDsOfNames(
1770 ISWbemObjectSet *iface,
1771 REFIID riid,
1772 LPOLESTR *names,
1773 UINT count,
1774 LCID lcid,
1775 DISPID *dispid )
1777 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1778 ITypeInfo *typeinfo;
1779 HRESULT hr;
1781 TRACE( "%p, %s, %p, %u, %#lx, %p\n", objectset, debugstr_guid(riid), names, count, lcid, dispid );
1783 if (!names || !count || !dispid) return E_INVALIDARG;
1785 hr = get_typeinfo( ISWbemObjectSet_tid, &typeinfo );
1786 if (SUCCEEDED(hr))
1788 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
1789 ITypeInfo_Release( typeinfo );
1791 return hr;
1794 static HRESULT WINAPI objectset_Invoke(
1795 ISWbemObjectSet *iface,
1796 DISPID member,
1797 REFIID riid,
1798 LCID lcid,
1799 WORD flags,
1800 DISPPARAMS *params,
1801 VARIANT *result,
1802 EXCEPINFO *excep_info,
1803 UINT *arg_err )
1805 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1806 ITypeInfo *typeinfo;
1807 HRESULT hr;
1809 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", objectset, member, debugstr_guid(riid),
1810 lcid, flags, params, result, excep_info, arg_err );
1812 hr = get_typeinfo( ISWbemObjectSet_tid, &typeinfo );
1813 if (SUCCEEDED(hr))
1815 hr = ITypeInfo_Invoke( typeinfo, &objectset->ISWbemObjectSet_iface, member, flags,
1816 params, result, excep_info, arg_err );
1817 ITypeInfo_Release( typeinfo );
1819 return hr;
1822 static HRESULT WINAPI objectset_get__NewEnum(
1823 ISWbemObjectSet *iface,
1824 IUnknown **pUnk )
1826 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1827 IEnumWbemClassObject *objectenum;
1828 HRESULT hr;
1830 TRACE( "%p, %p\n", objectset, pUnk );
1832 hr = IEnumWbemClassObject_Clone( objectset->objectenum, &objectenum );
1833 if (FAILED( hr )) return hr;
1835 hr = EnumVARIANT_create( objectset->services, objectenum, (IEnumVARIANT **)pUnk );
1836 IEnumWbemClassObject_Release( objectenum );
1837 return hr;
1840 static HRESULT WINAPI objectset_Item(
1841 ISWbemObjectSet *iface,
1842 BSTR strObjectPath,
1843 LONG iFlags,
1844 ISWbemObject **objWbemObject )
1846 FIXME( "\n" );
1847 return E_NOTIMPL;
1850 static HRESULT WINAPI objectset_get_Count(
1851 ISWbemObjectSet *iface,
1852 LONG *iCount )
1854 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1856 TRACE( "%p, %p\n", objectset, iCount );
1858 *iCount = objectset->count;
1859 return S_OK;
1862 static HRESULT WINAPI objectset_get_Security_(
1863 ISWbemObjectSet *iface,
1864 ISWbemSecurity **objWbemSecurity )
1866 FIXME( "\n" );
1867 return E_NOTIMPL;
1870 static HRESULT WINAPI objectset_ItemIndex(
1871 ISWbemObjectSet *iface,
1872 LONG lIndex,
1873 ISWbemObject **objWbemObject )
1875 struct objectset *objectset = impl_from_ISWbemObjectSet( iface );
1876 LONG count;
1877 HRESULT hr;
1878 IEnumVARIANT *enum_var;
1879 VARIANT var;
1881 TRACE( "%p, %ld, %p\n", objectset, lIndex, objWbemObject );
1883 *objWbemObject = NULL;
1884 hr = ISWbemObjectSet_get_Count( iface, &count );
1885 if (FAILED(hr)) return hr;
1887 if (lIndex >= count) return WBEM_E_NOT_FOUND;
1889 hr = ISWbemObjectSet_get__NewEnum( iface, (IUnknown **)&enum_var );
1890 if (FAILED(hr)) return hr;
1892 IEnumVARIANT_Reset( enum_var );
1893 hr = IEnumVARIANT_Skip( enum_var, lIndex );
1894 if (SUCCEEDED(hr))
1895 hr = IEnumVARIANT_Next( enum_var, 1, &var, NULL );
1896 IEnumVARIANT_Release( enum_var );
1898 if (SUCCEEDED(hr))
1900 if (V_VT( &var ) == VT_DISPATCH)
1901 hr = IDispatch_QueryInterface( V_DISPATCH( &var ), &IID_ISWbemObject, (void **)objWbemObject );
1902 else
1903 hr = WBEM_E_NOT_FOUND;
1904 VariantClear( &var );
1907 return hr;
1910 static const ISWbemObjectSetVtbl objectset_vtbl =
1912 objectset_QueryInterface,
1913 objectset_AddRef,
1914 objectset_Release,
1915 objectset_GetTypeInfoCount,
1916 objectset_GetTypeInfo,
1917 objectset_GetIDsOfNames,
1918 objectset_Invoke,
1919 objectset_get__NewEnum,
1920 objectset_Item,
1921 objectset_get_Count,
1922 objectset_get_Security_,
1923 objectset_ItemIndex
1926 static LONG get_object_count( IEnumWbemClassObject *iter )
1928 LONG count = 0;
1929 while (IEnumWbemClassObject_Skip( iter, WBEM_INFINITE, 1 ) == S_OK) count++;
1930 IEnumWbemClassObject_Reset( iter );
1931 return count;
1934 static HRESULT SWbemObjectSet_create( struct services *services, IEnumWbemClassObject *wbem_objectenum,
1935 ISWbemObjectSet **obj )
1937 struct objectset *objectset;
1939 TRACE( "%p, %p\n", obj, wbem_objectenum );
1941 if (!(objectset = malloc( sizeof(*objectset) ))) return E_OUTOFMEMORY;
1942 objectset->ISWbemObjectSet_iface.lpVtbl = &objectset_vtbl;
1943 objectset->refs = 1;
1944 objectset->objectenum = wbem_objectenum;
1945 IEnumWbemClassObject_AddRef( objectset->objectenum );
1946 objectset->count = get_object_count( objectset->objectenum );
1947 objectset->services = services;
1948 ISWbemServices_AddRef( &services->ISWbemServices_iface );
1950 *obj = &objectset->ISWbemObjectSet_iface;
1951 TRACE( "returning iface %p\n", *obj );
1952 return S_OK;
1955 struct enumvar
1957 IEnumVARIANT IEnumVARIANT_iface;
1958 LONG refs;
1959 IEnumWbemClassObject *objectenum;
1960 struct services *services;
1963 static inline struct enumvar *impl_from_IEnumVARIANT(
1964 IEnumVARIANT *iface )
1966 return CONTAINING_RECORD( iface, struct enumvar, IEnumVARIANT_iface );
1969 static ULONG WINAPI enumvar_AddRef(
1970 IEnumVARIANT *iface )
1972 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
1973 return InterlockedIncrement( &enumvar->refs );
1976 static ULONG WINAPI enumvar_Release(
1977 IEnumVARIANT *iface )
1979 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
1980 LONG refs = InterlockedDecrement( &enumvar->refs );
1981 if (!refs)
1983 TRACE( "destroying %p\n", enumvar );
1984 IEnumWbemClassObject_Release( enumvar->objectenum );
1985 ISWbemServices_Release( &enumvar->services->ISWbemServices_iface );
1986 free( enumvar );
1988 return refs;
1991 static HRESULT WINAPI enumvar_QueryInterface(
1992 IEnumVARIANT *iface,
1993 REFIID riid,
1994 void **ppvObject )
1996 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
1998 TRACE( "%p %s %p\n", enumvar, debugstr_guid(riid), ppvObject );
2000 if (IsEqualGUID( riid, &IID_IEnumVARIANT ) ||
2001 IsEqualGUID( riid, &IID_IUnknown ))
2003 *ppvObject = iface;
2005 else
2007 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2008 return E_NOINTERFACE;
2010 IEnumVARIANT_AddRef( iface );
2011 return S_OK;
2014 static HRESULT WINAPI enumvar_Next( IEnumVARIANT *iface, ULONG celt, VARIANT *var, ULONG *fetched )
2016 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2017 IWbemClassObject *obj;
2018 ULONG count = 0;
2020 TRACE( "%p, %lu, %p, %p\n", iface, celt, var, fetched );
2022 if (celt) IEnumWbemClassObject_Next( enumvar->objectenum, WBEM_INFINITE, 1, &obj, &count );
2023 if (count)
2025 ISWbemObject *sobj;
2026 HRESULT hr;
2028 hr = SWbemObject_create( enumvar->services, obj, &sobj );
2029 IWbemClassObject_Release( obj );
2030 if (FAILED( hr )) return hr;
2032 V_VT( var ) = VT_DISPATCH;
2033 V_DISPATCH( var ) = (IDispatch *)sobj;
2035 if (fetched) *fetched = count;
2036 return (count < celt) ? S_FALSE : S_OK;
2039 static HRESULT WINAPI enumvar_Skip( IEnumVARIANT *iface, ULONG celt )
2041 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2043 TRACE( "%p, %lu\n", iface, celt );
2045 return IEnumWbemClassObject_Skip( enumvar->objectenum, WBEM_INFINITE, celt );
2048 static HRESULT WINAPI enumvar_Reset( IEnumVARIANT *iface )
2050 struct enumvar *enumvar = impl_from_IEnumVARIANT( iface );
2052 TRACE( "%p\n", iface );
2054 return IEnumWbemClassObject_Reset( enumvar->objectenum );
2057 static HRESULT WINAPI enumvar_Clone( IEnumVARIANT *iface, IEnumVARIANT **penum )
2059 FIXME( "%p, %p\n", iface, penum );
2060 return E_NOTIMPL;
2063 static const struct IEnumVARIANTVtbl enumvar_vtbl =
2065 enumvar_QueryInterface,
2066 enumvar_AddRef,
2067 enumvar_Release,
2068 enumvar_Next,
2069 enumvar_Skip,
2070 enumvar_Reset,
2071 enumvar_Clone
2074 static HRESULT EnumVARIANT_create( struct services *services, IEnumWbemClassObject *objectenum,
2075 IEnumVARIANT **obj )
2077 struct enumvar *enumvar;
2079 if (!(enumvar = malloc( sizeof(*enumvar) ))) return E_OUTOFMEMORY;
2080 enumvar->IEnumVARIANT_iface.lpVtbl = &enumvar_vtbl;
2081 enumvar->refs = 1;
2082 enumvar->objectenum = objectenum;
2083 IEnumWbemClassObject_AddRef( enumvar->objectenum );
2084 enumvar->services = services;
2085 ISWbemServices_AddRef( &services->ISWbemServices_iface );
2087 *obj = &enumvar->IEnumVARIANT_iface;
2088 TRACE( "returning iface %p\n", *obj );
2089 return S_OK;
2092 static inline struct services *impl_from_ISWbemServices(
2093 ISWbemServices *iface )
2095 return CONTAINING_RECORD( iface, struct services, ISWbemServices_iface );
2098 static ULONG WINAPI services_AddRef(
2099 ISWbemServices *iface )
2101 struct services *services = impl_from_ISWbemServices( iface );
2102 return InterlockedIncrement( &services->refs );
2105 static ULONG WINAPI services_Release(
2106 ISWbemServices *iface )
2108 struct services *services = impl_from_ISWbemServices( iface );
2109 LONG refs = InterlockedDecrement( &services->refs );
2110 if (!refs)
2112 TRACE( "destroying %p\n", services );
2113 IWbemServices_Release( services->services );
2114 free( services );
2116 return refs;
2119 static HRESULT WINAPI services_QueryInterface(
2120 ISWbemServices *iface,
2121 REFIID riid,
2122 void **ppvObject )
2124 struct services *services = impl_from_ISWbemServices( iface );
2126 TRACE( "%p %s %p\n", services, debugstr_guid(riid), ppvObject );
2128 if (IsEqualGUID( riid, &IID_ISWbemServices ) ||
2129 IsEqualGUID( riid, &IID_IDispatch ) ||
2130 IsEqualGUID( riid, &IID_IUnknown ))
2132 *ppvObject = iface;
2134 else
2136 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2137 return E_NOINTERFACE;
2139 ISWbemServices_AddRef( iface );
2140 return S_OK;
2143 static HRESULT WINAPI services_GetTypeInfoCount(
2144 ISWbemServices *iface,
2145 UINT *count )
2147 struct services *services = impl_from_ISWbemServices( iface );
2148 TRACE( "%p, %p\n", services, count );
2150 *count = 1;
2151 return S_OK;
2154 static HRESULT WINAPI services_GetTypeInfo(
2155 ISWbemServices *iface,
2156 UINT index,
2157 LCID lcid,
2158 ITypeInfo **info )
2160 struct services *services = impl_from_ISWbemServices( iface );
2161 TRACE( "%p, %u, %#lx, %p\n", services, index, lcid, info );
2163 return get_typeinfo( ISWbemServices_tid, info );
2166 static HRESULT WINAPI services_GetIDsOfNames(
2167 ISWbemServices *iface,
2168 REFIID riid,
2169 LPOLESTR *names,
2170 UINT count,
2171 LCID lcid,
2172 DISPID *dispid )
2174 struct services *services = impl_from_ISWbemServices( iface );
2175 ITypeInfo *typeinfo;
2176 HRESULT hr;
2178 TRACE( "%p, %s, %p, %u, %#lx, %p\n", services, debugstr_guid(riid), names, count, lcid, dispid );
2180 if (!names || !count || !dispid) return E_INVALIDARG;
2182 hr = get_typeinfo( ISWbemServices_tid, &typeinfo );
2183 if (SUCCEEDED(hr))
2185 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2186 ITypeInfo_Release( typeinfo );
2188 return hr;
2191 static HRESULT WINAPI services_Invoke(
2192 ISWbemServices *iface,
2193 DISPID member,
2194 REFIID riid,
2195 LCID lcid,
2196 WORD flags,
2197 DISPPARAMS *params,
2198 VARIANT *result,
2199 EXCEPINFO *excep_info,
2200 UINT *arg_err )
2202 struct services *services = impl_from_ISWbemServices( iface );
2203 ITypeInfo *typeinfo;
2204 HRESULT hr;
2206 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", services, member, debugstr_guid(riid),
2207 lcid, flags, params, result, excep_info, arg_err );
2209 hr = get_typeinfo( ISWbemServices_tid, &typeinfo );
2210 if (SUCCEEDED(hr))
2212 hr = ITypeInfo_Invoke( typeinfo, &services->ISWbemServices_iface, member, flags,
2213 params, result, excep_info, arg_err );
2214 ITypeInfo_Release( typeinfo );
2216 return hr;
2219 static HRESULT WINAPI services_Get(
2220 ISWbemServices *iface,
2221 BSTR strObjectPath,
2222 LONG iFlags,
2223 IDispatch *objWbemNamedValueSet,
2224 ISWbemObject **objWbemObject )
2226 struct services *services = impl_from_ISWbemServices( iface );
2227 IWbemClassObject *obj;
2228 HRESULT hr;
2230 TRACE( "%p, %s, %#lx, %p, %p\n", iface, debugstr_w(strObjectPath), iFlags, objWbemNamedValueSet,
2231 objWbemObject );
2233 if (objWbemNamedValueSet) FIXME( "ignoring context\n" );
2235 hr = IWbemServices_GetObject( services->services, strObjectPath, iFlags, NULL, &obj, NULL );
2236 if (hr != S_OK) return hr;
2238 hr = SWbemObject_create( services, obj, objWbemObject );
2239 IWbemClassObject_Release( obj );
2240 return hr;
2243 static HRESULT WINAPI services_GetAsync(
2244 ISWbemServices *iface,
2245 IDispatch *objWbemSink,
2246 BSTR strObjectPath,
2247 LONG iFlags,
2248 IDispatch *objWbemNamedValueSet,
2249 IDispatch *objWbemAsyncContext )
2251 FIXME( "\n" );
2252 return E_NOTIMPL;
2255 static HRESULT WINAPI services_Delete(
2256 ISWbemServices *iface,
2257 BSTR strObjectPath,
2258 LONG iFlags,
2259 IDispatch *objWbemNamedValueSet )
2261 FIXME( "\n" );
2262 return E_NOTIMPL;
2265 static HRESULT WINAPI services_DeleteAsync(
2266 ISWbemServices* This,
2267 IDispatch *objWbemSink,
2268 BSTR strObjectPath,
2269 LONG iFlags,
2270 IDispatch *objWbemNamedValueSet,
2271 IDispatch *objWbemAsyncContext )
2273 FIXME( "\n" );
2274 return E_NOTIMPL;
2277 static BSTR build_query_string( const WCHAR *class )
2279 UINT len = lstrlenW(class) + ARRAY_SIZE(L"SELECT * FROM ");
2280 BSTR ret;
2282 if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
2283 lstrcpyW( ret, L"SELECT * FROM " );
2284 lstrcatW( ret, class );
2285 return ret;
2288 static HRESULT WINAPI services_InstancesOf(
2289 ISWbemServices *iface,
2290 BSTR strClass,
2291 LONG iFlags,
2292 IDispatch *objWbemNamedValueSet,
2293 ISWbemObjectSet **objWbemObjectSet )
2295 BSTR query, wql = SysAllocString( L"WQL" );
2296 HRESULT hr;
2298 TRACE( "%p, %s, %#lx, %p, %p\n", iface, debugstr_w(strClass), iFlags, objWbemNamedValueSet,
2299 objWbemObjectSet );
2301 if (!(query = build_query_string( strClass )))
2303 SysFreeString( wql );
2304 return E_OUTOFMEMORY;
2306 hr = ISWbemServices_ExecQuery( iface, query, wql, iFlags, objWbemNamedValueSet, objWbemObjectSet );
2307 SysFreeString( wql );
2308 SysFreeString( query );
2309 return hr;
2312 static HRESULT WINAPI services_InstancesOfAsync(
2313 ISWbemServices *iface,
2314 IDispatch *objWbemSink,
2315 BSTR strClass,
2316 LONG iFlags,
2317 IDispatch *objWbemNamedValueSet,
2318 IDispatch *objWbemAsyncContext )
2320 FIXME( "\n" );
2321 return E_NOTIMPL;
2324 static HRESULT WINAPI services_SubclassesOf(
2325 ISWbemServices *iface,
2326 BSTR strSuperclass,
2327 LONG iFlags,
2328 IDispatch *objWbemNamedValueSet,
2329 ISWbemObjectSet **objWbemObjectSet )
2331 FIXME( "\n" );
2332 return E_NOTIMPL;
2335 static HRESULT WINAPI services_SubclassesOfAsync(
2336 ISWbemServices *iface,
2337 IDispatch *objWbemSink,
2338 BSTR strSuperclass,
2339 LONG iFlags,
2340 IDispatch *objWbemNamedValueSet,
2341 IDispatch *objWbemAsyncContext )
2343 FIXME( "\n" );
2344 return E_NOTIMPL;
2347 static HRESULT WINAPI services_ExecQuery(
2348 ISWbemServices *iface,
2349 BSTR strQuery,
2350 BSTR strQueryLanguage,
2351 LONG iFlags,
2352 IDispatch *objWbemNamedValueSet,
2353 ISWbemObjectSet **objWbemObjectSet )
2355 struct services *services = impl_from_ISWbemServices( iface );
2356 IEnumWbemClassObject *iter;
2357 HRESULT hr;
2359 TRACE( "%p, %s, %s, %#lx, %p, %p\n", iface, debugstr_w(strQuery), debugstr_w(strQueryLanguage),
2360 iFlags, objWbemNamedValueSet, objWbemObjectSet );
2362 if (objWbemNamedValueSet) FIXME( "ignoring context\n" );
2364 hr = IWbemServices_ExecQuery( services->services, strQueryLanguage, strQuery, iFlags, NULL, &iter );
2365 if (hr != S_OK) return hr;
2367 hr = SWbemObjectSet_create( services, iter, objWbemObjectSet );
2368 IEnumWbemClassObject_Release( iter );
2369 return hr;
2372 static HRESULT WINAPI services_ExecQueryAsync(
2373 ISWbemServices *iface,
2374 IDispatch *objWbemSink,
2375 BSTR strQuery,
2376 BSTR strQueryLanguage,
2377 LONG lFlags,
2378 IDispatch *objWbemNamedValueSet,
2379 IDispatch *objWbemAsyncContext )
2381 FIXME( "\n" );
2382 return E_NOTIMPL;
2385 static HRESULT WINAPI services_AssociatorsOf(
2386 ISWbemServices *iface,
2387 BSTR strObjectPath,
2388 BSTR strAssocClass,
2389 BSTR strResultClass,
2390 BSTR strResultRole,
2391 BSTR strRole,
2392 VARIANT_BOOL bClassesOnly,
2393 VARIANT_BOOL bSchemaOnly,
2394 BSTR strRequiredAssocQualifier,
2395 BSTR strRequiredQualifier,
2396 LONG iFlags,
2397 IDispatch *objWbemNamedValueSet,
2398 ISWbemObjectSet **objWbemObjectSet )
2400 FIXME( "\n" );
2401 return E_NOTIMPL;
2404 static HRESULT WINAPI services_AssociatorsOfAsync(
2405 ISWbemServices *iface,
2406 IDispatch *objWbemSink,
2407 BSTR strObjectPath,
2408 BSTR strAssocClass,
2409 BSTR strResultClass,
2410 BSTR strResultRole,
2411 BSTR strRole,
2412 VARIANT_BOOL bClassesOnly,
2413 VARIANT_BOOL bSchemaOnly,
2414 BSTR strRequiredAssocQualifier,
2415 BSTR strRequiredQualifier,
2416 LONG iFlags,
2417 IDispatch *objWbemNamedValueSet,
2418 IDispatch *objWbemAsyncContext )
2420 FIXME( "\n" );
2421 return E_NOTIMPL;
2424 static HRESULT WINAPI services_ReferencesTo(
2425 ISWbemServices *iface,
2426 BSTR strObjectPath,
2427 BSTR strResultClass,
2428 BSTR strRole,
2429 VARIANT_BOOL bClassesOnly,
2430 VARIANT_BOOL bSchemaOnly,
2431 BSTR strRequiredQualifier,
2432 LONG iFlags,
2433 IDispatch *objWbemNamedValueSet,
2434 ISWbemObjectSet **objWbemObjectSet )
2436 FIXME( "\n" );
2437 return E_NOTIMPL;
2440 static HRESULT WINAPI services_ReferencesToAsync(
2441 ISWbemServices *iface,
2442 IDispatch *objWbemSink,
2443 BSTR strObjectPath,
2444 BSTR strResultClass,
2445 BSTR strRole,
2446 VARIANT_BOOL bClassesOnly,
2447 VARIANT_BOOL bSchemaOnly,
2448 BSTR strRequiredQualifier,
2449 LONG iFlags,
2450 IDispatch *objWbemNamedValueSet,
2451 IDispatch *objWbemAsyncContext )
2453 FIXME( "\n" );
2454 return E_NOTIMPL;
2457 static HRESULT WINAPI services_ExecNotificationQuery(
2458 ISWbemServices *iface,
2459 BSTR strQuery,
2460 BSTR strQueryLanguage,
2461 LONG iFlags,
2462 IDispatch *objWbemNamedValueSet,
2463 ISWbemEventSource **objWbemEventSource )
2465 FIXME( "\n" );
2466 return E_NOTIMPL;
2469 static HRESULT WINAPI services_ExecNotificationQueryAsync(
2470 ISWbemServices *iface,
2471 IDispatch *objWbemSink,
2472 BSTR strQuery,
2473 BSTR strQueryLanguage,
2474 LONG iFlags,
2475 IDispatch *objWbemNamedValueSet,
2476 IDispatch *objWbemAsyncContext )
2478 FIXME( "\n" );
2479 return E_NOTIMPL;
2482 static HRESULT WINAPI services_ExecMethod(
2483 ISWbemServices *iface,
2484 BSTR path,
2485 BSTR method,
2486 IDispatch *in_sparams,
2487 LONG flags,
2488 IDispatch *valueset,
2489 ISWbemObject **out_sparams )
2491 struct services *services = impl_from_ISWbemServices( iface );
2492 IWbemClassObject *out_params = NULL;
2493 struct object *in_params;
2494 IWbemContext *context;
2495 HRESULT hr;
2497 TRACE( "%p, %s, %s, %p, %#lx, %p, %p\n", services, debugstr_w(path), debugstr_w(method), in_sparams,
2498 flags, valueset, out_sparams );
2500 in_params = unsafe_object_impl_from_IDispatch( in_sparams );
2501 out_params = NULL;
2503 context = unsafe_get_context_from_namedvalueset( valueset );
2505 hr = IWbemServices_ExecMethod( services->services, path, method, flags, context, in_params ? in_params->object : NULL,
2506 out_sparams ? &out_params : NULL, NULL );
2508 if (SUCCEEDED(hr) && out_params)
2510 hr = SWbemObject_create( services, out_params, out_sparams );
2511 IWbemClassObject_Release( out_params );
2514 return hr;
2517 static HRESULT WINAPI services_ExecMethodAsync(
2518 ISWbemServices *iface,
2519 IDispatch *objWbemSink,
2520 BSTR strObjectPath,
2521 BSTR strMethodName,
2522 IDispatch *objWbemInParameters,
2523 LONG iFlags,
2524 IDispatch *objWbemNamedValueSet,
2525 IDispatch *objWbemAsyncContext )
2527 FIXME( "\n" );
2528 return E_NOTIMPL;
2531 static HRESULT WINAPI services_get_Security_(
2532 ISWbemServices *iface,
2533 ISWbemSecurity **objWbemSecurity )
2535 TRACE( "%p, %p\n", iface, objWbemSecurity );
2537 if (!objWbemSecurity)
2538 return E_INVALIDARG;
2540 return ISWbemSecurity_create( objWbemSecurity );
2543 static const ISWbemServicesVtbl services_vtbl =
2545 services_QueryInterface,
2546 services_AddRef,
2547 services_Release,
2548 services_GetTypeInfoCount,
2549 services_GetTypeInfo,
2550 services_GetIDsOfNames,
2551 services_Invoke,
2552 services_Get,
2553 services_GetAsync,
2554 services_Delete,
2555 services_DeleteAsync,
2556 services_InstancesOf,
2557 services_InstancesOfAsync,
2558 services_SubclassesOf,
2559 services_SubclassesOfAsync,
2560 services_ExecQuery,
2561 services_ExecQueryAsync,
2562 services_AssociatorsOf,
2563 services_AssociatorsOfAsync,
2564 services_ReferencesTo,
2565 services_ReferencesToAsync,
2566 services_ExecNotificationQuery,
2567 services_ExecNotificationQueryAsync,
2568 services_ExecMethod,
2569 services_ExecMethodAsync,
2570 services_get_Security_
2573 static HRESULT SWbemServices_create( IWbemServices *wbem_services, ISWbemServices **obj )
2575 struct services *services;
2577 TRACE( "%p, %p\n", obj, wbem_services );
2579 if (!(services = malloc( sizeof(*services) ))) return E_OUTOFMEMORY;
2580 services->ISWbemServices_iface.lpVtbl = &services_vtbl;
2581 services->refs = 1;
2582 services->services = wbem_services;
2583 IWbemServices_AddRef( services->services );
2585 *obj = &services->ISWbemServices_iface;
2586 TRACE( "returning iface %p\n", *obj );
2587 return S_OK;
2590 struct locator
2592 ISWbemLocator ISWbemLocator_iface;
2593 LONG refs;
2594 IWbemLocator *locator;
2597 static inline struct locator *impl_from_ISWbemLocator( ISWbemLocator *iface )
2599 return CONTAINING_RECORD( iface, struct locator, ISWbemLocator_iface );
2602 static ULONG WINAPI locator_AddRef(
2603 ISWbemLocator *iface )
2605 struct locator *locator = impl_from_ISWbemLocator( iface );
2606 return InterlockedIncrement( &locator->refs );
2609 static ULONG WINAPI locator_Release(
2610 ISWbemLocator *iface )
2612 struct locator *locator = impl_from_ISWbemLocator( iface );
2613 LONG refs = InterlockedDecrement( &locator->refs );
2614 if (!refs)
2616 TRACE( "destroying %p\n", locator );
2617 if (locator->locator)
2618 IWbemLocator_Release( locator->locator );
2619 free( locator );
2621 return refs;
2624 static HRESULT WINAPI locator_QueryInterface(
2625 ISWbemLocator *iface,
2626 REFIID riid,
2627 void **ppvObject )
2629 struct locator *locator = impl_from_ISWbemLocator( iface );
2631 TRACE( "%p, %s, %p\n", locator, debugstr_guid( riid ), ppvObject );
2633 if (IsEqualGUID( riid, &IID_ISWbemLocator ) ||
2634 IsEqualGUID( riid, &IID_IDispatch ) ||
2635 IsEqualGUID( riid, &IID_IUnknown ))
2637 *ppvObject = iface;
2639 else
2641 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2642 return E_NOINTERFACE;
2644 ISWbemLocator_AddRef( iface );
2645 return S_OK;
2648 static HRESULT WINAPI locator_GetTypeInfoCount(
2649 ISWbemLocator *iface,
2650 UINT *count )
2652 struct locator *locator = impl_from_ISWbemLocator( iface );
2654 TRACE( "%p, %p\n", locator, count );
2655 *count = 1;
2656 return S_OK;
2659 static HRESULT WINAPI locator_GetTypeInfo(
2660 ISWbemLocator *iface,
2661 UINT index,
2662 LCID lcid,
2663 ITypeInfo **info )
2665 struct locator *locator = impl_from_ISWbemLocator( iface );
2666 TRACE( "%p, %u, %#lx, %p\n", locator, index, lcid, info );
2668 return get_typeinfo( ISWbemLocator_tid, info );
2671 static HRESULT WINAPI locator_GetIDsOfNames(
2672 ISWbemLocator *iface,
2673 REFIID riid,
2674 LPOLESTR *names,
2675 UINT count,
2676 LCID lcid,
2677 DISPID *dispid )
2679 struct locator *locator = impl_from_ISWbemLocator( iface );
2680 ITypeInfo *typeinfo;
2681 HRESULT hr;
2683 TRACE( "%p, %s, %p, %u, %#lx, %p\n", locator, debugstr_guid(riid), names, count, lcid, dispid );
2685 if (!names || !count || !dispid) return E_INVALIDARG;
2687 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
2688 if (SUCCEEDED(hr))
2690 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2691 ITypeInfo_Release( typeinfo );
2693 return hr;
2696 static HRESULT WINAPI locator_Invoke(
2697 ISWbemLocator *iface,
2698 DISPID member,
2699 REFIID riid,
2700 LCID lcid,
2701 WORD flags,
2702 DISPPARAMS *params,
2703 VARIANT *result,
2704 EXCEPINFO *excep_info,
2705 UINT *arg_err )
2707 struct locator *locator = impl_from_ISWbemLocator( iface );
2708 ITypeInfo *typeinfo;
2709 HRESULT hr;
2711 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", locator, member, debugstr_guid(riid),
2712 lcid, flags, params, result, excep_info, arg_err );
2714 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
2715 if (SUCCEEDED(hr))
2717 hr = ITypeInfo_Invoke( typeinfo, &locator->ISWbemLocator_iface, member, flags,
2718 params, result, excep_info, arg_err );
2719 ITypeInfo_Release( typeinfo );
2721 return hr;
2724 static BSTR build_resource_string( BSTR server, BSTR namespace )
2726 ULONG len, len_server = 0, len_namespace = 0;
2727 BSTR ret;
2729 if (server && *server) len_server = lstrlenW( server );
2730 else len_server = 1;
2731 if (namespace && *namespace) len_namespace = lstrlenW( namespace );
2732 else len_namespace = ARRAY_SIZE(L"root\\default") - 1;
2734 if (!(ret = SysAllocStringLen( NULL, 2 + len_server + 1 + len_namespace ))) return NULL;
2736 ret[0] = ret[1] = '\\';
2737 if (server && *server) lstrcpyW( ret + 2, server );
2738 else ret[2] = '.';
2740 len = len_server + 2;
2741 ret[len++] = '\\';
2743 if (namespace && *namespace) lstrcpyW( ret + len, namespace );
2744 else lstrcpyW( ret + len, L"root\\default" );
2745 return ret;
2748 static HRESULT WINAPI locator_ConnectServer(
2749 ISWbemLocator *iface,
2750 BSTR strServer,
2751 BSTR strNamespace,
2752 BSTR strUser,
2753 BSTR strPassword,
2754 BSTR strLocale,
2755 BSTR strAuthority,
2756 LONG iSecurityFlags,
2757 IDispatch *objWbemNamedValueSet,
2758 ISWbemServices **objWbemServices )
2760 struct locator *locator = impl_from_ISWbemLocator( iface );
2761 IWbemServices *services;
2762 IWbemContext *context;
2763 BSTR resource;
2764 HRESULT hr;
2766 TRACE( "%p, %s, %s, %s, %p, %s, %s, %#lx, %p, %p\n", iface, debugstr_w(strServer),
2767 debugstr_w(strNamespace), debugstr_w(strUser), strPassword, debugstr_w(strLocale),
2768 debugstr_w(strAuthority), iSecurityFlags, objWbemNamedValueSet, objWbemServices );
2770 if (!locator->locator)
2772 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
2773 (void **)&locator->locator );
2774 if (hr != S_OK) return hr;
2777 context = unsafe_get_context_from_namedvalueset( objWbemNamedValueSet );
2779 if (!(resource = build_resource_string( strServer, strNamespace ))) return E_OUTOFMEMORY;
2780 hr = IWbemLocator_ConnectServer( locator->locator, resource, strUser, strPassword, strLocale,
2781 iSecurityFlags, strAuthority, context, &services );
2782 SysFreeString( resource );
2783 if (hr != S_OK) return hr;
2785 hr = SWbemServices_create( services, objWbemServices );
2786 IWbemServices_Release( services );
2787 return hr;
2790 static HRESULT WINAPI locator_get_Security_(
2791 ISWbemLocator *iface,
2792 ISWbemSecurity **objWbemSecurity )
2794 TRACE( "%p, %p\n", iface, objWbemSecurity );
2796 if (!objWbemSecurity)
2797 return E_INVALIDARG;
2799 return ISWbemSecurity_create( objWbemSecurity );
2802 static const ISWbemLocatorVtbl locator_vtbl =
2804 locator_QueryInterface,
2805 locator_AddRef,
2806 locator_Release,
2807 locator_GetTypeInfoCount,
2808 locator_GetTypeInfo,
2809 locator_GetIDsOfNames,
2810 locator_Invoke,
2811 locator_ConnectServer,
2812 locator_get_Security_
2815 HRESULT SWbemLocator_create( void **obj )
2817 struct locator *locator;
2819 TRACE( "%p\n", obj );
2821 if (!(locator = malloc( sizeof(*locator) ))) return E_OUTOFMEMORY;
2822 locator->ISWbemLocator_iface.lpVtbl = &locator_vtbl;
2823 locator->refs = 1;
2824 locator->locator = NULL;
2826 *obj = &locator->ISWbemLocator_iface;
2827 TRACE( "returning iface %p\n", *obj );
2828 return S_OK;
2831 struct security
2833 ISWbemSecurity ISWbemSecurity_iface;
2834 LONG refs;
2835 WbemImpersonationLevelEnum implevel;
2836 WbemAuthenticationLevelEnum authlevel;
2839 static inline struct security *impl_from_ISWbemSecurity( ISWbemSecurity *iface )
2841 return CONTAINING_RECORD( iface, struct security, ISWbemSecurity_iface );
2844 static ULONG WINAPI security_AddRef(
2845 ISWbemSecurity *iface )
2847 struct security *security = impl_from_ISWbemSecurity( iface );
2848 return InterlockedIncrement( &security->refs );
2851 static ULONG WINAPI security_Release(
2852 ISWbemSecurity *iface )
2854 struct security *security = impl_from_ISWbemSecurity( iface );
2855 LONG refs = InterlockedDecrement( &security->refs );
2856 if (!refs)
2858 TRACE( "destroying %p\n", security );
2859 free( security );
2861 return refs;
2864 static HRESULT WINAPI security_QueryInterface(
2865 ISWbemSecurity *iface,
2866 REFIID riid,
2867 void **ppvObject )
2869 struct security *security = impl_from_ISWbemSecurity( iface );
2870 TRACE( "%p, %s, %p\n", security, debugstr_guid( riid ), ppvObject );
2872 if (IsEqualGUID( riid, &IID_ISWbemSecurity ) ||
2873 IsEqualGUID( riid, &IID_IDispatch ) ||
2874 IsEqualGUID( riid, &IID_IUnknown ))
2876 *ppvObject = iface;
2878 else
2880 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
2881 return E_NOINTERFACE;
2883 ISWbemSecurity_AddRef( iface );
2884 return S_OK;
2887 static HRESULT WINAPI security_GetTypeInfoCount(
2888 ISWbemSecurity *iface,
2889 UINT *count )
2891 struct security *security = impl_from_ISWbemSecurity( iface );
2892 TRACE( "%p, %p\n", security, count );
2894 *count = 1;
2895 return S_OK;
2898 static HRESULT WINAPI security_GetTypeInfo(
2899 ISWbemSecurity *iface,
2900 UINT index,
2901 LCID lcid,
2902 ITypeInfo **info )
2904 struct security *security = impl_from_ISWbemSecurity( iface );
2905 TRACE( "%p, %u, %#lx, %p\n", security, index, lcid, info );
2907 return get_typeinfo( ISWbemSecurity_tid, info );
2910 static HRESULT WINAPI security_GetIDsOfNames(
2911 ISWbemSecurity *iface,
2912 REFIID riid,
2913 LPOLESTR *names,
2914 UINT count,
2915 LCID lcid,
2916 DISPID *dispid )
2918 struct security *security = impl_from_ISWbemSecurity( iface );
2919 ITypeInfo *typeinfo;
2920 HRESULT hr;
2922 TRACE( "%p, %s, %p, %u, %#lx, %p\n", security, debugstr_guid(riid), names, count, lcid, dispid );
2924 if (!names || !count || !dispid) return E_INVALIDARG;
2926 hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo );
2927 if (SUCCEEDED(hr))
2929 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
2930 ITypeInfo_Release( typeinfo );
2932 return hr;
2935 static HRESULT WINAPI security_Invoke(
2936 ISWbemSecurity *iface,
2937 DISPID member,
2938 REFIID riid,
2939 LCID lcid,
2940 WORD flags,
2941 DISPPARAMS *params,
2942 VARIANT *result,
2943 EXCEPINFO *excep_info,
2944 UINT *arg_err )
2946 struct security *security = impl_from_ISWbemSecurity( iface );
2947 ITypeInfo *typeinfo;
2948 HRESULT hr;
2950 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", security, member, debugstr_guid(riid),
2951 lcid, flags, params, result, excep_info, arg_err );
2953 hr = get_typeinfo( ISWbemSecurity_tid, &typeinfo );
2954 if (SUCCEEDED(hr))
2956 hr = ITypeInfo_Invoke( typeinfo, &security->ISWbemSecurity_iface, member, flags,
2957 params, result, excep_info, arg_err );
2958 ITypeInfo_Release( typeinfo );
2960 return hr;
2963 static HRESULT WINAPI security_get_ImpersonationLevel(
2964 ISWbemSecurity *iface,
2965 WbemImpersonationLevelEnum *impersonation_level )
2967 struct security *security = impl_from_ISWbemSecurity( iface );
2968 FIXME( "%p, %p: stub\n", security, impersonation_level );
2970 if (!impersonation_level)
2971 return E_INVALIDARG;
2973 *impersonation_level = security->implevel;
2974 return S_OK;
2977 static HRESULT WINAPI security_put_ImpersonationLevel(
2978 ISWbemSecurity *iface,
2979 WbemImpersonationLevelEnum impersonation_level )
2981 struct security *security = impl_from_ISWbemSecurity( iface );
2982 FIXME( "%p, %d: stub\n", security, impersonation_level );
2984 security->implevel = impersonation_level;
2985 return S_OK;
2988 static HRESULT WINAPI security_get_AuthenticationLevel(
2989 ISWbemSecurity *iface,
2990 WbemAuthenticationLevelEnum *authentication_level )
2992 struct security *security = impl_from_ISWbemSecurity( iface );
2993 FIXME( "%p, %p: stub\n", security, authentication_level );
2995 if (!authentication_level)
2996 return E_INVALIDARG;
2998 *authentication_level = security->authlevel;
2999 return S_OK;
3002 static HRESULT WINAPI security_put_AuthenticationLevel(
3003 ISWbemSecurity *iface,
3004 WbemAuthenticationLevelEnum authentication_level )
3006 struct security *security = impl_from_ISWbemSecurity( iface );
3007 FIXME( "%p, %d: stub\n", security, authentication_level );
3009 security->authlevel = authentication_level;
3010 return S_OK;
3013 static HRESULT WINAPI security_get_Privileges(
3014 ISWbemSecurity *iface,
3015 ISWbemPrivilegeSet **privilege_set )
3017 struct security *security = impl_from_ISWbemSecurity( iface );
3018 FIXME( "%p, %p: stub\n", security, privilege_set );
3020 if (!privilege_set)
3021 return E_INVALIDARG;
3023 return E_NOTIMPL;
3026 static const ISWbemSecurityVtbl security_vtbl =
3028 security_QueryInterface,
3029 security_AddRef,
3030 security_Release,
3031 security_GetTypeInfoCount,
3032 security_GetTypeInfo,
3033 security_GetIDsOfNames,
3034 security_Invoke,
3035 security_get_ImpersonationLevel,
3036 security_put_ImpersonationLevel,
3037 security_get_AuthenticationLevel,
3038 security_put_AuthenticationLevel,
3039 security_get_Privileges
3042 static HRESULT ISWbemSecurity_create( ISWbemSecurity **obj )
3044 struct security *security;
3046 TRACE( "%p\n", obj );
3048 if (!(security = malloc( sizeof(*security) ))) return E_OUTOFMEMORY;
3049 security->ISWbemSecurity_iface.lpVtbl = &security_vtbl;
3050 security->refs = 1;
3051 security->implevel = wbemImpersonationLevelImpersonate;
3052 security->authlevel = wbemAuthenticationLevelPktPrivacy;
3054 *obj = &security->ISWbemSecurity_iface;
3055 TRACE( "returning iface %p\n", *obj );
3056 return S_OK;
3059 struct namedvalue
3061 ISWbemNamedValue ISWbemNamedValue_iface;
3062 LONG refs;
3065 static struct namedvalueset *impl_from_ISWbemNamedValueSet( ISWbemNamedValueSet *iface )
3067 return CONTAINING_RECORD( iface, struct namedvalueset, ISWbemNamedValueSet_iface );
3070 static struct namedvalue *impl_from_ISWbemNamedValue( ISWbemNamedValue *iface )
3072 return CONTAINING_RECORD( iface, struct namedvalue, ISWbemNamedValue_iface );
3075 static HRESULT WINAPI namedvalue_QueryInterface(
3076 ISWbemNamedValue *iface,
3077 REFIID riid,
3078 void **ppvObject )
3080 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3082 TRACE( "%p, %s, %p\n", value, debugstr_guid( riid ), ppvObject );
3084 if (IsEqualGUID( riid, &IID_ISWbemNamedValue ) ||
3085 IsEqualGUID( riid, &IID_IDispatch ) ||
3086 IsEqualGUID( riid, &IID_IUnknown ))
3088 *ppvObject = iface;
3090 else
3092 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
3093 return E_NOINTERFACE;
3095 ISWbemNamedValue_AddRef( iface );
3096 return S_OK;
3099 static ULONG WINAPI namedvalue_AddRef(
3100 ISWbemNamedValue *iface )
3102 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3103 return InterlockedIncrement( &value->refs );
3106 static ULONG WINAPI namedvalue_Release(
3107 ISWbemNamedValue *iface )
3109 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3110 LONG refs = InterlockedDecrement( &value->refs );
3111 if (!refs)
3113 TRACE( "destroying %p\n", value );
3114 free( value );
3116 return refs;
3119 static HRESULT WINAPI namedvalue_GetTypeInfoCount(
3120 ISWbemNamedValue *iface,
3121 UINT *count )
3123 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3124 TRACE( "%p, %p\n", value, count );
3126 *count = 1;
3127 return S_OK;
3130 static HRESULT WINAPI namedvalue_GetTypeInfo(
3131 ISWbemNamedValue *iface,
3132 UINT index,
3133 LCID lcid,
3134 ITypeInfo **info )
3136 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3138 TRACE( "%p, %u, %#lx, %p\n", value, index, lcid, info );
3140 return get_typeinfo( ISWbemNamedValue_tid, info );
3143 static HRESULT WINAPI namedvalue_GetIDsOfNames(
3144 ISWbemNamedValue *iface,
3145 REFIID riid,
3146 LPOLESTR *names,
3147 UINT count,
3148 LCID lcid,
3149 DISPID *dispid )
3151 struct namedvalue *value = impl_from_ISWbemNamedValue( iface );
3152 ITypeInfo *typeinfo;
3153 HRESULT hr;
3155 TRACE( "%p, %s, %p, %u, %#lx, %p\n", value, debugstr_guid(riid), names, count, lcid, dispid );
3157 if (!names || !count || !dispid) return E_INVALIDARG;
3159 hr = get_typeinfo( ISWbemNamedValue_tid, &typeinfo );
3160 if (SUCCEEDED(hr))
3162 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
3163 ITypeInfo_Release( typeinfo );
3165 return hr;
3168 static HRESULT WINAPI namedvalue_Invoke(
3169 ISWbemNamedValue *iface,
3170 DISPID member,
3171 REFIID riid,
3172 LCID lcid,
3173 WORD flags,
3174 DISPPARAMS *params,
3175 VARIANT *result,
3176 EXCEPINFO *excep_info,
3177 UINT *arg_err )
3179 struct namedvalue *set = impl_from_ISWbemNamedValue( iface );
3180 ITypeInfo *typeinfo;
3181 HRESULT hr;
3183 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
3184 lcid, flags, params, result, excep_info, arg_err );
3186 hr = get_typeinfo( ISWbemNamedValue_tid, &typeinfo );
3187 if (SUCCEEDED(hr))
3189 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemNamedValue_iface, member, flags,
3190 params, result, excep_info, arg_err );
3191 ITypeInfo_Release( typeinfo );
3193 return hr;
3196 static HRESULT WINAPI namedvalue_get_Value(
3197 ISWbemNamedValue *iface,
3198 VARIANT *var )
3200 FIXME("\n");
3202 return E_NOTIMPL;
3205 static HRESULT WINAPI namedvalue_put_Value(
3206 ISWbemNamedValue *iface,
3207 VARIANT *var )
3209 FIXME("\n");
3211 return E_NOTIMPL;
3214 static HRESULT WINAPI namedvalue_get_Name(
3215 ISWbemNamedValue *iface,
3216 BSTR *name )
3218 FIXME("\n");
3220 return E_NOTIMPL;
3223 static const ISWbemNamedValueVtbl namedvaluevtbl =
3225 namedvalue_QueryInterface,
3226 namedvalue_AddRef,
3227 namedvalue_Release,
3228 namedvalue_GetTypeInfoCount,
3229 namedvalue_GetTypeInfo,
3230 namedvalue_GetIDsOfNames,
3231 namedvalue_Invoke,
3232 namedvalue_get_Value,
3233 namedvalue_put_Value,
3234 namedvalue_get_Name
3237 static HRESULT namedvalue_create( ISWbemNamedValue **value )
3239 struct namedvalue *object;
3241 if (!(object = malloc( sizeof(*object) ))) return E_OUTOFMEMORY;
3243 object->ISWbemNamedValue_iface.lpVtbl = &namedvaluevtbl;
3244 object->refs = 1;
3246 *value = &object->ISWbemNamedValue_iface;
3248 return S_OK;
3251 static HRESULT WINAPI namedvalueset_QueryInterface(
3252 ISWbemNamedValueSet *iface,
3253 REFIID riid,
3254 void **ppvObject )
3256 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3258 TRACE( "%p, %s, %p\n", set, debugstr_guid( riid ), ppvObject );
3260 if (IsEqualGUID( riid, &IID_ISWbemNamedValueSet ) ||
3261 IsEqualGUID( riid, &IID_IDispatch ) ||
3262 IsEqualGUID( riid, &IID_IUnknown ))
3264 *ppvObject = iface;
3266 else
3268 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
3269 return E_NOINTERFACE;
3271 ISWbemNamedValueSet_AddRef( iface );
3272 return S_OK;
3275 static ULONG WINAPI namedvalueset_AddRef(
3276 ISWbemNamedValueSet *iface )
3278 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3279 return InterlockedIncrement( &set->refs );
3282 static ULONG WINAPI namedvalueset_Release(
3283 ISWbemNamedValueSet *iface )
3285 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3286 LONG refs = InterlockedDecrement( &set->refs );
3287 if (!refs)
3289 TRACE( "destroying %p\n", set );
3290 if (set->context)
3291 IWbemContext_Release( set->context );
3292 free( set );
3294 return refs;
3297 static HRESULT WINAPI namedvalueset_GetTypeInfoCount(
3298 ISWbemNamedValueSet *iface,
3299 UINT *count )
3301 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3302 TRACE( "%p, %p\n", set, count );
3304 *count = 1;
3305 return S_OK;
3308 static HRESULT WINAPI namedvalueset_GetTypeInfo(
3309 ISWbemNamedValueSet *iface,
3310 UINT index,
3311 LCID lcid,
3312 ITypeInfo **info )
3314 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3316 TRACE( "%p, %u, %#lx, %p\n", set, index, lcid, info );
3318 return get_typeinfo( ISWbemNamedValueSet_tid, info );
3321 static HRESULT WINAPI namedvalueset_GetIDsOfNames(
3322 ISWbemNamedValueSet *iface,
3323 REFIID riid,
3324 LPOLESTR *names,
3325 UINT count,
3326 LCID lcid,
3327 DISPID *dispid )
3329 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3330 ITypeInfo *typeinfo;
3331 HRESULT hr;
3333 TRACE( "%p, %s, %p, %u, %#lx, %p\n", set, debugstr_guid(riid), names, count, lcid, dispid );
3335 if (!names || !count || !dispid) return E_INVALIDARG;
3337 hr = get_typeinfo( ISWbemNamedValueSet_tid, &typeinfo );
3338 if (SUCCEEDED(hr))
3340 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
3341 ITypeInfo_Release( typeinfo );
3343 return hr;
3346 static HRESULT WINAPI namedvalueset_Invoke(
3347 ISWbemNamedValueSet *iface,
3348 DISPID member,
3349 REFIID riid,
3350 LCID lcid,
3351 WORD flags,
3352 DISPPARAMS *params,
3353 VARIANT *result,
3354 EXCEPINFO *excep_info,
3355 UINT *arg_err )
3357 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3358 ITypeInfo *typeinfo;
3359 HRESULT hr;
3361 TRACE( "%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p\n", set, member, debugstr_guid(riid),
3362 lcid, flags, params, result, excep_info, arg_err );
3364 hr = get_typeinfo( ISWbemNamedValueSet_tid, &typeinfo );
3365 if (SUCCEEDED(hr))
3367 hr = ITypeInfo_Invoke( typeinfo, &set->ISWbemNamedValueSet_iface, member, flags,
3368 params, result, excep_info, arg_err );
3369 ITypeInfo_Release( typeinfo );
3371 return hr;
3374 static HRESULT WINAPI namedvalueset_get__NewEnum(
3375 ISWbemNamedValueSet *iface,
3376 IUnknown **unk )
3378 FIXME("\n");
3380 return E_NOTIMPL;
3383 static HRESULT WINAPI namedvalueset_Item(
3384 ISWbemNamedValueSet *iface,
3385 BSTR name,
3386 LONG flags,
3387 ISWbemNamedValue **value )
3389 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3390 VARIANT var;
3391 HRESULT hr;
3393 TRACE("%p, %s, %#lx, %p\n", set, debugstr_w(name), flags, value);
3395 if (SUCCEEDED(hr = IWbemContext_GetValue( set->context, name, flags, &var )))
3397 VariantClear( &var );
3398 hr = namedvalue_create( value );
3401 return hr;
3404 static HRESULT WINAPI namedvalueset_get_Count(
3405 ISWbemNamedValueSet *iface,
3406 LONG *count )
3408 FIXME("\n");
3410 return E_NOTIMPL;
3413 static HRESULT WINAPI namedvalueset_Add(
3414 ISWbemNamedValueSet *iface,
3415 BSTR name,
3416 VARIANT *var,
3417 LONG flags,
3418 ISWbemNamedValue **value )
3420 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3421 HRESULT hr;
3423 TRACE("%p, %s, %s, %#lx, %p\n", set, debugstr_w(name), debugstr_variant(var), flags, value);
3425 if (!name || !var || !value)
3426 return WBEM_E_INVALID_PARAMETER;
3428 if (SUCCEEDED(hr = IWbemContext_SetValue( set->context, name, flags, var )))
3430 hr = namedvalue_create( value );
3433 return hr;
3436 static HRESULT WINAPI namedvalueset_Remove(
3437 ISWbemNamedValueSet *iface,
3438 BSTR name,
3439 LONG flags )
3441 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3443 TRACE("%p, %s, %#lx\n", set, debugstr_w(name), flags);
3445 return IWbemContext_DeleteValue( set->context, name, flags );
3448 static HRESULT WINAPI namedvalueset_Clone(
3449 ISWbemNamedValueSet *iface,
3450 ISWbemNamedValueSet **valueset )
3452 FIXME("\n");
3454 return E_NOTIMPL;
3457 static HRESULT WINAPI namedvalueset_DeleteAll(
3458 ISWbemNamedValueSet *iface )
3460 struct namedvalueset *set = impl_from_ISWbemNamedValueSet( iface );
3462 TRACE("%p\n", set);
3464 return IWbemContext_DeleteAll( set->context );
3467 static const ISWbemNamedValueSetVtbl namedvalueset_vtbl =
3469 namedvalueset_QueryInterface,
3470 namedvalueset_AddRef,
3471 namedvalueset_Release,
3472 namedvalueset_GetTypeInfoCount,
3473 namedvalueset_GetTypeInfo,
3474 namedvalueset_GetIDsOfNames,
3475 namedvalueset_Invoke,
3476 namedvalueset_get__NewEnum,
3477 namedvalueset_Item,
3478 namedvalueset_get_Count,
3479 namedvalueset_Add,
3480 namedvalueset_Remove,
3481 namedvalueset_Clone,
3482 namedvalueset_DeleteAll,
3485 static struct namedvalueset *unsafe_valueset_impl_from_IDispatch(IDispatch *iface)
3487 if (!iface)
3488 return NULL;
3489 if (iface->lpVtbl != (IDispatchVtbl *)&namedvalueset_vtbl)
3491 FIXME( "External implementations are not supported.\n" );
3492 return NULL;
3494 return CONTAINING_RECORD(iface, struct namedvalueset, ISWbemNamedValueSet_iface);
3497 HRESULT SWbemNamedValueSet_create( void **obj )
3499 struct namedvalueset *set;
3500 HRESULT hr;
3502 TRACE( "%p\n", obj );
3504 if (!(set = calloc( 1, sizeof(*set) ))) return E_OUTOFMEMORY;
3505 set->ISWbemNamedValueSet_iface.lpVtbl = &namedvalueset_vtbl;
3506 set->refs = 1;
3508 if (FAILED(hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext,
3509 (void **)&set->context )))
3511 ISWbemNamedValueSet_Release( &set->ISWbemNamedValueSet_iface );
3512 return hr;
3515 *obj = &set->ISWbemNamedValueSet_iface;
3516 TRACE( "returning iface %p\n", *obj );
3517 return hr;