3030#include < windows.h>
3131#include < WbemIdl.h>
3232#include < comdef.h>
33+ #include < comutil.h> // For _bstr_t
3334#include < string>
3435#pragma comment(lib, "wbemuuid.lib")
3536#endif
@@ -102,7 +103,7 @@ void printSystemInfo()
102103 res &= CoCreateInstance (CLSID_WbemLocator, nullptr , CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator);
103104 if (locator)
104105 {
105- res &= locator->ConnectServer (_bstr_t (L" ROOT\\ CIMV2" ), nullptr , nullptr , nullptr , 0 , nullptr , nullptr , &service);
106+ res &= locator->ConnectServer (bstr_t (L" ROOT\\ CIMV2" ), nullptr , nullptr , nullptr , 0 , nullptr , nullptr , &service);
106107 if (service)
107108 {
108109 res &= CoSetProxyBlanket (service, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr , RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr , EOAC_NONE);
@@ -113,21 +114,21 @@ void printSystemInfo()
113114 IWbemClassObject* obj = nullptr ;
114115
115116 // CPU info
116- const std::wstring cpu_query (L" SELECT Name, NumberOfLogicalProcessors, MaxClockSpeed FROM Win32_Processor" );
117+ const std::wstring cpu_query (bstr_t ( L" SELECT Name, NumberOfLogicalProcessors, MaxClockSpeed FROM Win32_Processor" ) );
117118 service->ExecQuery (bstr_t (L" WQL" ), bstr_t (std::wstring (cpu_query.begin (), cpu_query.end ()).c_str ()), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr , &enumerator);
118119 while (enumerator)
119120 {
120121 enumerator->Next (WBEM_INFINITE, 1 , &obj, &u_return);
121122 if (!u_return)
122123 break ;
123124
124- hr = obj->Get (L" Name" , 0 , &vt_prop, nullptr , nullptr );
125+ hr = obj->Get (bstr_t ( L" Name" ) , 0 , &vt_prop, nullptr , nullptr );
125126 log (QString (" CPU name: %1" ).arg (vt_prop.bstrVal ));
126127
127- hr = obj->Get (L" MaxClockSpeed" , 0 , &vt_prop, nullptr , nullptr );
128+ hr = obj->Get (bstr_t ( L" MaxClockSpeed" ) , 0 , &vt_prop, nullptr , nullptr );
128129 log (QString (" CPU maximum speed: %1 MHz" ).arg (vt_prop.uintVal ));
129130
130- hr = obj->Get (L" NumberOfLogicalProcessors" , 0 , &vt_prop, nullptr , nullptr );
131+ hr = obj->Get (bstr_t ( L" NumberOfLogicalProcessors" ) , 0 , &vt_prop, nullptr , nullptr );
131132 log (QString (" CPU logical cores: %1" ).arg (vt_prop.intVal ));
132133
133134 VariantClear (&vt_prop);
@@ -136,15 +137,15 @@ void printSystemInfo()
136137
137138 // RAM info
138139 int64_t totalRAM = 0 ;
139- const std::wstring ram_query (L" SELECT Capacity FROM Win32_PhysicalMemory" );
140+ const std::wstring ram_query (bstr_t ( L" SELECT Capacity FROM Win32_PhysicalMemory" ) );
140141 service->ExecQuery (bstr_t (L" WQL" ), bstr_t (std::wstring (ram_query.begin (), ram_query.end ()).c_str ()), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr , &enumerator);
141142 while (enumerator)
142143 {
143144 enumerator->Next (WBEM_INFINITE, 1 , &obj, &u_return);
144145 if (!u_return)
145146 break ;
146147
147- hr = obj->Get (L" Capacity" , 0 , &vt_prop, nullptr , nullptr );
148+ hr = obj->Get (bstr_t ( L" Capacity" ) , 0 , &vt_prop, nullptr , nullptr );
148149 totalRAM += std::stoll (vt_prop.bstrVal );
149150
150151 VariantClear (&vt_prop);
@@ -153,23 +154,23 @@ void printSystemInfo()
153154 log (QString (" Total physical memory: %1 MB" ).arg (totalRAM/(1024 <<10 )));
154155
155156 // GPU info (Enabled only)
156- const std::wstring gpu_query (L" SELECT Name, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution FROM Win32_VideoController WHERE Status='OK'" );
157+ const std::wstring gpu_query (bstr_t ( L" SELECT Name, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution FROM Win32_VideoController WHERE Status='OK'" ) );
157158 service->ExecQuery (bstr_t (L" WQL" ), bstr_t (std::wstring (gpu_query.begin (), gpu_query.end ()).c_str ()), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr , &enumerator);
158159 while (enumerator)
159160 {
160161 enumerator->Next (WBEM_INFINITE, 1 , &obj, &u_return);
161162 if (!u_return)
162163 break ;
163164
164- hr = obj->Get (L" Name" , 0 , &vt_prop, nullptr , nullptr );
165+ hr = obj->Get (bstr_t ( L" Name" ) , 0 , &vt_prop, nullptr , nullptr );
165166 log (QString (" GPU name: %1" ).arg (vt_prop.bstrVal ));
166167
167- hr = obj->Get (L" AdapterRAM" , 0 , &vt_prop, nullptr , nullptr );
168+ hr = obj->Get (bstr_t ( L" AdapterRAM" ) , 0 , &vt_prop, nullptr , nullptr );
168169 log (QString (" GPU RAM: %1 MB" ).arg (vt_prop.ullVal /(1024 <<10 )));
169170
170- hr = obj->Get (L" CurrentHorizontalResolution" , 0 , &vt_prop, nullptr , nullptr );
171+ hr = obj->Get (bstr_t ( L" CurrentHorizontalResolution" ) , 0 , &vt_prop, nullptr , nullptr );
171172 int currHRes = vt_prop.intVal ;
172- hr = obj->Get (L" CurrentVerticalResolution" , 0 , &vt_prop, nullptr , nullptr );
173+ hr = obj->Get (bstr_t ( L" CurrentVerticalResolution" ) , 0 , &vt_prop, nullptr , nullptr );
173174 int currVRes = vt_prop.intVal ;
174175 log (QString (" Current resolution: %1x%2" ).arg (currHRes).arg (currVRes));
175176
0 commit comments