nExtMem() and Os()

nExtMem() and Os()

Postby sambomb » Mon Feb 22, 2016 1:23 pm

nExtMem() isn't returning the correct amount of memory and the OS() function doensn't work in windows 8 or above, returning windows NT instead

Is this related to my FWH / xHarbour version?

Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 6715)
FiveWin Version: FWHX 10.6
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: nExtMem() and Os()

Postby karinha » Mon Feb 22, 2016 1:38 pm

Code: Select all  Expand view

// GETSYSIN.PRG

#include "FiveWin.ch"

#define HORZRES             8
#define VERTRES            10
#Define BITSPIXEL          12
#define PLANES             14
#define LOGPIXELSX         88
#define LOGPIXELSY         90    

//----------------------------------------------------------------------------//

Function LargeFonts( nPixelX, nPixelY )

  Local hDC

  hDC     := CreateDC( "DISPLAY", "", "" )
  nPixelX := GetDeviceCaps( hDC, LOGPIXELSX )
  nPixelY := GetDeviceCaps( hDC, LOGPIXELSY )

  DeleteDC( hDC )

Return ( nPixelX >= 120 )

//----------------------------------------------------------------------------//

function DispFontPerSize()

   local hDC, nPixelX

   hDC     = CreateDC( "DISPLAY", "", "" )
   nPixelX = GetDeviceCaps( hDC, LOGPIXELSX )

   DeleteDC( hDC )

return ( nPixelX / 96 )

//----------------------------------------------------------------------------//

function ColorsQty()

   local hDC, nPlanes, nBitsPixel

   hDC        = CreateDC( "DISPLAY", "", "" )
   nPlanes    = GetDeviceCaps( hDC, PLANES )
   nBitsPixel = GetDeviceCaps( hDC, BITSPIXEL )

   DeleteDC( hDC )

return Int( 2 ^ ( nPlanes * nBitsPixel ) )

//----------------------------------------------------------------------------//

function ScrResolution( nWidth, nHeight )

   local hDC

   hDC     = CreateDC( "DISPLAY", "", "" )
   nWidth  = GetDeviceCaps( hDC, HORZRES )
   nHeight = GetDeviceCaps( hDC, VERTRES )

   DeleteDC( hDC )

return { nWidth, nHeight }

//----------------------------------------------------------------------------//

#ifdef __CLIPPER__

function cWinVersion()

   local cVersion := ""

   If IsWin95()
      cVersion = "95"

   elseif IsWinNT()
      if GetWinVer()[ 2 ] == 95
         cVersion = "2000"
      else
         cVersion = "NT"
      endif
   endif

return cVersion

#else

#define VER_PLATFORM_WIN32s         0
#define VER_PLATFORM_WIN32_WINDOWS  1
#define VER_PLATFORM_WIN32_NT       2

function cWinVersion()

   local aVersion := GetVersion()
   local cVersion := ""

   do case
      case aVersion[ 4 ] == VER_PLATFORM_WIN32_NT
           if aVersion[ 1 ] == 6
             if aVersion[ 2 ] == 0
                cVersion = "Vista"
             elseif aVersion[ 2 ] == 1
                cVersion = "7"
             elseif aVersion[ 2 ] == 2
                if IsWindows10()                 
                   cVersion = "10"
                else                         
                   cVersion = "8"  
                endif                            
             endif
           endif  
                 
           if aVersion[ 1 ] == 5
              if aVersion[ 2 ] == 2
                 cVersion = "Server 2003"
              elseif aVersion[ 2 ] == 1
                 cVersion = "XP"
              elseif aVersion[ 2 ] == 0
                 cVersion = "2000"
              endif
           endif

           if aVersion[ 1 ] <= 4
              cVersion = "NT"
           endif

      case aVersion[ 4 ] == VER_PLATFORM_WIN32_WINDOWS
           if aVersion[ 1 ] == 4
              if aVersion[ 2 ] == 90
                 cVersion = "ME"
              elseif aVersion[ 2 ] == 10
                 cVersion = "98"
              elseif aVersion[ 2 ] == 0
                 cVersion = "95"
              endif
           endif
   endcase

   cVersion += IF( IsWin64(), " de 64 ", " de 32 " ) + "Bits"

