Initialize WMI only once, remove init calls from everywhere it is called and initialize it once as a static variable

* See comment: https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/1581#note_684260496
This commit is contained in:
Adam Honse 2021-09-24 12:20:34 -05:00
parent eaaed7fd83
commit dd47256f06
6 changed files with 2 additions and 5 deletions

View file

@ -16,7 +16,6 @@ static void DetectAsusTUFLaptopWMIControllers(std::vector<RGBController*>&)
// For now, checking for "TUF Gaming" should suffice // For now, checking for "TUF Gaming" should suffice
Wmi wmi; Wmi wmi;
wmi.init();
std::vector<QueryObj> systemProduct; std::vector<QueryObj> systemProduct;
if (wmi.query("SELECT * FROM Win32_ComputerSystemProduct", systemProduct)) if (wmi.query("SELECT * FROM Win32_ComputerSystemProduct", systemProduct))

View file

@ -27,7 +27,6 @@ DMIInfo::DMIInfo()
manufacturer = ""; manufacturer = "";
HRESULT hres; HRESULT hres;
Wmi wmi; Wmi wmi;
wmi.init();
// Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS" // Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS"
// These devices may be browsed under Device Manager -> System Devices // These devices may be browsed under Device Manager -> System Devices

View file

@ -498,7 +498,6 @@ void i2c_smbus_i801_detect()
i2c_smbus_interface * bus; i2c_smbus_interface * bus;
HRESULT hres; HRESULT hres;
Wmi wmi; Wmi wmi;
wmi.init();
// Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS" // Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS"
// These devices may be browsed under Device Manager -> System Devices // These devices may be browsed under Device Manager -> System Devices

View file

@ -192,7 +192,6 @@ void i2c_smbus_piix4_detect()
i2c_smbus_interface * bus; i2c_smbus_interface * bus;
HRESULT hres; HRESULT hres;
Wmi wmi; Wmi wmi;
wmi.init();
// Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS" // Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS"
// These devices may be browsed under Device Manager -> System Devices // These devices may be browsed under Device Manager -> System Devices

View file

@ -2,6 +2,7 @@
IWbemLocator* Wmi::pLoc = nullptr; IWbemLocator* Wmi::pLoc = nullptr;
IWbemServices* Wmi::pSvc = nullptr; IWbemServices* Wmi::pSvc = nullptr;
HRESULT WmiInit = Wmi::init();
// Taken from https://stackoverflow.com/questions/215963/ // Taken from https://stackoverflow.com/questions/215963/
// Convert a wide Unicode string to an UTF8 string // Convert a wide Unicode string to an UTF8 string

View file

@ -26,7 +26,7 @@ public:
~Wmi(); ~Wmi();
// Initialises connection to WMI host // Initialises connection to WMI host
HRESULT init(); static HRESULT init();
HRESULT query(std::string queryStr, HRESULT query(std::string queryStr,
std::vector<QueryObj>& queryVectorOut, std::vector<QueryObj>& queryVectorOut,