Hi to all, I am currently developing a simple program which analyses system hardware such as processor speed etc.I am having problems with retreiving system memory ie how large the ram is, i have a starting point but does not seem to work i always get errors, i have been told by others to define the double i.e. Double = temp; Temp = XXXXX, but do not understand what this means as i am a novice to C++ Please see source code below: -
Well what you've done is not declare a variable properly.
When you use "double" it expects you to give it a variable name.
For example "totalram", ie "double totalram=..."
However, I think it makes more sense if you use "long" to store the RAM amount. So your new code would be something like:
1 2 3 4 5 6 7 8 9 10
MEMORYSTATUS memory;
memset(&memory,sizeof(MEMORYSTATUS),0);
memory.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&memory);
long totalram=memory.dwTotalPhys;
printf("%d bytes of RAM total",totalram);
As you can see I have made it print simply, the total bytes of RAM. Divide the number by 1024 for the kilobytes of RAM, then divide by 1024 for the megabytes of RAM, again for the gigabytes (etc).
Thank you very much for your response. I have tried the above code and understand what you are implying but when I compile it there are still errors relating the following line of code:
memset(&memory,sizeof(MEMORYSTATUS),0);
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2365: 'memset' : redefinition; previous definition was 'function'
Thanks Chris, the code now compiles......I am trying to assign the contents of the totalram variable to a label via the use of a button (RAM) using the following code:
case RAM:
main();
SetDlgItemText(hdwnd,lblSpeed,totalram);
break;
I keep on getting the following error:
error C2664: 'SetDlgItemTextA' : cannot convert parameter 3 from 'long' to 'LPCSTR
Right, the third parameter, in this case, "totalram" needs to be a null-terminated string (LPCTSTR) but it is a long.
BOOL SetDlgItemText(HWND hDlg, int nIDDlgItem, LPCTSTR lpString);
That is the definition of the subroutine you are using. In italics is the part you need to enter. Currently totalram is a long but it needs to be LPCTSTR so you will need to find a way of converting it.
There is this subroutine I have found:
BOOL SetDlgItemInt(HWND hDlg, int nIDDlgItem, UINT uValue, BOOL bSigned);
This time in italics is where (I presume) you would use the value totalram.
I think this should work (not got time to test it currently):