return cVersion

#endif

//----------------------------------------------------------------------------//

function IsWinVista()

return ( "Vista" $ cWinVersion() )

//----------------------------------------------------------------------------//

function IsWinXP()

return ( "XP" $ cWinVersion() )

//----------------------------------------------------------------------------//

function IsWin2000()

return ( "2000" $ cWinVersion() )

//----------------------------------------------------------------------------//

function IsWin7()

return "7" $ cWinVersion()

//----------------------------------------------------------------------------//

function IsWin8()

return "8" == cWinVersion()

//----------------------------------------------------------------------------//

#define  HKEY_LOCAL_MACHINE  2147483650  // 0x80000002

function IsWindows10()

   local oReg := TReg32():New( HKEY_LOCAL_MACHINE,;
                               "SOFTWARE\Microsoft\Windows NT\CurrentVersion",;
                               .f. )
   local cProductName := oReg:Get( "ProductName" )

   oReg:Close()

return "Windows 10" $ cProductName

//----------------------------------------------------------------------------//

function GetSysFont()

   do case
      case ! IsWinNt() .and. ! IsWin95()  // Win 3.1
           return "System"

      #ifdef __CLIPPER__   // A.L. 28/04/03, It fails with FWH/FW++
         case IsWin2000()  // Win2000
              return "Ms Sans Serif" // "SysTahoma"
      #endif

   endcase

return "Ms Sans Serif"  // Win NT, 9x

//----------------------------------------------------------------------------//

function BorlandVersion()
   
   #ifdef __XHARBOUR__
      local cHexVer := NumToHex( BorlandC() )
   #else  
      local cHexVer := hb_NumToHex( BorlandC() )
   #endif

return SubStr( cHexVer, 1, 1 ) + "." + SubStr( cHexVer, 2 )

//----------------------------------------------------------------------------//

function SaveDesktop( cPngFileName )

   local o := TWindow()
   
   DestroyWindow( o:hWnd )
   o:hWnd = GetDesktopWindow()
   o:SaveToPng( cPngFileName )
   
return nil

//----------------------------------------------------------------------------//  

#define SM_CXFULLSCREEN  16
#define SM_CYFULLSCREEN  17

function ScreenWidth()

return GetSysMetrics( SM_CXFULLSCREEN )

function ScreenHeight()

return GetSysMetrics( SM_CYFULLSCREEN )

//----------------------------------------------------------------------------//  

function IsWin64()

return ! Empty( GetEnv( "ProgramFiles(x86)" ) )

//----------------------------------------------------------------------------//
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: nExtMem() and Os()

Postby sambomb » Mon Feb 22, 2016 2:24 pm

Gostaria de utilizar a função OS pois ela já retorna o modelo do SO também pois alguns modelos geram incompatibilidade, como o windows 7 starter...

? "Versão windows: " + OS() //Versão windows: Windows 7 Professional 6.01.7601 Service Pack 1
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: nExtMem() and Os()

Postby karinha » Mon Feb 22, 2016 2:47 pm

sambomb wrote:Gostaria de utilizar a função OS pois ela já retorna o modelo do SO também pois alguns modelos geram incompatibilidade, como o windows 7 starter...

? "Versão windows: " + OS() //Versão windows: Windows 7 Professional 6.01.7601 Service Pack 1


look, mira, olha:

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=31789&p=185657&hilit=tsystem#p185657

http://fivewin.com.br/index.php?/topic/24424-classe-tsysteminfo/?hl=getsysin#entry272884

http://fivewin.com.br/index.php?/topic/23851-verificar-memoria-do-computador/?hl=nextmem

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: nExtMem() and Os()

Postby sambomb » Tue Feb 23, 2016 11:33 am

a nExtMem está retornando valores inválidos, minha máquina é um Windows 7 que tem 4 GB ( utilizável 3,24 ) sendo que reconhece apenas 2 GB em uma máquina com Windows 8.1, reconhece como negativo!
E a função Os() é nativa do xHarbour, mas parece que não foi atualizada, ela retorna todas as informações que eu preciso, queria saber não apenas a versão do Windows, mas também o tipo de licença dele como disse acima, mas muito obrigado, estou desenvolvendo uma rotina que poderei aproveitar trechos dessa TSystem
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: nExtMem() and Os()

Postby karinha » Tue Feb 23, 2016 2:04 pm

Windows 8.1, reconhece como negativo?

Você incorporou o GETSYSIN.PRG modificado por mim, logo acima?

Você tem a função Os() do xHarbour? Talvez o Marcelo Lombardo tenha uma mais recente.

Seria algo assim?

http://www.pctoledo.com.br/forum/viewtopic.php?f=4&t=16163

Abs.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: nExtMem() and Os()

Postby sambomb » Wed Feb 24, 2016 11:32 am

Não só no Windows 8.1

--> DadosSO

Versão windows: Windows 7 Professional 6.01.7601 Service Pack 1
Processador: AMD Athlon(tm) II X2 250 Processor 3017 Mhz
Data: 23/02/2016
Hora: 14:30:07
Nome de rede: LAZZO-PC
Usuário de rede: Lazzo
Acesso de gravação no 'C:\': True
Driver's ( 1 )
C: Serial: 4873455 Tamanho total: 465.662 GB Utilizado: 61.306 GB Restante: 404.356 GB
Cache HD: Cache não habilitado
Arquivos off-line: Desabilitado
Code: Select all  Expand view
aAdd( ::aTexto,"Memória: " + cValToChar( Int( nExtMem() / ( 1024 * 1024 ) ) + 1 ) + " MBs" )

Memória: -255 MBs
Memória livre - Sistema: 90 %
Memória livre - GDI: 90 %
Memória livre - User: 90 %
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: nExtMem() and Os()

Postby Carlos Mora » Wed Feb 24, 2016 2:50 pm

Don't know about xHarbour, but probably this is sth related to the numeric type used by nExtMem() an xHabour's integers. Using a 4 byte UNSIGNED LONG we can represent integers from 0 to 256^4-1, or 4,294,967,295, or SIGNED, ranging from -2,147,483,647 TO 2,147,483,648. I think the function is working fine, but returning an UNSIGNED LONG that xHarbour is handling as signed, so that's why you ar getting negative results. A quick temporary patch can be that, in case of a negative result, it should be substracted from 256^4-1, wich will result in your case to 3840 Mb, that is your claimd free mem.
Obvously, this patch will fail in PC with more than 4 GB, as probably will do anything in 32 bits with results expresing byte counts that a 4 byte LONG won't be able to represent.
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: nExtMem() and Os()

Postby karinha » Wed Feb 24, 2016 3:48 pm

Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   LOCAL cMemoria, nBytes, nKBytes, nMBytes, nGBytes

   nBytes  := nExtMem()
 
   nKBytes := nBytes / 1014
 
   nMBytes := nKBytes / 1024
 
   nGBytes := nMBytes / 1014

   // Com erro - With Error
   //  aAdd( ::aTexto,"Memória: " + cValToChar( Int( nExtMem() / ( 1024 * 1024 ) ) + 1 ) + " MBs" )
   ? ( "Memóry Error: " + cValToChar( Int( nExtMem() / ( 1024 * 1024 ) ) + 1 ) + " MBs" )

   ? cMemoria := Trans( nExtMem(), "@E 9,999,999,999 Bytes free" )

   ? cMemoria := Trans( ( nExtMem() / ( 1024 * 1024 * 1014 ) ), "@E 999.99 GB Free" )

                                                       // or .97 = 4 Gbs.
   ? cMemoria := Trans( ( nExtMem() / ( 1024 * 1024 * 1014 ) + 1 ), "@E 999.99 GB Total" )

RETURN NIL

// END OF PROGRAM
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 102 guests