I believe you're looking for this:
std::wstring SID = L"S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334";
hres = pSvc->GetObject((L"Win32_SID.SID='" + SID + L"'").c_str(), 0, NULL, &pclsObj, NULL);
If the above code (notice I added a forgotten call to c_str()
) doesn't work for you, you could try this instead:
#include <sstream>
std::wstring SID = L"S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334";
std::wostringstream s;
s << L"Win32_SID.SID='" << SID << L"'";
hres = pSvc->GetObject(s.str().c_str(), 0, NULL, &pclsObj, NULL);
If this still doesn't work, I'd start suspecting a problem with the compiler.
You've mentioned in the comments you're using the ancient VC++ 6.0, so I will try something really basic (I assume your goal is to have SID
be a variable):
#include <cwchar>
std::wstring SID = L"S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334";
const wchar_t *prefix = L"Win32_SID.SID='";
wchar_t *arg = new wchar_t[wcslen(prefix) + SID.size() + 2]; //2 = terminating ' and NUL
wcscpy(arg, prefix);
wcscat(arg, SDI.c_str());
wcscat(arg, L"'");
hres = pSvc->GetObject(arg, 0, NULL, &pclsObj, NULL);
delete[] arg;
Please note it's not test it - I don't have access to VC++ 6.0.