I'm making an plugin for Open Hardware Monitor. But I have a problem using the Windows wmi database. I can run a query and I get an value from it. But I can't convert the value to the correct type. Because I create a query on runtime I can't know what type the WMI database must return to run without errors. In my case i can get a float or a string. But when i get an float from the database and i convert it to a string i got an memory error. And if i convert a string to the float I doesn't get any errors. Now how can i create a check if the BSTR value is invalid? Or how can I check which type i must use? I have tested it with some if statment or with a try catch. But non of them are working.
try
{
wstring ws(vtProp.bstrVal, SysStringLen(vtProp.bstrVal));
returnValue = string(ws.begin(), ws.end());
ws.clear();
}
catch (...)
{
float temp = vtProp.fltVal;
returnValue = to_string(temp);
}