--- In [email protected], "qzzyyx" <blackh...@...> wrote:
>
> How do I see the args?
OK, I figured that out. I have something that seems to work. I'd be happy to
hear suggestions (even on the code, which appears below). Avoiding the C
library makes the DLL 2560 bytes.
bigmem.bigmem() (default is "AvailPhys")
or
bigmem.bigmem("string")
where "string" is, case-insensitively, one of "TotalPhys", "AvailPhys",
"TotalPage", "AvailPage", "TotalVirtual", "AvailVirtual", "Percent". Values
are integers, 0-100 for "Percent" and megabytes otherwise.
typedef BOOL (*GMSExTYPE)(LPMEMORYSTATUSEX);
GMSExTYPE GMSEx;
HMODULE hKernel32;
BOOL WINAPI MyDllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID)
{
if ( dwReason == DLL_PROCESS_ATTACH )
{
GMSEx = NULL;
hKernel32 = GetModuleHandle("KERNEL32.DLL");
GMSEx = (GMSExTYPE) GetProcAddress(hKernel32,
"GlobalMemoryStatusEx");
}
return TRUE;
}
_declspec(dllexport) VOID bigmem( LPSTR szv, LPSTR szx,
BOOL (*GetVar)(LPSTR, LPSTR), VOID (*SetVar)(LPSTR, LPSTR),
DWORD* pFlags, UINT nargs, LPSTR* szargs, PPROSERVICES* ppsv)
{
CHAR *strings[7] = {"TotalPhys", "AvailPhys", "TotalPage",
"AvailPage", "TotalVirtual", "AvailVirtual", "Percent"};
UINT offset = 2; // default = AvailPhys
if ( nargs > 0 )
{
for ( UINT j=0; j<7; j++ )
{
if ( !lstrcmpi(szargs[1], strings[j]) )
{
offset = j;
break;
}
}
}
DWORD dwResult;
if ( GMSEx )
{
MEMORYSTATUSEX msex;
msex.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&msex);
dwResult = offset == 6 ?
msex.dwMemoryLoad :
*(&msex.ullTotalPhys + offset) >> 20;
}
else
{
MEMORYSTATUS ms;
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&ms);
dwResult = offset = 6 ?
ms.dwMemoryLoad :
*(&ms.dwAvailPhys + offset) >> 20;
}
wsprintf(*szargs, "%lu", dwResult);
}