xref: /reactos/base/shell/cmd/memory.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  *  MEMORY.C - internal command.
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  *  History:
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  *    01-Sep-1999 (Eric Kohl)
8*c2c66affSColin Finck  *        Started.
9*c2c66affSColin Finck  *
10*c2c66affSColin Finck  *    28-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
11*c2c66affSColin Finck  *        Remove all hardcoded strings in En.rc
12*c2c66affSColin Finck  */
13*c2c66affSColin Finck 
14*c2c66affSColin Finck #include "precomp.h"
15*c2c66affSColin Finck 
16*c2c66affSColin Finck #ifdef INCLUDE_CMD_MEMORY
17*c2c66affSColin Finck 
CommandMemory(LPTSTR param)18*c2c66affSColin Finck INT CommandMemory (LPTSTR param)
19*c2c66affSColin Finck {
20*c2c66affSColin Finck     MEMORYSTATUSEX msex;
21*c2c66affSColin Finck     TCHAR szMemoryLoad[20];
22*c2c66affSColin Finck     TCHAR szTotalPhys[40];
23*c2c66affSColin Finck     TCHAR szAvailPhys[40];
24*c2c66affSColin Finck     TCHAR szTotalPageFile[40];
25*c2c66affSColin Finck     TCHAR szAvailPageFile[40];
26*c2c66affSColin Finck     TCHAR szTotalVirtual[40];
27*c2c66affSColin Finck     TCHAR szAvailVirtual[40];
28*c2c66affSColin Finck     BOOL (WINAPI *GlobalMemoryStatusEx)(LPMEMORYSTATUSEX);
29*c2c66affSColin Finck 
30*c2c66affSColin Finck     if (!_tcsncmp (param, _T("/?"), 2))
31*c2c66affSColin Finck     {
32*c2c66affSColin Finck         ConOutResPaging(TRUE,STRING_MEMORY_HELP1);
33*c2c66affSColin Finck         return 0;
34*c2c66affSColin Finck     }
35*c2c66affSColin Finck 
36*c2c66affSColin Finck     GlobalMemoryStatusEx
37*c2c66affSColin Finck         = (BOOL (WINAPI *)(LPMEMORYSTATUSEX))GetProcAddress(GetModuleHandle(_T("KERNEL32")), "GlobalMemoryStatusEx");
38*c2c66affSColin Finck     if (GlobalMemoryStatusEx)
39*c2c66affSColin Finck     {
40*c2c66affSColin Finck         msex.dwLength = sizeof(MEMORYSTATUSEX);
41*c2c66affSColin Finck         GlobalMemoryStatusEx(&msex);
42*c2c66affSColin Finck     }
43*c2c66affSColin Finck     else
44*c2c66affSColin Finck     {
45*c2c66affSColin Finck         MEMORYSTATUS ms;
46*c2c66affSColin Finck         ms.dwLength = sizeof(MEMORYSTATUS);
47*c2c66affSColin Finck         GlobalMemoryStatus(&ms);
48*c2c66affSColin Finck         msex.dwMemoryLoad = ms.dwMemoryLoad;
49*c2c66affSColin Finck         msex.ullTotalPhys = ms.dwTotalPhys;
50*c2c66affSColin Finck         msex.ullAvailPhys = ms.dwAvailPhys;
51*c2c66affSColin Finck         msex.ullTotalPageFile = ms.dwTotalPageFile;
52*c2c66affSColin Finck         msex.ullAvailPageFile = ms.dwAvailPageFile;
53*c2c66affSColin Finck         msex.ullTotalVirtual = ms.dwTotalVirtual;
54*c2c66affSColin Finck         msex.ullAvailVirtual = ms.dwAvailVirtual;
55*c2c66affSColin Finck     }
56*c2c66affSColin Finck 
57*c2c66affSColin Finck     ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
58*c2c66affSColin Finck     ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
59*c2c66affSColin Finck     ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
60*c2c66affSColin Finck     ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
61*c2c66affSColin Finck     ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
62*c2c66affSColin Finck     ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
63*c2c66affSColin Finck     ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
64*c2c66affSColin Finck 
65*c2c66affSColin Finck     ConOutResPrintf(STRING_MEMORY_HELP2,
66*c2c66affSColin Finck                     szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
67*c2c66affSColin Finck                     szAvailPageFile, szTotalVirtual, szAvailVirtual);
68*c2c66affSColin Finck 
69*c2c66affSColin Finck     return 0;
70*c2c66affSColin Finck }
71*c2c66affSColin Finck 
72*c2c66affSColin Finck #endif /* INCLUDE_CMD_MEMORY */
73*c2c66affSColin Finck 
74*c2c66affSColin Finck /* EOF */
75