WMI and Variables
Aug 29, 2012 at 11:52am UTC
I am struggling to find an answer to this one and i am wondering if any of you can help me:
When accessing WMI in C++ you would normally go something like this:
1 2 3 4 5 6 7
IEnumWbemClassObject* pEnumerator = NULL;
hr = pSvc->ExecQuery(
BSTR(L"WQL" ),
BSTR(L"SELECT * FROM Win32_ComputerSystem" ),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
But instead of just hard coding L"SELECT * FROM Win32_ComputerSystem"
is there a way that I can just use a standard char* or WCHAR*?
Any help would be greatly appreciated
Aug 29, 2012 at 1:50pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string>
#include <windows.h>
int main()
{
std::wstring wstr ;
std::wcout << L"? " && std::getline( std::wcin, wstr ) ;
BSTR bstr = ::SysAllocStringLen( wstr.data(), wstr.size() ) ; // wstring to BSTR
std::wstring wstr_cpy( bstr, ::SysStringLen(bstr) ) ; // BSTR to wstring
::SysFreeString(bstr) ;
std::wcout << wstr_cpy << L'\n' ;
}
Topic archived. No new replies allowed.