Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get disk size and memory
Message
 
 
To
08/12/2003 10:47:19
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00856759
Message ID:
00857060
Views:
30
Just FYI: A link to the UT Windows API#12725 might have been better.

>
>function api_memorystatus &&API function to retrieve memory information.
>local lmemorystatus
>*- Declare API function to retrieve memory information.
>DECLARE GlobalMemoryStatus IN Win32API STRING @MemStat
>
>*- fLong2str() is passed a dwLength of 32; since structure is 32 bytes long.
>*- This is appended to a 28 byte blank buffer; a total of 32 bytes.
>cBuffer = fLong2str( 32 ) + REPLICATE( CHR(0), 28 )
>GlobalMemoryStatus( @cBuffer )
>
>*- dwLength is 4 bytes, start extracting members at byte 5.
>*- Each member is 4 bytes long.
>nMemoryLoad = fStr2long( SUBSTR( cBuffer, 5, 4 ))
>nTotalPhys  = fStr2long( SUBSTR( cBuffer, 9, 4 )) / 1024
>nAvailPhys  = fStr2long( SUBSTR( cBuffer, 13, 4 )) / 1024
>
>nTotalPageFile	= fStr2long( SUBSTR( cBuffer, 17, 4 )) / 1024
>nAvailPageFile	= fStr2long( SUBSTR( cBuffer, 21, 4 )) / 1024
>nTotalVirtual	= fStr2long( SUBSTR( cBuffer, 25, 4 )) / 1024
>nAvailVirtual	= fStr2long( SUBSTR( cBuffer, 29, 4 )) / 1024
>
>lmemorystatus = "Memory Load:			" + TRANSFORM( nMemoryLoad, "999,999,999" ) + "%"+chr(13)+chr(10)+;
> "Physical memory:		" + TRANSFORM( nTotalPhys,  "999,999,999" ) + "k"+chr(13)+chr(10)+;
> "Available physical:		" + TRANSFORM( nAvailPhys,  "999,999,999" ) + "k"+chr(13)+chr(10)+chr(13)+chr(10)+;
> "Paging file:			" + TRANSFORM( nTotalPageFile, "999,999,999" ) + "k"+chr(13)+chr(10)+;
> "Available paging file:		" + TRANSFORM( nAvailPageFile, "999,999,999" ) + "k"+chr(13)+chr(10)+;
> "Total virtual memory:	 	" + TRANSFORM( nTotalVirtual,  "999,999,999" ) + "k"+chr(13)+chr(10)+;
> "Available virtual memory:	" + TRANSFORM( nAvailVirtual,  "999,999,999" ) + "k"
>
>?lmemorystatus
>RETURN lmemorystatus
>
>******************************
>FUNCTION fLong2str( iLongVal )
>******************************
>	*- passed : 32-bit non-negative "numeric" value (iLongVal).
>	*- returns : ASCII character representation of iLongVal in
>	*-			LITTLE_ENDIAN format (least significant byte first).
>	LOCAL iBit, cResult
>	cResult = ""
>	FOR iBit = 24 TO 0 STEP -8
>		*- Prepend new character to cResult.
>		cResult = CHR( INT( iLongVal / (2^iBit) )) + cResult
>		iLongVal = MOD( iLongVal, (2^iBit) )
>	NEXT
>	RETURN cResult
>	ENDFUNC	&& flong2str( iLongVal ).
>
>***************************
>FUNCTION fStr2long( cLong )
>***************************
>	*- passed:  4-byte character string (cLong) in LITTLE_ENDIAN format (least significant byte first).
>	*- returns: Long integer value.
>	LOCAL iBit, iResult
>	iResult = 0
>	FOR iBit = 0 TO 24 STEP 8
>		iResult = iResult + (ASC(cLong) * (2^iBit))
>		cLong = RIGHT( cLong, LEN(cLong) - 1 )
>	NEXT
>	RETURN iResult
>	ENDFUNC	&& fStr2long( cLong )
>
>For disk space
>
>
FUNCTION getdiskspace		&& works like diskspace(), returns free,full or used
>	PARAMETERS m.lcdrive, m.lcdrivevalue
>	*!*	PARAMETERS:
>	*!* 					m.lcDrive: Optional Assumes "C:\" OR
>	*!*										Pass Drive parameter in this format "C:\"
>	*!*						m.lcReturnValue: 	Optional Assumes "FREE"
>	*!*										"FREE" = Free Drive Space
>	*!*										"FULL" = Total Drive Space
>	*!*										"USED" = Used Drive Space
>	
>	*!* RETURNS:			Drive Size in Bytes based on Parameter passed
>	*!*						OR Negitive One (-1) if an error
>	local m.nreturnvalue
>	STORE -1 TO m.nreturnvalue
>	*!* Check for What to return
>	IF TYPE("m.lcDriveValue") <> "C"
>		m.lcdrivevalue = "FREE"
>	ENDIF
>	*!* Check for drive to report on
>	IF TYPE("lcDrive") <> "C"
>		m.lcdrive = "C:\"
>	ELSE
>		m.lcdrive = UPPER(LEFT(ALLTRIM(m.lcdrive),1))+":\"
>	ENDIF
>
>	lpFreeBytesAvailableToCaller = ''
>	lpTotalNumberOfBytes = ''
>	lpTotalNumberOfFreeBytes = ''
>
>	DECLARE INTEGER GetDiskFreeSpaceEx IN kernel32 AS GetDiskFreeSpace ;
>		STRING , STRING @lpFreeBytesAvailableToCaller, STRING ;
>		@lpTotalNumberOfBytes, ;
>		STRING @lpTotalNumberOfFreeBytes
>
>	lpFreeBytesAvailableToCaller = REPLICATE(CHR(0),8)
>	lpTotalNumberOfBytes = REPLICATE(CHR(0),8)
>	lpTotalNumberOfFreeBytes = REPLICATE(CHR(0),8)
>
>	if GetDiskFreeSpace(m.lcdrive, @lpFreeBytesAvailableToCaller,@lpTotalNumberOfBytes, ;
>		@lpTotalNumberOfFreeBytes) > 0
>
>		lpFreeBytesAvailableToCaller = str2long(lpFreeBytesAvailableToCaller)
>		lpTotalNumberOfBytes = str2long(lpTotalNumberOfBytes)
>		lpTotalNumberOfFreeBytes = str2long(lpTotalNumberOfFreeBytes)
>		lpTotalBytesUsed = lpTotalNumberOfBytes- MAX(lpFreeBytesAvailableToCaller,lpTotalNumberOfFreeBytes)
>		DO CASE
>		CASE UPPER(m.lcdrivevalue) = "FREE"
>			m.nreturnvalue = MIN(lpFreeBytesAvailableToCaller,lpTotalNumberOfFreeBytes)
>		CASE UPPER(m.lcdrivevalue) = "FULL"
>			m.nreturnvalue = lpTotalNumberOfBytes
>		CASE UPPER(m.lcdrivevalue) = "USED"
>			m.nreturnvalue = lpTotalBytesUsed
>		ENDCASE
>	endif
>	GetDiskFreeSpace = .null.
>	release GetDiskFreeSpace
>	RETURN m.nreturnvalue
>
censored.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform