|
|
amaneet wrote: Now Please suggest me which language is appropriate to make this program.
There are probably several that could be used. Which are you most familar with?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
Can you help me? Now I want to use the WMI class to get hardware/system information, including the processor, memory, disk drive, operation system, and so on. Bascially, all system hardware and software information. I have known mabye it's simply using the WMI class. But I don't know how to use it? Can you give me an example or source code. Hope to get all reply, thanks.
David
|
|
|
|
|
|
Dear WhiteSky,
Thanks for your help, I will have a review firstly. If any quesiton, I will ask you, thanks.
David
|
|
|
|
|
Dear Whitesky,
I have a try as the WMI C++ Application Example. I want to get the physical memory information. So I replace the Win32_OperatingSystem with the Win32_PhysicalMemory. I can get the string type data from the VARIANT structure just as example code, according to the Win32_PhysicalMemory class definition. But I don't know how to get the uint16 or uint32 type data from the VARIANT structure. Can you tell me?
HRESULT hres;
// 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.
}
cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
// 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_OperatingSystem"),
bstr_t("SELECT * FROM Win32_PhysicalMemory"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for operating system name 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);
// I can get the string type data
cout<<"BankLabel:";
hr = pclsObj->Get(L"BankLabel", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr) && (V_VT(&vtProp) == VT_BSTR))
{
wcout<<vtprop.bstrval<<endl;
variantclear(&vtprop);
="" }
="" but="" i="" don't="" know="" how="" to="" get="" the="" uint16="" or="" uint32="" type="" data="" just="" as="" width.="" can="" you="" help="" me?
="" cout<<"datawidth:";
="" hr="pclsObj-">Get(L"DataWidth", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr) && (V_VT(&vtProp) == VT_BSTR))
{
TCHAR chTemp[80] = {0};
itoa(abs(vtProp.iVal), chTemp, 10);
wcout<<chtemp<<endl;
variantclear(&vtprop);
="" }
="" }
="" cleanup
="" =="======
" psvc-="">Release();
pLoc->Release();
pEnumerator->Release();
pclsObj->Release();
CoUninitialize();
return 0; // Program successfully completed.
|
|
|
|
|
|
Hi David,
when i see your question i remember my question in many years ago i wanted to got all detaily computer Memory(size,speed,bus,...)Motherboard(serial number,bios,cmos....) and i tried about 5 months but in the end i couldnt any helpful thing (i think you can remember DOS and Assembly).I used Win32_PhysicalMemory for got Capacity but not all previous,but your problem i am wondering i try with C# of course its differ with VC++ (a ManagementScope then ObjectQuery("Select * FROM Win32_PhysicalMemory") and .....)
but i cant get Status,Speed and manufacture,...) but for capacity or Name and some things its working like VC++ then i tring with VC++ but it seems that result is same with C# and i think your code not problem but i think it needs to a additional code then i starting to search on internet a big search and i see about 50 site but in these sites all users has same error with you they cant get BankLabel (of course we have this parameter) InstallDate,Manufacturer,HotSwappable,Model,PartNumber and ... if we want use another WMI we can use from Methods but in Win32_PhysicalMemory we dont have any methods and almost more examples are in C# or VB like(http://www.dx21.com/SCRIPTING/WMI/SUBCLASS.ASP?CID=32)
if you see this site 12 or 15 lines a declare a root a query and in the loop read items but i cant find any good C++ code for you for example in this link http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21214650.html) you can a problem Win32_PhysicalMemory(C++) and it seems that he find his problem
maybe it is some helpful to you
|
|
|
|
|
I would recommend you the following samples:
I hope they are helpful.
|
|
|
|
|
Thanks for your help, but how can I get your recommended samples linking? You can provide them to me? Thanks.
David
|
|
|
|
|
I have an application which calls the functions of a DLL. If control goes to that DLL i can not maximize my application. it simply hangs. then i need to END-TASK the application. Here i want to increase the priority of SC_MAXIMIZE message. How can i do it? please help me
JITEEN
|
|
|
|
|
Hi,
I think you don't need an increased priority, you only need a DLL without a deadlock!
Or if you havn't a deadlock, you need multithreading.
Your problem is, that your application-main-thread can't process the message-loop, if he is running (and blocking) at the DLL.
HTH
Frank
|
|
|
|
|
So here, i need to UI thread. Or the DLL's function which i m calling needs to be in thread? i mean what i should do exactly.
Jiteen
|
|
|
|
|
helpcode wrote: en i need to END-TASK the application. Here i want to increase the priority of SC_MAXIMIZE message. How can i do it? please help me ..
actually your main thread is calling the Function Thread, which seems to performing long function.. thats why it making the main thread hung!.. so better you try MultiThreading program! for that you have to implement some callback mechanism for same!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
The UI looks hung because messages have to actually be processed by the UI thread. While the thread is running code in the DLL, it's not processing messages in the queue. Changing to a multi-threaded design is often the best way to solve this problem.
|
|
|
|
|
hi all,
i am having one problem with threading
i created one dialog based application whose work is to read the data from serial port and display it.so i created one thred for this work.
means now i got two threads one is application thread and other is serial communication thread which is created in OnInitDialog.
now everything is working i mean the thread got created it read some bytes
from port and now it wants to show the data so need to send this data to main
thread. so i am doing this with ::SendMessage() but it is giving access violation. i don't know why this is happening and currently i am not sending the data also i.e. buffer so please help me
below is code (stepwise)
1)In Oninitdialog
THREADPARAM *ptp = new THREADPARAM;
if(ptp)
{
memset(ptp->array,0,30);
strcpy(ptp->array,"Harshal");
ptp->appHandle = this->m_hWnd;
hSerialThread = CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE) SerialCommunication,
(LPVOID) NULL,
0,
&dwSerialThreadID);
}
2)Thread function
UINT SerialCommunication(LPVOID pParam)
{
int write_req=0;
THREADPARAM *ptp = (THREADPARAM *)pParam;
while(1)
{
if(write_req == 2)// send write request and read it
{
DWORD length=0;
DWORD dwRead=0;
if (WriteFile(hCom,
SEND_CMD, // pointer to data to write to file
NOOFBYTE, // number of bytes to write
&length, // pointer to number of bytes written
NULL) == 0)
{// write failed
write_req = 0;
continue;
}
// writefile succeeded issue readfile
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req = 0;
continue;
}
if(dwRead > 0)
{
//MessageBox(NULL,buffer,"Data with packet",MB_OK);
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);// error is here
}
write_req = 0;
}
else // only read from port and increment counter
{
DWORD dwRead=0;
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req++;
continue;
}
if(dwRead > 0)
{// you are in thread you need to send message to
// main application
//char a;
HWND hwnd = (HWND)AfxGetApp()->m_pMainWindow;
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);
//MessageBox(NULL,buffer,"Data without packet",MB_OK);
}
write_req++;
}
}
return 0;
}
3) Sent message function
LRESULT CReadDataDlg::OnShowDataMessage(UINT wParam, LONG lParam)
{
return 0;
}
Thanks and regards
Harshal
|
|
|
|
|
harsha_1234 wrote: ::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);
Use PostMessage() instead of SendMessage.. and look for difference between PostMessage and SendMessage in MSDN!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
From the 'serial port reader' thread I would place the data into a thread-safe queue of some sort and notify the 'display' thread that new data is available. The 'display' thread can pull it out of the queue and format as appropriate.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Hi, I am reading some float value from a file.
Code:
char tScaleLow[8],tScaleHigh[8],tAlarmLow[8],tAlarmHigh[8];
cfTag.Read(tScaleLow,sizeof(float));
cfTag.Read(tScaleHigh,sizeof(float));
cfTag.Read(tAlarmLow,sizeof(float));
cfTag.Read(tAlarmHigh,sizeof(float));
This is my code it reads the value fine.But the drawback is it reads only 4 characters i.e, if ScaleHigh is 100000 it reads only 1000.
So, i changed the code as follow...
float fScaleLow,fScaleHigh,fAlarmLow,fAlarmHigh;
cfTag.Read(&fScaleLow,sizeof(float));
cfTag.Read(&fScaleHigh,sizeof(float));
cfTag.Read(&fAlarmLow,sizeof(float));
cfTag.Read(&fAlarmHigh,sizeof(float));
This reads some garbage value like 6.002e+102 like this,all the four things reads like this.
Whats the wrong in my code?Or is there any way to read all values in that previous code.
Anu
|
|
|
|
|
Anu_Bala wrote: reads only 4 characters
That's because you are passing the sizeof(float) which is 4 on windows platform.
The second parameter for Read() - The maximum number of bytes to be read from the file. This is four and so it reads four.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Yes,
Any solution for this?
Anu
|
|
|
|
|
After each value that you write in a file put a comma ',' as a delimiter.Split the string of the file based on that ','.
Another option would be to read and write the full structure at a time and get/set the values in the file.(Use fread in this case)
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Can u tell me why its not read in this code..
float fScaleLow,fScaleHigh,fAlarmLow,fAlarmHigh;
cfTag.Read(&fScaleLow,sizeof(float));
cfTag.Read(&fScaleHigh,sizeof(float));
cfTag.Read(&fAlarmLow,sizeof(float));
cfTag.Read(&fAlarmHigh,sizeof(float));
its read the wrong value..
Pls..
Anu
|
|
|
|
|
As it seems, the value in the file is a string.
If that is the case (and cfTag.Read is a functions to read a string from a file into a given char array), you are using it wrong. You should probably use something around the lines of (thats a guess):
char tScaleLow[TSCALELENGTH]; and<br />
cfTag.Read(tScaleLow,sizeof(char) * TSCALELENGTH);
Actually, without a definition of cfTag.Read, there is no way to tell what you are doing wrong, but I really suspect wrong use of "Read" to be the reason.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi all,
I hope you can give me a hint or help about a debugging issue.
Out of a minidump I got from a release build, the problem showed as follows:
The stack in VC++ debugger when opening the .dmp file, showed:
0x00000000
and nothing else. EIP of course also contained NULL.
I then looked at the ESP address to see the stack. There I found the jump-back address to see where the code would continue if the jump that now occurred to 0x00000000 would have been successful.
The C++ code there looks like the following:
if (variable && variable->SomeFunction() && .....)
"variable" is a pointer to an object of a class.
The question now is, how can I debug that further. Did "variable" maybe not contain - for some reason - a pointer to an object of the class it should point to where the offset to ->SomeFunction() would be NULL ?
Any idea how, for the next iteration of the release software, some code could be added to give more information about the problem - if it still crashes there ?
Thanks for any help,
Manfred
|
|
|
|
|