Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!icdoc!sot-ecs!ih From: ih@ecs.soton.ac.uk (Ian Heath) Newsgroups: comp.windows.ms.programmer Subject: Re: Free Resources Message-ID: <8045@ecs.soton.ac.uk> Date: 7 Jun 91 15:47:56 GMT References: <1195@tuura.UUCP> Sender: news@ecs.soton.ac.uk Lines: 53 In <1195@tuura.UUCP> risto@tuura.UUCP (Risto Lankinen) writes: >James_Bell@f6.n3601.z1.fidonet.org (James Bell) writes: >>> Does anyone know whether it's possible for a program to find out >>> the percentage of remaining free resources, as it is posted in >>The on-disk doc files w/the SDK tell how progman computes the system resources, >>but I don't think they give a function for it. If you >>discover/write one, let me know and/or post it! OK, here we go. This the the "official" way of calculating the free system resources (at least it's the way Program Manager does it) :-> DWORD FAR PASCAL GetHeapSpaces(HANDLE h) ; int GetFreeSystemResources(void) { DWORD dwHeapSize ; int nUserPercent,nGdiPercent ; dwHeapSize = GetHeapSpaces(GetModuleHandle("user")) ; nUserPercent = 100*(LOWORD(dwHeapSize)/1024)/ (HIWORD(dwHeapSize)/1024) ; dwHeapSize = GetHeapSpaces(GetModuleHandle("gdi")) ; nGdiPercent = 100*(LOWORD(dwHeapSize)/1024)/ (HIWORD(dwHeapSize)/1024) ; return (min(nUserPercent,nGdiPercent)) ; } I got this from reverse engineering the program manager program (with apologies to Microsoft). It uses a non-documented function call (GetHeapSpaces whose prototype is given above) and gives the same results as File/Program manager. *** DISCLAIMER *** I don't guarantee this will work for any other version of windows other than 3.0. As it uses an undocumented function call there's no reason the function'll remain the same across versions. However, if Microsoft use it, it must be right B-> While we're on the subject of Windows Hacking, has anyone else found any good undocumented functions within Windows that they might want to share??? Cheers, Ian -- Ian Heath, email: ih@ecs.soton.ac.uk (BITNET) or ih@uk.ac.soton.ecs (JANET) "And now you are alone my friend and I must set you free And you must face the world outside and find your destiny" - Freudiana