Click here to Skip to main content
15,889,931 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Work with CWebBrowser On Windows Mobile Pin
Miss_F7-Feb-09 2:23
Miss_F7-Feb-09 2:23 
AnswerRe: Work with CWebBrowser On Windows Mobile Pin
Alain Rist7-Feb-09 3:53
Alain Rist7-Feb-09 3:53 
GeneralRe: Work with CWebBrowser On Windows Mobile Pin
Miss_F7-Feb-09 18:21
Miss_F7-Feb-09 18:21 
QuestionProblem with #defined values Pin
ldsdbomber4-Feb-09 22:34
ldsdbomber4-Feb-09 22:34 
AnswerRe: Problem with #defined values Pin
ldsdbomber4-Feb-09 22:42
ldsdbomber4-Feb-09 22:42 
AnswerRe: Problem with #defined values Pin
Code-o-mat4-Feb-09 22:44
Code-o-mat4-Feb-09 22:44 
QuestionRe: Problem with #defined values Pin
CPallini4-Feb-09 23:11
mveCPallini4-Feb-09 23:11 
Question(WMI) I don't get info about all CPU-cores [modified] Pin
Pasy_m4-Feb-09 20:54
Pasy_m4-Feb-09 20:54 
I want to get the info about all (currently 4) cpu-cores I have.
The most information I get is with the WMI-system (WIN32_processor).
I found at all web-pages the same sample-code for the WMI-access with C++.
I changed it for my needs and it works almost fine. The only
problem is that it gives me only the data for CPU0, but not
the 3 others.
As soon as i change the WQL request to ("SELECT * FROM Win32_Process")
the "while (pEnumerator)"-loop works fine and I get all processes currently running.
So I don't understand why the WQL request returns only the first CPU...

Thanks a lot for any help!

best regards

Peter

>>>> Output >>>>
Number of processors: 4 // from GetSystemInfo()
DeviceID : CPU0
LoadPercentage : 7
Name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz

>>>> code >>>

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <wbemidl.h>

# pragma comment(lib, "wbemuuid.lib")

int main(int argc, char **argv)
{
HRESULT hres;

SYSTEM_INFO siSysInfo;

// Copy the hardware information to the SYSTEM_INFO structure.
GetSystemInfo(&siSysInfo);

cout << "Number of processors: " << siSysInfo.dwNumberOfProcessors << endl;

// Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------

hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hres << endl;
return 1; // Program has failed.
}

// Step 2: --------------------------------------------------
// Set general COM security levels --------------------------
// Note: If you are using Windows 2000, you need to specify -
// the default authentication credentials for a user by using
// a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
// parameter of CoInitializeSecurity ------------------------

hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);


if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}

// Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI -------------------------

IWbemLocator *pLoc = NULL;

hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);

if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}

// Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method

IWbemServices *pSvc = NULL;

// Connect to the root\cimv2 namespace with
// the current user and obtain pointer pSvc
// to make IWbemServices calls.
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);

if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}

// Step 5: --------------------------------------------------
// Set security levels on the proxy -------------------------

hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);

if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}

// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----

// For example, get the name of the operating system
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Processor"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);

if (FAILED(hres))
{
cout << "Query for processors failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}

// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------

IWbemClassObject *pclsObj;
ULONG uReturn = 0;

while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

if(0 == uReturn)
{
break;
}

VARIANT vtProp;

VariantInit(&vtProp);
// Get the value of the Name property
hr = pclsObj->Get(L"DeviceID", 0, &vtProp, 0, 0);
wcout << " DeviceID : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);

VariantInit(&vtProp);
// Get the value of the Name property
hr = pclsObj->Get(L"LoadPercentage", 0, &vtProp, 0, 0);
wcout << " LoadPercentage : " << vtProp.uintVal << endl;
VariantClear(&vtProp);

VariantInit(&vtProp);
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
wcout << " Name : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);

pclsObj->Release();
}
// Cleanup

pSvc->Release();
pLoc->Release();
pEnumerator->Release();
CoUninitialize();

return 0; // Program successfully completed.

}

>>>> Output >>>>
Number of processors: 4
DeviceID : CPU0
LoadPercentage : 7
Name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz

modified on Thursday, February 5, 2009 8:48 AM

AnswerRe: (WMI) I don't get info about all CPU-cores Pin
Stuart Dootson4-Feb-09 23:10
professionalStuart Dootson4-Feb-09 23:10 
GeneralRe: (WMI) I don't get info about all CPU-cores Pin
Pasy_m5-Feb-09 2:42
Pasy_m5-Feb-09 2:42 
GeneralRe: (WMI) I don't get info about all CPU-cores Pin
David Crow5-Feb-09 3:33
David Crow5-Feb-09 3:33 
GeneralRe: (WMI) I don't get info about all CPU-cores Pin
Pasy_m6-Feb-09 1:27
Pasy_m6-Feb-09 1:27 
AnswerRe: (WMI) I don't get info about all CPU-cores Pin
Pasy_m12-Feb-09 1:38
Pasy_m12-Feb-09 1:38 
QuestionStretching Gifs Pin
chandru.jeeva4-Feb-09 20:47
chandru.jeeva4-Feb-09 20:47 
AnswerRe: Stretching Gifs Pin
Stuart Dootson4-Feb-09 23:56
professionalStuart Dootson4-Feb-09 23:56 
GeneralRe: Stretching Gifs Pin
chandru.jeeva5-Feb-09 0:54
chandru.jeeva5-Feb-09 0:54 
GeneralRe: Stretching Gifs Pin
Stuart Dootson5-Feb-09 1:05
professionalStuart Dootson5-Feb-09 1:05 
GeneralRe: Stretching Gifs Pin
chandru.jeeva8-Feb-09 19:02
chandru.jeeva8-Feb-09 19:02 
QuestionGetting message on pressing keyboard buttons while application is running Pin
VCProgrammer4-Feb-09 20:12
VCProgrammer4-Feb-09 20:12 
AnswerRe: Getting message on pressing keyboard buttons while application is running Pin
Cedric Moonen4-Feb-09 20:53
Cedric Moonen4-Feb-09 20:53 
QuestionProblem with modeless dialog Pin
materatsu4-Feb-09 18:52
materatsu4-Feb-09 18:52 
AnswerRe: Problem with modeless dialog Pin
soumya.sn4-Feb-09 19:25
soumya.sn4-Feb-09 19:25 
GeneralRe: Problem with modeless dialog Pin
materatsu9-Feb-09 16:03
materatsu9-Feb-09 16:03 
QuestionShellexecute and installing a file with out showing any further dialogs. Pin
kDevloper4-Feb-09 18:52
kDevloper4-Feb-09 18:52 
AnswerRe: Shellexecute and installing a file with out showing any further dialogs. Pin
«_Superman_»4-Feb-09 21:44
professional«_Superman_»4-Feb-09 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.