D
Mit WMI ist das ein ordentliches Gefummel. Will mir eine Klasse schreiben, welche mir die COM-Sachen versteckt. Hab aber Probleme mit dem BSTRs.
Wie bekomme ich einem BSTR in einen std::string?
Oder in einen char*?
[EDIT2]
Hier meine Lösung zum konvertieren von BSTR nach char*. Ich hab den Kode der ersten Fkt. im Netz gefunden und die zweite Fkt. für die Rückwandlung aus der ersten Fkt. durch probieren modifiziert.
char* convertBSTR(BSTR str)
{
if(!str) return NULL;
DWORD cb,cwch = ::SysStringLen(str);
char *szOut = NULL;
if(cb = ::WideCharToMultiByte(CP_ACP, 0, str, cwch + 1, NULL, 0, 0, 0))
{
szOut = new char[cb];
if(szOut)
{
szOut[cb - 1] = '\0';
if(!::WideCharToMultiByte(CP_ACP, 0, str, cwch + 1, szOut, cb, 0, 0))
{
delete []szOut;
szOut = NULL;
}
}
}
return szOut;
}
BSTR convert2BSTR(const char* str)
{
if(!str) return NULL;
int cwch, cb = 0;
for (const char* i = str; *i != '\0'; ++i, ++cb);
wchar_t* buf = NULL;
if (cwch = ::MultiByteToWideChar(CP_ACP, 0, str, cb+1, NULL, 0))
{
buf = new wchar_t[cwch];
if (buf)
{
if (!::MultiByteToWideChar(CP_ACP, 0, str, cb+1, buf, cwch))
{
delete [] buf;
buf = NULL;
return NULL;
}
}
}
BSTR bstrOut = ::SysAllocString(buf);
delete [] buf;
return bstrOut;
}
[/EDIT2]