Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get disk size and memory
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00856759
Message ID:
00856831
Vues:
27
>Thanks Borislay, but can you please show me
>how to get total size of RAM ?

Maybe this will help. It returns more than you are asking for but can be easily modified to get teh values that you are looking for.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform