wbemprox: Implement StdRegProv.GetStringValue.

This commit is contained in:
Hans Leidekker 2012-10-15 10:46:09 +02:00 committed by Alexandre Julliard
parent e27801e93b
commit 60db122133
4 changed files with 150 additions and 13 deletions

View file

@ -303,8 +303,9 @@ static const struct column col_sounddevice[] =
};
static const struct column col_stdregprov[] =
{
{ method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
{ method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
{ method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
{ method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
{ method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
};
static const struct column col_videocontroller[] =
{
@ -481,6 +482,7 @@ struct record_stdregprov
{
class_method *enumkey;
class_method *enumvalues;
class_method *getstringvalue;
};
struct record_videocontroller
{
@ -520,7 +522,12 @@ static const struct record_params data_params[] =
{ class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
{ class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
{ class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
{ class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
{ class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
{ class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
{ class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
{ class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
{ class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
{ class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
};
static const struct record_sounddevice data_sounddevice[] =
{
@ -528,7 +535,7 @@ static const struct record_sounddevice data_sounddevice[] =
};
static const struct record_stdregprov data_stdregprov[] =
{
{ reg_enumkey, reg_enumvalues }
{ reg_enum_key, reg_enum_values, reg_get_stringvalue }
};
static UINT get_processor_count(void)

View file

@ -70,7 +70,7 @@ static HRESULT to_i4_array( DWORD *values, DWORD count, VARIANT *var )
return S_OK;
}
static HRESULT enumkey( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *retval )
static HRESULT enum_key( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *retval )
{
HKEY hkey;
HRESULT hr = S_OK;
@ -121,7 +121,7 @@ static HRESULT enumkey( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT
return hr;
}
HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
HRESULT reg_enum_key( IWbemClassObject *in, IWbemClassObject **out )
{
VARIANT defkey, subkey, names, retval;
IWbemClassObject *sig;
@ -148,7 +148,7 @@ HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
return hr;
}
VariantInit( &names );
hr = enumkey( (HKEY)V_I4(&defkey), V_BSTR(&subkey), &names, &retval );
hr = enum_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, &retval );
if (hr != S_OK) goto done;
if (!V_UI4( &retval ))
{
@ -165,7 +165,7 @@ done:
return hr;
}
static HRESULT enumvalues( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, VARIANT *retval )
static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, VARIANT *retval )
{
HKEY hkey = NULL;
HRESULT hr = S_OK;
@ -219,7 +219,7 @@ done:
return hr;
}
HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
HRESULT reg_enum_values( IWbemClassObject *in, IWbemClassObject **out )
{
VARIANT defkey, subkey, names, types, retval;
IWbemClassObject *sig;
@ -247,7 +247,7 @@ HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
}
VariantInit( &names );
VariantInit( &types );
hr = enumvalues( (HKEY)V_I4(&defkey), V_BSTR(&subkey), &names, &types, &retval );
hr = enum_values( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, &types, &retval );
if (hr != S_OK) goto done;
if (!V_UI4( &retval ))
{
@ -266,3 +266,75 @@ done:
if (hr != S_OK) IWbemClassObject_Release( *out );
return hr;
}
static HRESULT get_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value, VARIANT *retval )
{
HRESULT hr = S_OK;
WCHAR *buf = NULL;
DWORD size;
LONG res;
TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
if ((res = RegGetValueW( root, subkey, name, RRF_RT_REG_SZ, NULL, NULL, &size ))) goto done;
if (!(buf = heap_alloc( size )))
{
hr = E_OUTOFMEMORY;
goto done;
}
if (!(res = RegGetValueW( root, subkey, name, RRF_RT_REG_SZ, NULL, buf, &size )))
set_variant( VT_BSTR, 0, buf, value );
done:
set_variant( VT_UI4, res, NULL, retval );
heap_free( buf );
return hr;
}
HRESULT reg_get_stringvalue( IWbemClassObject *in, IWbemClassObject **out )
{
VARIANT defkey, subkey, name, value, retval;
IWbemClassObject *sig;
HRESULT hr;
TRACE("%p, %p\n", in, out);
hr = IWbemClassObject_Get( in, param_defkeyW, 0, &defkey, NULL, NULL );
if (hr != S_OK) return hr;
hr = IWbemClassObject_Get( in, param_subkeynameW, 0, &subkey, NULL, NULL );
if (hr != S_OK) return hr;
hr = IWbemClassObject_Get( in, param_valuenameW, 0, &name, NULL, NULL );
if (hr != S_OK) return hr;
hr = create_signature( class_stdregprovW, method_getstringvalueW, PARAM_OUT, &sig );
if (hr != S_OK)
{
VariantClear( &name );
VariantClear( &subkey );
return hr;
}
hr = IWbemClassObject_SpawnInstance( sig, 0, out );
if (hr != S_OK)
{
VariantClear( &name );
VariantClear( &subkey );
IWbemClassObject_Release( sig );
return hr;
}
VariantInit( &value );
hr = get_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, &retval );
if (hr != S_OK) goto done;
if (!V_UI4( &retval ))
{
hr = IWbemClassObject_Put( *out, param_valueW, 0, &value, CIM_STRING );
if (hr != S_OK) goto done;
}
hr = IWbemClassObject_Put( *out, param_returnvalueW, 0, &retval, CIM_UINT32 );
done:
VariantClear( &name );
VariantClear( &subkey );
IWbemClassObject_Release( sig );
if (hr != S_OK) IWbemClassObject_Release( *out );
return hr;
}

View file

@ -129,18 +129,22 @@ static void test_StdRegProv( IWbemServices *services )
{
static const WCHAR enumkeyW[] = {'E','n','u','m','K','e','y',0};
static const WCHAR enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
static const WCHAR getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
static const WCHAR stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
static const WCHAR defkeyW[] = {'h','D','e','f','K','e','y',0};
static const WCHAR subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
static const WCHAR namesW[] = {'s','N','a','m','e','s',0};
static const WCHAR typesW[] = {'T','y','p','e','s',0};
static const WCHAR valueW[] = {'s','V','a','l','u','e',0};
static const WCHAR valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};
static const WCHAR programfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
static const WCHAR windowsW[] =
{'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
BSTR class = SysAllocString( stdregprovW ), method;
IWbemClassObject *reg, *sig_in, *sig_out, *in, *out;
VARIANT defkey, subkey, retval, names, types;
VARIANT defkey, subkey, retval, names, types, value, valuename;
CIMTYPE type;
HRESULT hr;
@ -246,6 +250,56 @@ static void test_StdRegProv( IWbemServices *services )
IWbemClassObject_Release( sig_in );
IWbemClassObject_Release( sig_out );
hr = IWbemClassObject_GetMethod( reg, getstringvalueW, 0, &sig_in, &sig_out );
ok( hr == S_OK, "failed to get GetStringValue method %08x\n", hr );
hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
V_VT( &defkey ) = VT_I4;
V_I4( &defkey ) = 0x80000002;
hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
ok( hr == S_OK, "failed to set root %08x\n", hr );
V_VT( &subkey ) = VT_BSTR;
V_BSTR( &subkey ) = SysAllocString( windowsW );
hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
ok( hr == S_OK, "failed to set subkey %08x\n", hr );
V_VT( &valuename ) = VT_BSTR;
V_BSTR( &valuename ) = SysAllocString( programfilesW );
hr = IWbemClassObject_Put( in, valuenameW, 0, &valuename, 0 );
ok( hr == S_OK, "failed to set value name %08x\n", hr );
out = NULL;
method = SysAllocString( getstringvalueW );
hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
ok( hr == S_OK, "failed to execute method %08x\n", hr );
SysFreeString( method );
type = 0xdeadbeef;
VariantInit( &retval );
hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
ok( hr == S_OK, "failed to get return value %08x\n", hr );
ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
type = 0xdeadbeef;
VariantInit( &value );
hr = IWbemClassObject_Get( out, valueW, 0, &value, &type, NULL );
ok( hr == S_OK, "failed to get value %08x\n", hr );
ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
VariantClear( &value );
VariantClear( &valuename );
VariantClear( &subkey );
IWbemClassObject_Release( in );
IWbemClassObject_Release( out );
IWbemClassObject_Release( sig_in );
IWbemClassObject_Release( sig_out );
IWbemClassObject_Release( reg );
SysFreeString( class );
}

View file

@ -196,8 +196,9 @@ HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT reg_enumkey(IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_enumvalues(IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_enum_key(IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_enum_values(IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_get_stringvalue(IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc( size_t len )
@ -234,9 +235,12 @@ static const WCHAR class_stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v
static const WCHAR method_enumkeyW[] = {'E','n','u','m','K','e','y',0};
static const WCHAR method_enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
static const WCHAR method_getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
static const WCHAR param_defkeyW[] = {'h','D','e','f','K','e','y',0};
static const WCHAR param_namesW[] = {'s','N','a','m','e','s',0};
static const WCHAR param_returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
static const WCHAR param_subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
static const WCHAR param_typesW[] = {'T','y','p','e','s',0};
static const WCHAR param_valueW[] = {'s','V','a','l','u','e',0};
static const WCHAR param_valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};