Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
System Power Status
Message
 
To
05/04/2000 08:49:14
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00355606
Message ID:
00355621
Views:
18
>Hi there
>
>I'm trying to use the GetSystemPowerStatus call for use on a laptop when the power gets low. The structure is...
>
>Type SYSTEM_POWER_STATUS
> ACLineStatus As Byte
> BatteryFlag As Byte
> BatteryLifePercent As Byte
> Reserved1 As Byte
> BatteryLifeTime As Long
> BatteryFullLifeTime As Long
>End Type
>
>My VFP code is...
>
>DECLARE INTEGER GetSystemPowerStatus IN KERNEL32 STRING @lpStatus
>
>lpStatus = REPLICATE(CHR(0), 12)
>GetSystemPowerStatus(@lpStatus)
>
>However, I'm having a bit of trouble converting the return string back to anything meaningful. All the conversion routines from Hex To Dec I've seen always return 0. I'm using NT sp4. Is this an NT thing or I am just being thick???
>
>Cheers
Arthur,

You can convert the values with the following:
FUNCTION StringToInteger
    
  LPARAMETER pcstring, plsigned
    
  LOCAL lnresult, lnlast, lni, llsigned,;
    lnmsb, lnmax
  lnresult = 0
  lnlast = LEN(pcstring)
  * Return Signed Integer?
  IF PCOUNT() = 2
    llsigned = plsigned
  ELSE
    llsigned = .F.
  ENDIF
  FOR lni = 1 TO lnlast
    lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1))
  NEXT
  IF llsigned
    lnmsb = (lnlast * 8) - 1
    IF BITTEST(lnresult, lnmsb)
      lnmax = (2 ^ (lnmsb + 1))
      lnresult = lnresult - lnmax
    ENDIF
  ENDIF
  RETURN lnresult
ENDFUNC
* Usage
lnlinestat = StringToInteger(LEFT(lpStatus, 1))
lnbattflag = StringToInteger(SUBSTR(lpStatus, 2, 1))
lnbattpct = StringToInteger(SUBSTR(lpStatus, 3, 1))
lnreserved = StringToInteger(SUBSTR(lpStatus, 4, 1)) && Not really necessary
lnlifetime = StringToInteger(SUBSTR(lpStatus, 5, 4))
lnfulllife = StringToInteger(RIGHT(lpStatus, 4))
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform