2 * Copyright 2012 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
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
33 struct enum_class_object
35 IEnumWbemClassObject IEnumWbemClassObject_iface
;
41 static inline struct enum_class_object
*impl_from_IEnumWbemClassObject(
42 IEnumWbemClassObject
*iface
)
44 return CONTAINING_RECORD(iface
, struct enum_class_object
, IEnumWbemClassObject_iface
);
47 static ULONG WINAPI
enum_class_object_AddRef(
48 IEnumWbemClassObject
*iface
)
50 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
51 return InterlockedIncrement( &ec
->refs
);
54 static ULONG WINAPI
enum_class_object_Release(
55 IEnumWbemClassObject
*iface
)
57 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
58 LONG refs
= InterlockedDecrement( &ec
->refs
);
61 TRACE("destroying %p\n", ec
);
62 release_query( ec
->query
);
68 static HRESULT WINAPI
enum_class_object_QueryInterface(
69 IEnumWbemClassObject
*iface
,
73 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
75 TRACE("%p, %s, %p\n", ec
, debugstr_guid( riid
), ppvObject
);
77 if ( IsEqualGUID( riid
, &IID_IEnumWbemClassObject
) ||
78 IsEqualGUID( riid
, &IID_IUnknown
) )
82 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
84 *ppvObject
= &client_security
;
89 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
92 IEnumWbemClassObject_AddRef( iface
);
96 static HRESULT WINAPI
enum_class_object_Reset(
97 IEnumWbemClassObject
*iface
)
99 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
101 TRACE("%p\n", iface
);
104 return WBEM_S_NO_ERROR
;
107 static HRESULT WINAPI
enum_class_object_Next(
108 IEnumWbemClassObject
*iface
,
111 IWbemClassObject
**apObjects
,
114 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
115 struct view
*view
= ec
->query
->view
;
120 TRACE("%p, %d, %u, %p, %p\n", iface
, lTimeout
, uCount
, apObjects
, puReturned
);
122 if (!uCount
) return WBEM_S_FALSE
;
123 if (!apObjects
|| !puReturned
) return WBEM_E_INVALID_PARAMETER
;
124 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
127 if (ec
->index
>= view
->result_count
) return WBEM_S_FALSE
;
129 table
= get_view_table( view
, ec
->index
);
130 hr
= create_class_object( table
->name
, iface
, ec
->index
, NULL
, apObjects
);
131 if (hr
!= S_OK
) return hr
;
135 if (ec
->index
== view
->result_count
&& uCount
> 1) return WBEM_S_FALSE
;
136 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
137 return WBEM_S_NO_ERROR
;
140 static HRESULT WINAPI
enum_class_object_NextAsync(
141 IEnumWbemClassObject
*iface
,
143 IWbemObjectSink
*pSink
)
145 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
149 static HRESULT WINAPI
enum_class_object_Clone(
150 IEnumWbemClassObject
*iface
,
151 IEnumWbemClassObject
**ppEnum
)
153 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
155 TRACE("%p, %p\n", iface
, ppEnum
);
157 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
160 static HRESULT WINAPI
enum_class_object_Skip(
161 IEnumWbemClassObject
*iface
,
165 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
166 struct view
*view
= ec
->query
->view
;
169 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
171 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
173 if (!view
->result_count
) return WBEM_S_FALSE
;
175 if (nCount
> view
->result_count
- ec
->index
)
177 ec
->index
= view
->result_count
- 1;
181 return WBEM_S_NO_ERROR
;
184 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
186 enum_class_object_QueryInterface
,
187 enum_class_object_AddRef
,
188 enum_class_object_Release
,
189 enum_class_object_Reset
,
190 enum_class_object_Next
,
191 enum_class_object_NextAsync
,
192 enum_class_object_Clone
,
193 enum_class_object_Skip
196 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
198 struct enum_class_object
*ec
;
200 TRACE("%p\n", ppObj
);
202 ec
= heap_alloc( sizeof(*ec
) );
203 if (!ec
) return E_OUTOFMEMORY
;
205 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
207 ec
->query
= addref_query( query
);
210 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
212 TRACE("returning iface %p\n", *ppObj
);
216 static struct record
*create_record( struct table
*table
)
219 struct record
*record
;
221 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
222 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
227 for (i
= 0; i
< table
->num_cols
; i
++)
229 record
->fields
[i
].type
= table
->columns
[i
].type
;
230 record
->fields
[i
].u
.ival
= 0;
232 record
->count
= table
->num_cols
;
233 record
->table
= addref_table( table
);
237 void destroy_array( struct array
*array
, CIMTYPE type
)
241 if (type
== CIM_STRING
|| type
== CIM_DATETIME
|| type
== CIM_REFERENCE
)
243 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* array
->elem_size
) );
245 heap_free( array
->ptr
);
249 static void destroy_record( struct record
*record
)
254 release_table( record
->table
);
255 for (i
= 0; i
< record
->count
; i
++)
257 if (record
->fields
[i
].type
== CIM_STRING
||
258 record
->fields
[i
].type
== CIM_DATETIME
||
259 record
->fields
[i
].type
== CIM_REFERENCE
) heap_free( record
->fields
[i
].u
.sval
);
260 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
261 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
263 heap_free( record
->fields
);
269 IWbemClassObject IWbemClassObject_iface
;
272 IEnumWbemClassObject
*iter
;
276 struct record
*record
; /* uncommitted instance */
279 static inline struct class_object
*impl_from_IWbemClassObject(
280 IWbemClassObject
*iface
)
282 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
285 static ULONG WINAPI
class_object_AddRef(
286 IWbemClassObject
*iface
)
288 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
289 return InterlockedIncrement( &co
->refs
);
292 static ULONG WINAPI
class_object_Release(
293 IWbemClassObject
*iface
)
295 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
296 LONG refs
= InterlockedDecrement( &co
->refs
);
299 TRACE("destroying %p\n", co
);
300 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
301 destroy_record( co
->record
);
302 heap_free( co
->name
);
308 static HRESULT WINAPI
class_object_QueryInterface(
309 IWbemClassObject
*iface
,
313 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
315 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
317 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
318 IsEqualGUID( riid
, &IID_IUnknown
) )
322 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
324 *ppvObject
= &client_security
;
329 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
330 return E_NOINTERFACE
;
332 IWbemClassObject_AddRef( iface
);
336 static HRESULT WINAPI
class_object_GetQualifierSet(
337 IWbemClassObject
*iface
,
338 IWbemQualifierSet
**ppQualSet
)
340 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
342 TRACE("%p, %p\n", iface
, ppQualSet
);
344 return WbemQualifierSet_create( co
->name
, NULL
, (void **)ppQualSet
);
347 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
349 VARTYPE vartype
= to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
);
351 if (type
) *type
= record
->fields
[index
].type
;
353 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
355 V_VT( var
) = vartype
| VT_ARRAY
;
356 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
359 switch (record
->fields
[index
].type
)
364 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
367 V_I4( var
) = record
->fields
[index
].u
.ival
;
370 V_UI4( var
) = record
->fields
[index
].u
.ival
;
373 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
374 return WBEM_E_INVALID_PARAMETER
;
376 V_VT( var
) = vartype
;
380 static HRESULT WINAPI
class_object_Get(
381 IWbemClassObject
*iface
,
388 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
389 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
391 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
398 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
399 return record_get_value( co
->record
, index
, pVal
, pType
);
401 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
404 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
410 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
411 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
413 if (type
& CIM_FLAG_ARRAY
)
415 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
423 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
429 record
->fields
[index
].u
.ival
= val
;
432 FIXME("unhandled type %u\n", type
);
435 return WBEM_E_INVALID_PARAMETER
;
438 static HRESULT WINAPI
class_object_Put(
439 IWbemClassObject
*iface
,
445 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
446 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
448 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
455 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
456 return record_set_value( co
->record
, index
, pVal
);
458 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
461 static HRESULT WINAPI
class_object_Delete(
462 IWbemClassObject
*iface
,
465 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
469 static HRESULT WINAPI
class_object_GetNames(
470 IWbemClassObject
*iface
,
471 LPCWSTR wszQualifierName
,
473 VARIANT
*pQualifierVal
,
476 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
477 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
479 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
480 debugstr_variant(pQualifierVal
), pNames
);
482 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
483 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
484 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
486 FIXME("flags %08x not supported\n", lFlags
);
489 if (wszQualifierName
|| pQualifierVal
)
490 FIXME("qualifier not supported\n");
492 return get_properties( ec
->query
->view
, co
->index
, lFlags
, pNames
);
495 static HRESULT WINAPI
class_object_BeginEnumeration(
496 IWbemClassObject
*iface
,
499 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
501 TRACE("%p, %08x\n", iface
, lEnumFlags
);
503 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
505 co
->index_property
= 0;
509 static HRESULT WINAPI
class_object_Next(
510 IWbemClassObject
*iface
,
517 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
518 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
519 struct view
*view
= iter
->query
->view
;
520 struct table
*table
= get_view_table( view
, obj
->index
);
525 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
527 for (i
= obj
->index_property
; i
< table
->num_cols
; i
++)
529 if (is_method( table
, i
)) continue;
530 if (!is_result_prop( view
, table
->columns
[i
].name
)) continue;
531 if (!(prop
= SysAllocString( table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
532 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
534 SysFreeString( prop
);
538 obj
->index_property
= i
+ 1;
539 if (strName
) *strName
= prop
;
540 else SysFreeString( prop
);
544 return WBEM_S_NO_MORE_DATA
;
547 static HRESULT WINAPI
class_object_EndEnumeration(
548 IWbemClassObject
*iface
)
550 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
552 TRACE("%p\n", iface
);
554 co
->index_property
= 0;
558 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
559 IWbemClassObject
*iface
,
561 IWbemQualifierSet
**ppQualSet
)
563 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
565 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
567 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
570 static HRESULT WINAPI
class_object_Clone(
571 IWbemClassObject
*iface
,
572 IWbemClassObject
**ppCopy
)
574 FIXME("%p, %p\n", iface
, ppCopy
);
578 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
585 for (i
= 0; i
< table
->num_cols
; i
++)
587 if ((value
= get_value_bstr( table
, row
, i
)))
589 *len
+= ARRAY_SIZE( L
"\n\t%s = %s;" );
590 *len
+= lstrlenW( table
->columns
[i
].name
);
591 *len
+= SysStringLen( value
);
592 SysFreeString( value
);
595 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
597 for (i
= 0; i
< table
->num_cols
; i
++)
599 if ((value
= get_value_bstr( table
, row
, i
)))
601 p
+= swprintf( p
, *len
- (p
- ret
), L
"\n\t%s = %s;", table
->columns
[i
].name
, value
);
602 SysFreeString( value
);
608 static BSTR
get_object_text( const struct view
*view
, UINT index
)
610 UINT len
, len_body
, row
= view
->result
[index
];
611 struct table
*table
= get_view_table( view
, index
);
614 len
= ARRAY_SIZE( L
"\ninstance of %s\n{%s\n};" );
615 len
+= lstrlenW( table
->name
);
616 if (!(body
= get_body_text( table
, row
, &len_body
))) return NULL
;
619 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
620 swprintf( ret
, len
, L
"\ninstance of %s\n{%s\n};", table
->name
, body
);
621 SysFreeString( body
);
625 static HRESULT WINAPI
class_object_GetObjectText(
626 IWbemClassObject
*iface
,
628 BSTR
*pstrObjectText
)
630 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
631 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
632 struct view
*view
= ec
->query
->view
;
635 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
637 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
639 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
640 *pstrObjectText
= text
;
644 static HRESULT WINAPI
class_object_SpawnDerivedClass(
645 IWbemClassObject
*iface
,
647 IWbemClassObject
**ppNewClass
)
649 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
653 static HRESULT WINAPI
class_object_SpawnInstance(
654 IWbemClassObject
*iface
,
656 IWbemClassObject
**ppNewInstance
)
658 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
659 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
660 struct table
*table
= get_view_table( ec
->query
->view
, co
->index
);
661 struct record
*record
;
663 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
665 if (!(record
= create_record( table
))) return E_OUTOFMEMORY
;
667 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
670 static HRESULT WINAPI
class_object_CompareTo(
671 IWbemClassObject
*iface
,
673 IWbemClassObject
*pCompareTo
)
675 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
679 static HRESULT WINAPI
class_object_GetPropertyOrigin(
680 IWbemClassObject
*iface
,
682 BSTR
*pstrClassName
)
684 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
688 static HRESULT WINAPI
class_object_InheritsFrom(
689 IWbemClassObject
*iface
,
690 LPCWSTR strAncestor
)
692 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
696 static UINT
count_instances( IEnumWbemClassObject
*iter
)
699 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
700 IEnumWbemClassObject_Reset( iter
);
704 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
712 *(UINT16
*)ptr
= val
;
718 *(UINT32
*)ptr
= val
;
721 FIXME("unhandled type %u\n", type
);
726 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
727 struct column
**cols
, BYTE
**data
)
729 struct column
*columns
;
731 IWbemClassObject
*param
;
733 HRESULT hr
= E_OUTOFMEMORY
;
738 count
= count_instances( iter
);
739 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
740 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
744 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
747 hr
= IWbemClassObject_Get( param
, L
"Parameter", 0, &val
, NULL
, NULL
);
748 if (hr
!= S_OK
) goto error
;
749 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
750 VariantClear( &val
);
752 hr
= IWbemClassObject_Get( param
, L
"Type", 0, &val
, NULL
, NULL
);
753 if (hr
!= S_OK
) goto error
;
754 columns
[i
].type
= V_UI4( &val
);
756 hr
= IWbemClassObject_Get( param
, L
"DefaultValue", 0, &val
, NULL
, NULL
);
757 if (hr
!= S_OK
) goto error
;
758 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
759 offset
+= get_type_size( columns
[i
].type
);
761 IWbemClassObject_Release( param
);
770 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
771 heap_free( columns
);
776 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
780 struct column
*columns
;
784 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
785 if (hr
!= S_OK
) return hr
;
787 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
789 free_columns( columns
, num_cols
);
791 return E_OUTOFMEMORY
;
793 if (!add_table( table
)) free_table( table
); /* already exists */
797 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
799 UINT len
= ARRAY_SIZE(L
"__%s_%s_%s") + ARRAY_SIZE(L
"OUT") + lstrlenW( class ) + lstrlenW( method
);
802 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
803 swprintf( ret
, len
, L
"__%s_%s_%s", class, method
, dir
== PARAM_IN
? L
"IN" : L
"OUT" );
804 return wcsupr( ret
);
807 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
808 IWbemClassObject
**sig
)
810 static const WCHAR selectW
[] = L
"SELECT * FROM __PARAMETERS WHERE Class='%s' AND Method='%s' AND Direction%s";
811 UINT len
= ARRAY_SIZE(selectW
) + ARRAY_SIZE(L
">=0");
812 IEnumWbemClassObject
*iter
;
816 len
+= lstrlenW( class ) + lstrlenW( method
);
817 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
818 swprintf( query
, len
, selectW
, class, method
, dir
>= 0 ? L
">=0" : L
"<=0" );
820 hr
= exec_query( query
, &iter
);
822 if (hr
!= S_OK
) return hr
;
824 if (!count_instances( iter
))
827 IEnumWbemClassObject_Release( iter
);
831 if (!(name
= build_signature_table_name( class, method
, dir
)))
833 IEnumWbemClassObject_Release( iter
);
834 return E_OUTOFMEMORY
;
836 hr
= create_signature_table( iter
, name
);
837 IEnumWbemClassObject_Release( iter
);
839 hr
= get_object( name
, sig
);
845 static HRESULT WINAPI
class_object_GetMethod(
846 IWbemClassObject
*iface
,
849 IWbemClassObject
**ppInSignature
,
850 IWbemClassObject
**ppOutSignature
)
852 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
853 IWbemClassObject
*in
, *out
;
856 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
858 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
859 if (hr
!= S_OK
) return hr
;
861 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
864 if (ppInSignature
) *ppInSignature
= in
;
865 else if (in
) IWbemClassObject_Release( in
);
866 if (ppOutSignature
) *ppOutSignature
= out
;
867 else if (out
) IWbemClassObject_Release( out
);
869 else IWbemClassObject_Release( in
);
873 static HRESULT WINAPI
class_object_PutMethod(
874 IWbemClassObject
*iface
,
877 IWbemClassObject
*pInSignature
,
878 IWbemClassObject
*pOutSignature
)
880 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
884 static HRESULT WINAPI
class_object_DeleteMethod(
885 IWbemClassObject
*iface
,
888 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
892 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
893 IWbemClassObject
*iface
,
896 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
898 TRACE("%p, %08x\n", iface
, lEnumFlags
);
900 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
902 co
->index_method
= 0;
906 static HRESULT WINAPI
class_object_NextMethod(
907 IWbemClassObject
*iface
,
910 IWbemClassObject
**ppInSignature
,
911 IWbemClassObject
**ppOutSignature
)
913 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
917 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
919 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
921 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
924 SysFreeString( method
);
927 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
930 SysFreeString( method
);
932 IWbemClassObject_Release( *ppInSignature
);
942 static HRESULT WINAPI
class_object_EndMethodEnumeration(
943 IWbemClassObject
*iface
)
945 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
947 TRACE("%p\n", iface
);
949 co
->index_method
= 0;
953 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
954 IWbemClassObject
*iface
,
956 IWbemQualifierSet
**ppQualSet
)
958 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
962 static HRESULT WINAPI
class_object_GetMethodOrigin(
963 IWbemClassObject
*iface
,
964 LPCWSTR wszMethodName
,
967 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
971 static const IWbemClassObjectVtbl class_object_vtbl
=
973 class_object_QueryInterface
,
975 class_object_Release
,
976 class_object_GetQualifierSet
,
980 class_object_GetNames
,
981 class_object_BeginEnumeration
,
983 class_object_EndEnumeration
,
984 class_object_GetPropertyQualifierSet
,
986 class_object_GetObjectText
,
987 class_object_SpawnDerivedClass
,
988 class_object_SpawnInstance
,
989 class_object_CompareTo
,
990 class_object_GetPropertyOrigin
,
991 class_object_InheritsFrom
,
992 class_object_GetMethod
,
993 class_object_PutMethod
,
994 class_object_DeleteMethod
,
995 class_object_BeginMethodEnumeration
,
996 class_object_NextMethod
,
997 class_object_EndMethodEnumeration
,
998 class_object_GetMethodQualifierSet
,
999 class_object_GetMethodOrigin
1002 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1003 struct record
*record
, IWbemClassObject
**obj
)
1005 struct class_object
*co
;
1007 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1009 co
= heap_alloc( sizeof(*co
) );
1010 if (!co
) return E_OUTOFMEMORY
;
1012 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1014 if (!name
) co
->name
= NULL
;
1015 else if (!(co
->name
= heap_strdupW( name
)))
1018 return E_OUTOFMEMORY
;
1022 co
->index_method
= 0;
1023 co
->index_property
= 0;
1024 co
->record
= record
;
1025 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1027 *obj
= &co
->IWbemClassObject_iface
;
1029 TRACE("returning iface %p\n", *obj
);