MEMORYSTATUSEX issue

Started by
-1 comments, last by GetWindowRect 18 years, 7 months ago
I am trying to use the MEMORYSTATUSEX structure to get memory info. Everything gets put into the structure correctly, it seems, when I use GlobalMemoryStatusEx. However, when I use wsprintf to put the info into a char array it shows all the available memory members as 0 if I use %ld, %lu, or %d. I looked at the help on MSDN and they use %*I64d with a WIDTH constant of 7. It displays the actual numbers, except a couple numbers display as something like: 1fff80 and 1fe770 I have never seen %*I64d used before, but it seems that without using that I cannot display the memory correctly. Is this a right presumption, or am I doing something wrong? Here are both methods, mine and the modified MSDN version:

MEMORYSTATUSEX MemoryInfo()
{
	const int DIV = 1024;
	const int WIDTH = 7;
	const char* divisor = "K";
	char memInfo[5000];
	
	MEMORYSTATUSEX statex;

	statex.dwLength = sizeof (MEMORYSTATUSEX);

	GlobalMemoryStatusEx (&statex);
	
        //my version
	sprintf (memInfo,	"%ld percent of memory is in use.\n"
			        "There are %d total Kbytes of physical memory.\n"
				"There are %d free Kbytes of physical memory.\n"
				"There are %lu total Kbytes of paging file.\n"
				"There are %lu free Kbytes of paging file.\n"
				"There are %lu total Kbytes of virtual memory.\n"
			        "There are %lu free Kbytes of virtual memory.\n",	
								statex.dwMemoryLoad,
								statex.ullTotalPhys/DIV,
								statex.ullAvailPhys/DIV,
								statex.ullTotalPageFile/DIV,
								statex.ullAvailPageFile/DIV,
								statex.ullTotalVirtual/DIV,
								statex.ullAvailVirtual/DIV);
	
	MessageBox(NULL, memInfo, "Memory Information", MB_OK|MB_ICONINFORMATION);
	
	char one[50], two[50], three[50], four[50], five[50], six[50], seven[50], eight[50];
        //MSDN version (they use printf and do it on multiple lines, so I 
        //left it in the same format and combined all the info into one variable
        //I know there are easier and/or better ways around this, I just did it this way to keep it as close to their version as I could (or something)
	sprintf (one, "%ld percent of memory is in use.\n",
          statex.dwMemoryLoad);
	sprintf (two, "There are %*I64d total %sbytes of physical memory.\n",
          WIDTH, statex.ullTotalPhys/DIV, divisor);
	sprintf (three, "There are %*I64d free %sbytes of physical memory.\n",
          WIDTH, statex.ullAvailPhys/DIV, divisor);
	sprintf (four, "There are %*I64d total %sbytes of paging file.\n",
          WIDTH, statex.ullTotalPageFile/DIV, divisor);
	sprintf (five, "There are %*I64d free %sbytes of paging file.\n",
          WIDTH, statex.ullAvailPageFile/DIV, divisor);
	sprintf (six, "There are %*I64x total %sbytes of virtual memory.\n",
		  WIDTH, statex.ullTotalVirtual/DIV, divisor);
	sprintf (seven, "There are %*I64x free %sbytes of virtual memory.\n",
		  WIDTH, statex.ullAvailVirtual/DIV, divisor);
	sprintf (eight, "There are %*I64x free %sbytes of extended memory.\n",
		WIDTH, statex.ullAvailExtendedVirtual/DIV, divisor);

	sprintf(memInfo, "%s %s %s %s %s %s %s %s", one, two, three, four, five, six, seven, eight);

	MessageBox(NULL, memInfo, "Memory Information", MB_OK|MB_ICONINFORMATION);
	// Show the amount of extended memory available.

	
	return statex;
}



Can anyone tell me what the difference is between %I64x, %I64d and why they work, but %lu/%ld/%d do not? Thank you in advance

This topic is closed to new replies.

Advertisement