Skip to content

Commit 7f764cb

Browse files
committed
I hope this is fixed compilation with old MSVC
1 parent 2cdd967 commit 7f764cb

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,15 @@ IF(WIN32)
331331
# C4305: type truncation
332332
# C4351: "new" behaviour, member array default initialization. Required since at least C++98, but funny MSVC throws a warning.
333333
# C4996: deprecated POSIX names (used in zlib)
334-
# C5105: defines in macros
334+
# C5105: defines in macros
335335
# Zc:_cplusplus: Qt >5.9.0 requires a C++17 compiler, because cmake has a bug: https://gitlab.kitware.com/cmake/cmake/-/issues/1883
336+
SET(STEL_MSVC_FLAGS "/wd4244 /wd4305 /wd4351 /wd4996 /wd5105 /utf-8 /Zc:__cplusplus")
337+
336338
# permissive: required by Qt >=6.9.0 (see qt6\QtCore\qcompilerdetection.h for more information: https://github.com/qt/qtbase/blob/v6.9.0/src/corelib/global/qcompilerdetection.h#L1304-L1316)
337-
SET(STEL_MSVC_FLAGS "/wd4244 /wd4305 /wd4351 /wd4996 /wd5105 /utf-8 /Zc:__cplusplus /permissive-")
339+
IF(${QT_VERSION} VERSION_GREATER_EQUAL 6.9.0)
340+
SET(STEL_MSVC_FLAGS "${STEL_MSVC_FLAGS} /permissive-")
341+
ENDIF()
342+
338343
# Avoid type conflict with C++17 standard
339344
# SET(STEL_MSVC_FLAGS "${STEL_MSVC_FLAGS} /D_HAS_STD_BYTE=0") # Don't do this in Qt6. Just avoid "using namespace std" anywhere! https://developercommunity.visualstudio.com/t/error-c2872-byte-ambiguous-symbol/93889
340345
# Set multiprocessing and minimal version of Windows

src/StelSystemInfo.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <windows.h>
3131
#include <WbemIdl.h>
3232
#include <comdef.h>
33-
#include <comutil.h> // For _bstr_t
3433
#include <string>
3534
#pragma comment(lib, "wbemuuid.lib")
3635
#endif
@@ -114,38 +113,38 @@ void printSystemInfo()
114113
IWbemClassObject* obj = nullptr;
115114

116115
// CPU info
117-
const std::wstring cpu_query(_bstr_t(L"SELECT Name, NumberOfLogicalProcessors, MaxClockSpeed FROM Win32_Processor"));
118-
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);
116+
const std::wstring cpu_query(L"SELECT Name, NumberOfLogicalProcessors, MaxClockSpeed FROM Win32_Processor");
117+
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);
119118
while (enumerator)
120119
{
121120
enumerator->Next(WBEM_INFINITE, 1, &obj, &u_return);
122121
if (!u_return)
123122
break;
124123

125-
hr = obj->Get(_bstr_t(L"Name"), 0, &vt_prop, nullptr, nullptr);
126-
log(QString("CPU name: %1").arg(vt_prop.bstrVal));
124+
hr = obj->Get(L"Name", 0, &vt_prop, nullptr, nullptr);
125+
log(QString("CPU name: %1").arg(vt_prop.bstrVal));
127126

128-
hr = obj->Get(_bstr_t(L"MaxClockSpeed"), 0, &vt_prop, nullptr, nullptr);
129-
log(QString("CPU maximum speed: %1 MHz").arg(vt_prop.uintVal));
127+
hr = obj->Get(L"MaxClockSpeed", 0, &vt_prop, nullptr, nullptr);
128+
log(QString("CPU maximum speed: %1 MHz").arg(vt_prop.uintVal));
130129

131-
hr = obj->Get(_bstr_t(L"NumberOfLogicalProcessors"), 0, &vt_prop, nullptr, nullptr);
132-
log(QString("CPU logical cores: %1").arg(vt_prop.intVal));
130+
hr = obj->Get(L"NumberOfLogicalProcessors", 0, &vt_prop, nullptr, nullptr);
131+
log(QString("CPU logical cores: %1").arg(vt_prop.intVal));
133132

134133
VariantClear(&vt_prop);
135134
obj->Release();
136135
}
137136

138137
// RAM info
139138
int64_t totalRAM = 0;
140-
const std::wstring ram_query(_bstr_t(L"SELECT Capacity FROM Win32_PhysicalMemory"));
141-
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);
139+
const std::wstring ram_query(L"SELECT Capacity FROM Win32_PhysicalMemory");
140+
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);
142141
while (enumerator)
143142
{
144143
enumerator->Next(WBEM_INFINITE, 1, &obj, &u_return);
145144
if (!u_return)
146145
break;
147146

148-
hr = obj->Get(_bstr_t(L"Capacity"), 0, &vt_prop, nullptr, nullptr);
147+
hr = obj->Get(L"Capacity", 0, &vt_prop, nullptr, nullptr);
149148
totalRAM += std::stoll(vt_prop.bstrVal);
150149

151150
VariantClear(&vt_prop);
@@ -154,23 +153,23 @@ void printSystemInfo()
154153
log(QString("Total physical memory: %1 MB").arg(totalRAM/(1024<<10)));
155154

156155
// GPU info (Enabled only)
157-
const std::wstring gpu_query(_bstr_t(L"SELECT Name, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution FROM Win32_VideoController WHERE Status='OK'"));
158-
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);
156+
const std::wstring gpu_query(L"SELECT Name, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution FROM Win32_VideoController WHERE Status='OK'");
157+
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);
159158
while (enumerator)
160159
{
161160
enumerator->Next(WBEM_INFINITE, 1, &obj, &u_return);
162161
if (!u_return)
163162
break;
164163

165-
hr = obj->Get(_bstr_t(L"Name"), 0, &vt_prop, nullptr, nullptr);
166-
log(QString("GPU name: %1").arg(vt_prop.bstrVal));
164+
hr = obj->Get(L"Name", 0, &vt_prop, nullptr, nullptr);
165+
log(QString("GPU name: %1").arg(vt_prop.bstrVal));
167166

168-
hr = obj->Get(_bstr_t(L"AdapterRAM"), 0, &vt_prop, nullptr, nullptr);
169-
log(QString("GPU RAM: %1 MB").arg(vt_prop.ullVal/(1024<<10)));
167+
hr = obj->Get(L"AdapterRAM", 0, &vt_prop, nullptr, nullptr);
168+
log(QString("GPU RAM: %1 MB").arg(vt_prop.ullVal/(1024<<10)));
170169

171-
hr = obj->Get(_bstr_t(L"CurrentHorizontalResolution"), 0, &vt_prop, nullptr, nullptr);
170+
hr = obj->Get(L"CurrentHorizontalResolution", 0, &vt_prop, nullptr, nullptr);
172171
int currHRes = vt_prop.intVal;
173-
hr = obj->Get(_bstr_t(L"CurrentVerticalResolution"), 0, &vt_prop, nullptr, nullptr);
172+
hr = obj->Get(L"CurrentVerticalResolution", 0, &vt_prop, nullptr, nullptr);
174173
int currVRes = vt_prop.intVal;
175174
log(QString("Current resolution: %1x%2").arg(currHRes).arg(currVRes));
176175

0 commit comments

Comments
 (0)