wbemdisp: Use wide-char string literals.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2020-11-29 23:30:32 +01:00 committed by Alexandre Julliard
parent 3093ac8b09
commit 2863952c1d
3 changed files with 25 additions and 54 deletions

View File

@ -436,14 +436,13 @@ static HRESULT WINAPI propertyset_Item( ISWbemPropertySet *iface, BSTR name,
static HRESULT WINAPI propertyset_get_Count( ISWbemPropertySet *iface, LONG *count ) static HRESULT WINAPI propertyset_get_Count( ISWbemPropertySet *iface, LONG *count )
{ {
static const WCHAR propcountW[] = {'_','_','P','R','O','P','E','R','T','Y','_','C','O','U','N','T',0};
struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface ); struct propertyset *propertyset = impl_from_ISWbemPropertySet( iface );
HRESULT hr; HRESULT hr;
VARIANT val; VARIANT val;
TRACE( "%p, %p\n", propertyset, count ); TRACE( "%p, %p\n", propertyset, count );
hr = IWbemClassObject_Get( propertyset->object, propcountW, 0, &val, NULL, NULL ); hr = IWbemClassObject_Get( propertyset->object, L"__PROPERTY_COUNT", 0, &val, NULL, NULL );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
*count = V_I4( &val ); *count = V_I4( &val );
@ -1701,12 +1700,11 @@ static HRESULT WINAPI services_DeleteAsync(
static BSTR build_query_string( const WCHAR *class ) static BSTR build_query_string( const WCHAR *class )
{ {
static const WCHAR selectW[] = {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0}; UINT len = lstrlenW(class) + ARRAY_SIZE(L"SELECT * FROM ");
UINT len = lstrlenW(class) + ARRAY_SIZE(selectW);
BSTR ret; BSTR ret;
if (!(ret = SysAllocStringLen( NULL, len ))) return NULL; if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
lstrcpyW( ret, selectW ); lstrcpyW( ret, L"SELECT * FROM " );
lstrcatW( ret, class ); lstrcatW( ret, class );
return ret; return ret;
} }
@ -1718,8 +1716,7 @@ static HRESULT WINAPI services_InstancesOf(
IDispatch *objWbemNamedValueSet, IDispatch *objWbemNamedValueSet,
ISWbemObjectSet **objWbemObjectSet ) ISWbemObjectSet **objWbemObjectSet )
{ {
static const WCHAR wqlW[] = {'W','Q','L',0}; BSTR query, wql = SysAllocString( L"WQL" );
BSTR query, wql = SysAllocString( wqlW );
HRESULT hr; HRESULT hr;
TRACE( "%p, %s, %x, %p, %p\n", iface, debugstr_w(strClass), iFlags, objWbemNamedValueSet, TRACE( "%p, %s, %x, %p, %p\n", iface, debugstr_w(strClass), iFlags, objWbemNamedValueSet,
@ -2128,14 +2125,13 @@ static HRESULT WINAPI locator_Invoke(
static BSTR build_resource_string( BSTR server, BSTR namespace ) static BSTR build_resource_string( BSTR server, BSTR namespace )
{ {
static const WCHAR defaultW[] = {'r','o','o','t','\\','d','e','f','a','u','l','t',0};
ULONG len, len_server = 0, len_namespace = 0; ULONG len, len_server = 0, len_namespace = 0;
BSTR ret; BSTR ret;
if (server && *server) len_server = lstrlenW( server ); if (server && *server) len_server = lstrlenW( server );
else len_server = 1; else len_server = 1;
if (namespace && *namespace) len_namespace = lstrlenW( namespace ); if (namespace && *namespace) len_namespace = lstrlenW( namespace );
else len_namespace = ARRAY_SIZE(defaultW) - 1; else len_namespace = ARRAY_SIZE(L"root\\default") - 1;
if (!(ret = SysAllocStringLen( NULL, 2 + len_server + 1 + len_namespace ))) return NULL; if (!(ret = SysAllocStringLen( NULL, 2 + len_server + 1 + len_namespace ))) return NULL;
@ -2147,7 +2143,7 @@ static BSTR build_resource_string( BSTR server, BSTR namespace )
ret[len++] = '\\'; ret[len++] = '\\';
if (namespace && *namespace) lstrcpyW( ret + len, namespace ); if (namespace && *namespace) lstrcpyW( ret + len, namespace );
else lstrcpyW( ret + len, defaultW ); else lstrcpyW( ret + len, L"root\\default" );
return ret; return ret;
} }

View File

@ -129,8 +129,7 @@ done:
static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName, static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
ULONG *pchEaten, IMoniker **ppmkOut) ULONG *pchEaten, IMoniker **ppmkOut)
{ {
static const WCHAR prefixW[] = {'w','i','n','m','g','m','t','s',':',0}; const DWORD prefix_len = ARRAY_SIZE(L"winmgmts:") - 1;
const DWORD prefix_len = ARRAY_SIZE(prefixW) - 1;
ISWbemLocator *locator = NULL; ISWbemLocator *locator = NULL;
ISWbemServices *services = NULL; ISWbemServices *services = NULL;
ISWbemObject *obj = NULL; ISWbemObject *obj = NULL;
@ -140,7 +139,7 @@ static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindC
TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut ); TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
if (wcsnicmp( pszDisplayName, prefixW, prefix_len )) return MK_E_SYNTAX; if (wcsnicmp( pszDisplayName, L"winmgmts:", prefix_len )) return MK_E_SYNTAX;
p = pszDisplayName + prefix_len; p = pszDisplayName + prefix_len;
if (*p == '{') if (*p == '{')

View File

@ -34,26 +34,10 @@ static const LCID english = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US)
static void test_ParseDisplayName(void) static void test_ParseDisplayName(void)
{ {
static const WCHAR biosW[] = {'W','i','n','3','2','_','B','i','o','s',0}; static const WCHAR name1[] = L"winmgmts:";
static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0}; static const WCHAR name2[] = L"winmgmts:\\\\.\\root\\cimv2";
static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0}; static const WCHAR name3[] = L"winmgmts:\\\\.\\root\\cimv2:Win32_LogicalDisk.DeviceID='C:'";
static const WCHAR nosuchW[] = {'N','o','S','u','c','h',0}; static const WCHAR name4[] = L"winmgmts:\\\\.\\root\\cimv2:Win32_Service";
static const WCHAR name1[] =
{'w','i','n','m','g','m','t','s',':',0};
static const WCHAR name2[] =
{'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
static const WCHAR name3[] =
{'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':',
'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k','.',
'D','e','v','i','c','e','I','D','=','\'','C',':','\'',0};
static const WCHAR name4[] =
{'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':',
'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
static const WCHAR stdregprovW[] =
{'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','d','e','f','a','u','l','t',':',
'S','t','d','R','e','g','P','r','o','v',0};
static const WCHAR getstringvalueW[] =
{'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
static const struct static const struct
{ {
const WCHAR *name; const WCHAR *name;
@ -130,7 +114,7 @@ static void test_ParseDisplayName(void)
{ {
ISWbemObjectSet *objectset = NULL; ISWbemObjectSet *objectset = NULL;
str = SysAllocString( biosW ); str = SysAllocString( L"Win32_Bios" );
hr = ISWbemServices_InstancesOf( services, str, 0, NULL, &objectset ); hr = ISWbemServices_InstancesOf( services, str, 0, NULL, &objectset );
SysFreeString( str ); SysFreeString( str );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
@ -174,28 +158,28 @@ static void test_ParseDisplayName(void)
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( count == 1, "got %u\n", count ); ok( count == 1, "got %u\n", count );
str = SysAllocString( manufacturerW ); str = SysAllocString( L"Manufacturer" );
dispid = 0xdeadbeef; dispid = 0xdeadbeef;
hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid ); hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
SysFreeString( str ); SysFreeString( str );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( dispid == 0x1800001 || dispid == 0x10b /* win2k */, "got %x\n", dispid ); ok( dispid == 0x1800001 || dispid == 0x10b /* win2k */, "got %x\n", dispid );
str = SysAllocString( versionW ); str = SysAllocString( L"version" );
dispid = 0xdeadbeef; dispid = 0xdeadbeef;
hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid ); hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
SysFreeString( str ); SysFreeString( str );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( dispid == 0x1800002 || dispid == 0x119 /* win2k */, "got %x\n", dispid ); ok( dispid == 0x1800002 || dispid == 0x119 /* win2k */, "got %x\n", dispid );
str = SysAllocString( nosuchW ); str = SysAllocString( L"NoSuch" );
dispid = 0xdeadbeef; dispid = 0xdeadbeef;
hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid ); hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
SysFreeString( str ); SysFreeString( str );
ok( hr == DISP_E_UNKNOWNNAME, "got %x\n", hr ); ok( hr == DISP_E_UNKNOWNNAME, "got %x\n", hr );
ok( dispid == DISPID_UNKNOWN, "got %x\n", dispid ); ok( dispid == DISPID_UNKNOWN, "got %x\n", dispid );
str = SysAllocString( manufacturerW ); str = SysAllocString( L"Manufacturer" );
dispid = 0xdeadbeef; dispid = 0xdeadbeef;
hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid ); hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
SysFreeString( str ); SysFreeString( str );
@ -261,7 +245,7 @@ static void test_ParseDisplayName(void)
hr = CreateBindCtx( 0, &ctx ); hr = CreateBindCtx( 0, &ctx );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
str = SysAllocString( stdregprovW ); str = SysAllocString( L"winmgmts:\\\\.\\root\\default:StdRegProv" );
hr = IParseDisplayName_ParseDisplayName( displayname, NULL, str, &eaten, &moniker ); hr = IParseDisplayName_ParseDisplayName( displayname, NULL, str, &eaten, &moniker );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
SysFreeString( str ); SysFreeString( str );
@ -280,7 +264,7 @@ static void test_ParseDisplayName(void)
{ {
DISPID dispid = 0xdeadbeef; DISPID dispid = 0xdeadbeef;
str = SysAllocString( getstringvalueW ); str = SysAllocString( L"GetStringValue" );
hr = ISWbemObject_GetIDsOfNames( sobj, &IID_NULL, &str, 1, english, &dispid ); hr = ISWbemObject_GetIDsOfNames( sobj, &IID_NULL, &str, 1, english, &dispid );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( dispid == 0x1000001, "got %x\n", dispid ); ok( dispid == 0x1000001, "got %x\n", dispid );
@ -295,14 +279,6 @@ static void test_ParseDisplayName(void)
IParseDisplayName_Release( displayname ); IParseDisplayName_Release( displayname );
} }
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR root[] = {'r','o','o','t','\\','C','I','M','V','2',0};
static const WCHAR query[] = {'S','e','l','e','c','t',' ','P','r','o','c','e','s','s','o','r','I','d',' ','f','r','o','m',
' ','W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
static const WCHAR lang[] = {'W','Q','L',0};
static const WCHAR props[] = {'P','r','o','p','e','r','t','i','e','s','_',0};
static const WCHAR procid[] = {'P','r','o','c','e','s','s','o','r','I','d',0};
static void test_locator(void) static void test_locator(void)
{ {
HRESULT hr; HRESULT hr;
@ -324,15 +300,15 @@ static void test_locator(void)
hr = CoCreateInstance( &CLSID_SWbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_ISWbemLocator, (void **)&locator ); hr = CoCreateInstance( &CLSID_SWbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_ISWbemLocator, (void **)&locator );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
host_bstr = SysAllocString(localhost); host_bstr = SysAllocString( L"localhost" );
root_bstr = SysAllocString(root); root_bstr = SysAllocString( L"root\\CIMV2" );
hr = ISWbemLocator_ConnectServer( locator, host_bstr, root_bstr, NULL, NULL, NULL, NULL, 0, NULL, &services); hr = ISWbemLocator_ConnectServer( locator, host_bstr, root_bstr, NULL, NULL, NULL, NULL, 0, NULL, &services);
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
SysFreeString( root_bstr ); SysFreeString( root_bstr );
SysFreeString( host_bstr ); SysFreeString( host_bstr );
query_bstr = SysAllocString(query); query_bstr = SysAllocString( L"Select ProcessorId from Win32_Processor" );
lang_bstr = SysAllocString(lang); lang_bstr = SysAllocString( L"WQL" );
hr = ISWbemServices_ExecQuery( services, query_bstr, lang_bstr, wbemFlagForwardOnly, NULL, &object_set); hr = ISWbemServices_ExecQuery( services, query_bstr, lang_bstr, wbemFlagForwardOnly, NULL, &object_set);
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
SysFreeString( lang_bstr ); SysFreeString( lang_bstr );
@ -374,7 +350,7 @@ static void test_locator(void)
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( V_VT(&var) == VT_DISPATCH, "got %x\n", V_VT(&var)); ok( V_VT(&var) == VT_DISPATCH, "got %x\n", V_VT(&var));
props_bstr = SysAllocString( props ); props_bstr = SysAllocString( L"Properties_" );
hr = IDispatch_GetIDsOfNames( V_DISPATCH(&var), &IID_NULL, &props_bstr, 1, english, &id ); hr = IDispatch_GetIDsOfNames( V_DISPATCH(&var), &IID_NULL, &props_bstr, 1, english, &id );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
ok( id == 21, "got %d\n", id ); ok( id == 21, "got %d\n", id );
@ -390,7 +366,7 @@ static void test_locator(void)
ok( hr == WBEM_E_NOT_FOUND, "got %x\n", hr ); ok( hr == WBEM_E_NOT_FOUND, "got %x\n", hr );
SysFreeString( props_bstr ); SysFreeString( props_bstr );
procid_bstr = SysAllocString( procid ); procid_bstr = SysAllocString( L"ProcessorId" );
hr = ISWbemPropertySet_Item( prop_set, procid_bstr, 0, &prop ); hr = ISWbemPropertySet_Item( prop_set, procid_bstr, 0, &prop );
ok( hr == S_OK, "got %x\n", hr ); ok( hr == S_OK, "got %x\n", hr );
SysFreeString( procid_bstr ); SysFreeString( procid_bstr );