wbemprox: Add a partial StdRegProv class implementation.
[wine/multimedia.git] / dlls / wbemprox / query.c
blobb6b74efee3f4aa4128207692edc4da69e775b991
1 /*
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
19 #define COBJMACROS
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wbemcli.h"
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33 static HRESULT get_column_index( const struct table *table, const WCHAR *name, UINT *column )
35 UINT i;
36 for (i = 0; i < table->num_cols; i++)
38 if (!strcmpiW( table->columns[i].name, name ))
40 *column = i;
41 return S_OK;
44 return WBEM_E_INVALID_QUERY;
47 static UINT get_column_size( const struct table *table, UINT column )
49 if (table->columns[column].type & CIM_FLAG_ARRAY) return sizeof(void *);
51 switch (table->columns[column].type & COL_TYPE_MASK)
53 case CIM_SINT16:
54 case CIM_UINT16:
55 return sizeof(INT16);
56 case CIM_SINT32:
57 case CIM_UINT32:
58 return sizeof(INT32);
59 case CIM_SINT64:
60 case CIM_UINT64:
61 return sizeof(INT64);
62 case CIM_DATETIME:
63 case CIM_STRING:
64 return sizeof(WCHAR *);
65 default:
66 ERR("unknown column type %u\n", table->columns[column].type & COL_TYPE_MASK);
67 break;
69 return sizeof(INT32);
72 static UINT get_column_offset( const struct table *table, UINT column )
74 UINT i, offset = 0;
75 for (i = 0; i < column; i++) offset += get_column_size( table, i );
76 return offset;
79 static UINT get_row_size( const struct table *table )
81 return get_column_offset( table, table->num_cols - 1 ) + get_column_size( table, table->num_cols - 1 );
84 static HRESULT get_value( const struct table *table, UINT row, UINT column, LONGLONG *val )
86 UINT col_offset, row_size;
87 const BYTE *ptr;
89 col_offset = get_column_offset( table, column );
90 row_size = get_row_size( table );
91 ptr = table->data + row * row_size + col_offset;
93 if (table->columns[column].type & CIM_FLAG_ARRAY)
95 *val = (LONGLONG)(INT_PTR)*(const void **)ptr;
96 return S_OK;
98 switch (table->columns[column].type & COL_TYPE_MASK)
100 case CIM_DATETIME:
101 case CIM_STRING:
102 *val = (LONGLONG)(INT_PTR)*(const WCHAR **)ptr;
103 break;
104 case CIM_SINT16:
105 *val = *(const INT16 *)ptr;
106 break;
107 case CIM_UINT16:
108 *val = *(const UINT16 *)ptr;
109 break;
110 case CIM_SINT32:
111 *val = *(const INT32 *)ptr;
112 break;
113 case CIM_UINT32:
114 *val = *(const UINT32 *)ptr;
115 break;
116 case CIM_SINT64:
117 *val = *(const INT64 *)ptr;
118 break;
119 case CIM_UINT64:
120 *val = *(const UINT64 *)ptr;
121 break;
122 default:
123 ERR("invalid column type %u\n", table->columns[column].type & COL_TYPE_MASK);
124 *val = 0;
125 break;
127 return S_OK;
130 static BSTR get_value_bstr( const struct table *table, UINT row, UINT column )
132 static const WCHAR fmt_signedW[] = {'%','d',0};
133 static const WCHAR fmt_unsignedW[] = {'%','u',0};
134 static const WCHAR fmt_signed64W[] = {'%','I','6','4','d',0};
135 static const WCHAR fmt_unsigned64W[] = {'%','I','6','4','u',0};
136 static const WCHAR fmt_strW[] = {'\"','%','s','\"',0};
137 LONGLONG val;
138 BSTR ret;
139 WCHAR number[22];
140 UINT len;
142 if (table->columns[column].type & CIM_FLAG_ARRAY)
144 FIXME("array to string conversion not handled\n");
145 return NULL;
147 if (get_value( table, row, column, &val ) != S_OK) return NULL;
149 switch (table->columns[column].type & COL_TYPE_MASK)
151 case CIM_DATETIME:
152 case CIM_STRING:
153 len = strlenW( (const WCHAR *)(INT_PTR)val ) + 2;
154 if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
155 sprintfW( ret, fmt_strW, (const WCHAR *)(INT_PTR)val );
156 return ret;
158 case CIM_SINT16:
159 case CIM_SINT32:
160 sprintfW( number, fmt_signedW, val );
161 return SysAllocString( number );
163 case CIM_UINT16:
164 case CIM_UINT32:
165 sprintfW( number, fmt_unsignedW, val );
166 return SysAllocString( number );
168 case CIM_SINT64:
169 wsprintfW( number, fmt_signed64W, val );
170 return SysAllocString( number );
172 case CIM_UINT64:
173 wsprintfW( number, fmt_unsigned64W, val );
174 return SysAllocString( number );
176 default:
177 FIXME("unhandled column type %u\n", table->columns[column].type & COL_TYPE_MASK);
178 break;
180 return NULL;
183 HRESULT create_view( const struct property *proplist, const WCHAR *class,
184 const struct expr *cond, struct view **ret )
186 struct view *view = heap_alloc( sizeof(struct view) );
188 if (!view) return E_OUTOFMEMORY;
189 view->proplist = proplist;
190 view->table = get_table( class );
191 view->cond = cond;
192 view->result = NULL;
193 view->count = 0;
194 *ret = view;
195 return S_OK;
198 static void clear_table( struct table *table )
200 UINT i, j, type;
202 if (!table->fill || !table->data) return;
204 for (i = 0; i < table->num_rows; i++)
206 for (j = 0; j < table->num_cols; j++)
208 if (!(table->columns[j].type & COL_FLAG_DYNAMIC)) continue;
210 type = table->columns[j].type & COL_TYPE_MASK;
211 if (type == CIM_STRING || type == CIM_DATETIME || (type & CIM_FLAG_ARRAY))
213 void *ptr;
214 if (get_value( table, i, j, (LONGLONG *)&ptr ) == S_OK) heap_free( ptr );
218 heap_free( table->data );
219 table->data = NULL;
222 void destroy_view( struct view *view )
224 if (view->table) clear_table( view->table );
225 heap_free( view->result );
226 heap_free( view );
229 static BOOL eval_like( const WCHAR *lstr, const WCHAR *rstr )
231 const WCHAR *p = lstr, *q = rstr;
233 while (*p && *q)
235 if (*q == '%')
237 while (*q == '%') q++;
238 if (!*q) return TRUE;
239 while (*p && toupperW( p[1] ) != toupperW( q[1] )) p++;
240 if (!*p) return TRUE;
242 if (toupperW( *p++ ) != toupperW( *q++ )) return FALSE;
244 return TRUE;
247 static HRESULT eval_strcmp( UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val )
249 switch (op)
251 case OP_EQ:
252 *val = !strcmpW( lstr, rstr );
253 break;
254 case OP_GT:
255 *val = strcmpW( lstr, rstr ) > 0;
256 break;
257 case OP_LT:
258 *val = strcmpW( lstr, rstr ) < 0;
259 break;
260 case OP_LE:
261 *val = strcmpW( lstr, rstr ) <= 0;
262 break;
263 case OP_GE:
264 *val = strcmpW( lstr, rstr ) >= 0;
265 break;
266 case OP_NE:
267 *val = strcmpW( lstr, rstr );
268 break;
269 case OP_LIKE:
270 *val = eval_like( lstr, rstr );
271 break;
272 default:
273 ERR("unhandled operator %u\n", op);
274 return WBEM_E_INVALID_QUERY;
276 return S_OK;
279 static inline BOOL is_strcmp( const struct complex_expr *expr )
281 return ((expr->left->type == EXPR_PROPVAL && expr->right->type == EXPR_SVAL) ||
282 (expr->left->type == EXPR_SVAL && expr->right->type == EXPR_PROPVAL));
285 static HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG * );
287 static HRESULT eval_binary( const struct table *table, UINT row, const struct complex_expr *expr,
288 LONGLONG *val )
290 HRESULT lret, rret;
291 LONGLONG lval, rval;
293 lret = eval_cond( table, row, expr->left, &lval );
294 rret = eval_cond( table, row, expr->right, &rval );
295 if (lret != S_OK || rret != S_OK) return WBEM_E_INVALID_QUERY;
297 if (is_strcmp( expr ))
299 const WCHAR *lstr = (const WCHAR *)(INT_PTR)lval;
300 const WCHAR *rstr = (const WCHAR *)(INT_PTR)rval;
302 return eval_strcmp( expr->op, lstr, rstr, val );
304 switch (expr->op)
306 case OP_EQ:
307 *val = (lval == rval);
308 break;
309 case OP_AND:
310 *val = (lval && rval);
311 break;
312 case OP_OR:
313 *val = (lval || rval);
314 break;
315 case OP_GT:
316 *val = (lval > rval);
317 break;
318 case OP_LT:
319 *val = (lval < rval);
320 break;
321 case OP_LE:
322 *val = (lval <= rval);
323 break;
324 case OP_GE:
325 *val = (lval >= rval);
326 break;
327 case OP_NE:
328 *val = (lval != rval);
329 break;
330 default:
331 ERR("unhandled operator %u\n", expr->op);
332 return WBEM_E_INVALID_QUERY;
334 return S_OK;
337 static HRESULT eval_unary( const struct table *table, UINT row, const struct complex_expr *expr,
338 LONGLONG *val )
341 HRESULT hr;
342 UINT column;
343 LONGLONG lval;
345 hr = get_column_index( table, expr->left->u.propval->name, &column );
346 if (hr != S_OK)
347 return hr;
349 hr = get_value( table, row, column, &lval );
350 if (hr != S_OK)
351 return hr;
353 switch (expr->op)
355 case OP_ISNULL:
356 *val = !lval;
357 break;
358 case OP_NOTNULL:
359 *val = lval;
360 break;
361 default:
362 ERR("unknown operator %u\n", expr->op);
363 return WBEM_E_INVALID_QUERY;
365 return S_OK;
368 static HRESULT eval_propval( const struct table *table, UINT row, const struct property *propval,
369 LONGLONG *val )
372 HRESULT hr;
373 UINT column;
375 hr = get_column_index( table, propval->name, &column );
376 if (hr != S_OK)
377 return hr;
379 return get_value( table, row, column, val );
382 static HRESULT eval_cond( const struct table *table, UINT row, const struct expr *cond,
383 LONGLONG *val )
385 if (!cond)
387 *val = 1;
388 return S_OK;
390 switch (cond->type)
392 case EXPR_COMPLEX:
393 return eval_binary( table, row, &cond->u.expr, val );
394 case EXPR_UNARY:
395 return eval_unary( table, row, &cond->u.expr, val );
396 case EXPR_PROPVAL:
397 return eval_propval( table, row, cond->u.propval, val );
398 case EXPR_SVAL:
399 *val = (LONGLONG)(INT_PTR)cond->u.sval;
400 return S_OK;
401 case EXPR_IVAL:
402 case EXPR_BVAL:
403 *val = cond->u.ival;
404 return S_OK;
405 default:
406 ERR("invalid expression type\n");
407 break;
409 return WBEM_E_INVALID_QUERY;
412 static HRESULT execute_view( struct view *view )
414 UINT i, j = 0, len;
416 if (!view->table || !view->table->num_rows) return S_OK;
418 len = min( view->table->num_rows, 16 );
419 if (!(view->result = heap_alloc( len * sizeof(UINT) ))) return E_OUTOFMEMORY;
421 for (i = 0; i < view->table->num_rows; i++)
423 HRESULT hr;
424 LONGLONG val = 0;
426 if (j >= len)
428 UINT *tmp;
429 len *= 2;
430 if (!(tmp = heap_realloc( view->result, len * sizeof(UINT) ))) return E_OUTOFMEMORY;
431 view->result = tmp;
433 if ((hr = eval_cond( view->table, i, view->cond, &val )) != S_OK) return hr;
434 if (val) view->result[j++] = i;
436 view->count = j;
437 return S_OK;
440 static struct query *create_query(void)
442 struct query *query;
444 if (!(query = heap_alloc( sizeof(*query) ))) return NULL;
445 list_init( &query->mem );
446 query->refs = 1;
447 return query;
450 static void free_query( struct query *query )
452 struct list *mem, *next;
454 destroy_view( query->view );
455 LIST_FOR_EACH_SAFE( mem, next, &query->mem )
457 heap_free( mem );
459 heap_free( query );
462 void addref_query( struct query *query )
464 InterlockedIncrement( &query->refs );
467 void release_query( struct query *query )
469 if (!InterlockedDecrement( &query->refs )) free_query( query );
472 HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result )
474 HRESULT hr;
475 struct query *query;
477 *result = NULL;
478 if (!(query = create_query())) return E_OUTOFMEMORY;
479 hr = parse_query( str, &query->view, &query->mem );
480 if (hr != S_OK) goto done;
481 hr = execute_view( query->view );
482 if (hr != S_OK) goto done;
483 hr = EnumWbemClassObject_create( NULL, query, (void **)result );
485 done:
486 release_query( query );
487 return hr;
490 static BOOL is_selected_prop( const struct view *view, const WCHAR *name )
492 const struct property *prop = view->proplist;
494 if (!prop) return TRUE;
495 while (prop)
497 if (!strcmpiW( prop->name, name )) return TRUE;
498 prop = prop->next;
500 return FALSE;
503 static BOOL is_system_prop( const WCHAR *name )
505 return (name[0] == '_' && name[1] == '_');
508 static BSTR build_servername( const struct view *view )
510 WCHAR server[MAX_COMPUTERNAME_LENGTH + 1], *p;
511 DWORD len = sizeof(server)/sizeof(server[0]);
513 if (view->proplist) return NULL;
515 if (!(GetComputerNameW( server, &len ))) return NULL;
516 for (p = server; *p; p++) *p = toupperW( *p );
517 return SysAllocString( server );
520 static BSTR build_classname( const struct view *view )
522 return SysAllocString( view->table->name );
525 static BSTR build_namespace( const struct view *view )
527 static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
529 if (view->proplist) return NULL;
530 return SysAllocString( cimv2W );
533 static BSTR build_proplist( const struct view *view, UINT index, UINT count, UINT *len )
535 static const WCHAR fmtW[] = {'%','s','=','%','s',0};
536 UINT i, j, offset, row = view->result[index];
537 BSTR *values, ret = NULL;
539 if (!(values = heap_alloc( count * sizeof(BSTR) ))) return NULL;
541 *len = j = 0;
542 for (i = 0; i < view->table->num_cols; i++)
544 if (view->table->columns[i].type & COL_FLAG_KEY)
546 const WCHAR *name = view->table->columns[i].name;
548 values[j] = get_value_bstr( view->table, row, i );
549 *len += strlenW( fmtW ) + strlenW( name ) + strlenW( values[j] );
550 j++;
553 if ((ret = SysAllocStringLen( NULL, *len )))
555 offset = j = 0;
556 for (i = 0; i < view->table->num_cols; i++)
558 if (view->table->columns[i].type & COL_FLAG_KEY)
560 const WCHAR *name = view->table->columns[i].name;
562 offset += sprintfW( ret + offset, fmtW, name, values[j] );
563 if (j < count - 1) ret[offset++] = ',';
564 j++;
568 for (i = 0; i < count; i++) SysFreeString( values[i] );
569 heap_free( values );
570 return ret;
573 static UINT count_key_columns( const struct view *view )
575 UINT i, num_keys = 0;
577 for (i = 0; i < view->table->num_cols; i++)
579 if (view->table->columns[i].type & COL_FLAG_KEY) num_keys++;
581 return num_keys;
584 static BSTR build_relpath( const struct view *view, UINT index, const WCHAR *name )
586 static const WCHAR fmtW[] = {'%','s','.','%','s',0};
587 BSTR class, proplist, ret = NULL;
588 UINT num_keys, len;
590 if (view->proplist) return NULL;
592 if (!(class = build_classname( view ))) return NULL;
593 if (!(num_keys = count_key_columns( view ))) return class;
594 if (!(proplist = build_proplist( view, index, num_keys, &len ))) goto done;
596 len += strlenW( fmtW ) + SysStringLen( class );
597 if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
598 sprintfW( ret, fmtW, class, proplist );
600 done:
601 SysFreeString( class );
602 SysFreeString( proplist );
603 return ret;
606 static BSTR build_path( const struct view *view, UINT index, const WCHAR *name )
608 static const WCHAR fmtW[] = {'\\','\\','%','s','\\','%','s',':','%','s',0};
609 BSTR server, namespace = NULL, relpath = NULL, ret = NULL;
610 UINT len;
612 if (view->proplist) return NULL;
614 if (!(server = build_servername( view ))) return NULL;
615 if (!(namespace = build_namespace( view ))) goto done;
616 if (!(relpath = build_relpath( view, index, name ))) goto done;
618 len = strlenW( fmtW ) + SysStringLen( server ) + SysStringLen( namespace ) + SysStringLen( relpath );
619 if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
620 sprintfW( ret, fmtW, server, namespace, relpath );
622 done:
623 SysFreeString( server );
624 SysFreeString( namespace );
625 SysFreeString( relpath );
626 return ret;
629 static inline BOOL is_method( const struct table *table, UINT column )
631 return table->columns[column].type & COL_FLAG_METHOD;
634 static UINT count_properties( const struct view *view )
636 UINT i, num_props = 0;
638 for (i = 0; i < view->table->num_cols; i++)
640 if (!is_method( view->table, i)) num_props++;
642 return num_props;
645 static UINT count_selected_properties( const struct view *view )
647 const struct property *prop = view->proplist;
648 UINT count;
650 if (!prop) return count_properties( view );
652 count = 1;
653 while ((prop = prop->next)) count++;
654 return count;
657 static HRESULT get_system_propval( const struct view *view, UINT index, const WCHAR *name,
658 VARIANT *ret, CIMTYPE *type, LONG *flavor )
660 static const WCHAR classW[] = {'_','_','C','L','A','S','S',0};
661 static const WCHAR genusW[] = {'_','_','G','E','N','U','S',0};
662 static const WCHAR pathW[] = {'_','_','P','A','T','H',0};
663 static const WCHAR namespaceW[] = {'_','_','N','A','M','E','S','P','A','C','E',0};
664 static const WCHAR propcountW[] = {'_','_','P','R','O','P','E','R','T','Y','_','C','O','U','N','T',0};
665 static const WCHAR relpathW[] = {'_','_','R','E','L','P','A','T','H',0};
666 static const WCHAR serverW[] = {'_','_','S','E','R','V','E','R',0};
668 if (flavor) *flavor = WBEM_FLAVOR_ORIGIN_SYSTEM;
670 if (!strcmpiW( name, classW ))
672 V_VT( ret ) = VT_BSTR;
673 V_BSTR( ret ) = build_classname( view );
674 if (type) *type = CIM_STRING;
675 return S_OK;
677 if (!strcmpiW( name, genusW ))
679 V_VT( ret ) = VT_I4;
680 V_I4( ret ) = WBEM_GENUS_INSTANCE; /* FIXME */
681 if (type) *type = CIM_SINT32;
682 return S_OK;
684 else if (!strcmpiW( name, namespaceW ))
686 V_VT( ret ) = VT_BSTR;
687 V_BSTR( ret ) = build_namespace( view );
688 if (type) *type = CIM_STRING;
689 return S_OK;
691 else if (!strcmpiW( name, pathW ))
693 V_VT( ret ) = VT_BSTR;
694 V_BSTR( ret ) = build_path( view, index, name );
695 if (type) *type = CIM_STRING;
696 return S_OK;
698 if (!strcmpiW( name, propcountW ))
700 V_VT( ret ) = VT_I4;
701 V_I4( ret ) = count_selected_properties( view );
702 if (type) *type = CIM_SINT32;
703 return S_OK;
705 else if (!strcmpiW( name, relpathW ))
707 V_VT( ret ) = VT_BSTR;
708 V_BSTR( ret ) = build_relpath( view, index, name );
709 if (type) *type = CIM_STRING;
710 return S_OK;
712 else if (!strcmpiW( name, serverW ))
714 V_VT( ret ) = VT_BSTR;
715 V_BSTR( ret ) = build_servername( view );
716 if (type) *type = CIM_STRING;
717 return S_OK;
719 FIXME("system property %s not implemented\n", debugstr_w(name));
720 return WBEM_E_NOT_FOUND;
723 static void set_variant( VARTYPE vartype, LONGLONG val, BSTR val_bstr, VARIANT *ret )
725 switch (vartype)
727 case VT_BSTR:
728 V_VT( ret ) = VT_BSTR;
729 V_BSTR( ret ) = val_bstr;
730 return;
731 case VT_I2:
732 V_VT( ret ) = VT_I2;
733 V_I2( ret ) = val;
734 return;
735 case VT_UI2:
736 V_VT( ret ) = VT_UI2;
737 V_UI2( ret ) = val;
738 return;
739 case VT_I4:
740 V_VT( ret ) = VT_I4;
741 V_I4( ret ) = val;
742 return;
743 case VT_UI4:
744 V_VT( ret ) = VT_UI4;
745 V_UI4( ret ) = val;
746 return;
747 case VT_NULL:
748 V_VT( ret ) = VT_NULL;
749 return;
750 default:
751 ERR("unhandled variant type %u\n", vartype);
752 return;
756 HRESULT get_propval( const struct view *view, UINT index, const WCHAR *name, VARIANT *ret,
757 CIMTYPE *type, LONG *flavor )
759 HRESULT hr;
760 UINT column, row = view->result[index];
761 VARTYPE vartype;
762 BSTR val_bstr = NULL;
763 LONGLONG val;
765 if (is_system_prop( name )) return get_system_propval( view, index, name, ret, type, flavor );
766 if (!is_selected_prop( view, name )) return WBEM_E_NOT_FOUND;
768 hr = get_column_index( view->table, name, &column );
769 if (hr != S_OK || is_method( view->table, column )) return WBEM_E_NOT_FOUND;
771 vartype = view->table->columns[column].vartype;
773 hr = get_value( view->table, row, column, &val );
774 if (hr != S_OK) return hr;
776 switch (view->table->columns[column].type & COL_TYPE_MASK)
778 case CIM_STRING:
779 case CIM_DATETIME:
780 if (val)
782 vartype = VT_BSTR;
783 val_bstr = SysAllocString( (const WCHAR *)(INT_PTR)val );
785 else
786 vartype = VT_NULL;
787 break;
788 case CIM_SINT16:
789 if (!vartype) vartype = VT_I2;
790 break;
791 case CIM_UINT16:
792 if (!vartype) vartype = VT_UI2;
793 break;
794 case CIM_SINT32:
795 if (!vartype) vartype = VT_I4;
796 break;
797 case CIM_UINT32:
798 if (!vartype) vartype = VT_UI4;
799 break;
800 case CIM_SINT64:
801 vartype = VT_BSTR;
802 val_bstr = get_value_bstr( view->table, row, column );
803 break;
804 case CIM_UINT64:
805 vartype = VT_BSTR;
806 val_bstr = get_value_bstr( view->table, row, column );
807 break;
808 default:
809 ERR("unhandled column type %u\n", view->table->columns[column].type);
810 return WBEM_E_FAILED;
812 set_variant( vartype, val, val_bstr, ret );
813 if (type) *type = view->table->columns[column].type & COL_TYPE_MASK;
814 if (flavor) *flavor = 0;
815 return S_OK;
818 HRESULT get_properties( const struct view *view, SAFEARRAY **props )
820 SAFEARRAY *sa;
821 BSTR str;
822 LONG i;
823 UINT num_props = count_properties( view );
825 if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, num_props ))) return E_OUTOFMEMORY;
827 for (i = 0; i < view->table->num_cols; i++)
829 if (is_method( view->table, i )) continue;
831 str = SysAllocString( view->table->columns[i].name );
832 if (!str || SafeArrayPutElement( sa, &i, str ) != S_OK)
834 SysFreeString( str );
835 SafeArrayDestroy( sa );
836 return E_OUTOFMEMORY;
839 *props = sa;
840 return S_OK;