Thanks for that I tried there code all I get is a zero in the text box, it deploys to the pda fine but just shows 0%
I'm getting warnings though on the following functions.
* type of member (all of the below) is not CLS-compliant
Any ideas?
Code:
' SYSTEM_POWER_STATUS_EX2
Public BatteryLifeTime As System.UInt32
Public BatteryFullLifeTime As System.UInt32
Public BackupBatteryLifeTime As System.UInt32
Public BackupBatteryFullLifeTime As System.UInt32
Public BatteryVoltage As System.UInt32
Public BatteryCurrent As System.UInt32
Public BatteryAverageCurrent As System.UInt32
Public BatteryAverageInterval As System.UInt32
Public BatterymAHourConsumed As System.UInt32
Public BatteryTemperature As System.UInt32
Public BackupBatteryVoltage As System.UInt32
'SYSTEM_POWER_STATUS_EX
Public BatteryLifeTime As System.UInt32
Public BatteryFullLifeTime As System.UInt32
Public BackupBatteryLifeTime As System.UInt32
Public BackupBatteryFullLifeTime As System.UInt32
Heres the code
Code:
Imports System.Runtime.InteropServices
Public Class Form1
' VB
Public Class SYSTEM_POWER_STATUS_EX2
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As System.UInt32
Public BatteryFullLifeTime As System.UInt32
Public Reserved2 As Byte
Public BackupBatteryFlag As Byte
Public BackupBatteryLifePercent As Byte
Public Reserved3 As Byte
Public BackupBatteryLifeTime As System.UInt32
Public BackupBatteryFullLifeTime As System.UInt32
Public BatteryVoltage As System.UInt32
Public BatteryCurrent As System.UInt32
Public BatteryAverageCurrent As System.UInt32
Public BatteryAverageInterval As System.UInt32
Public BatterymAHourConsumed As System.UInt32
Public BatteryTemperature As System.UInt32
Public BackupBatteryVoltage As System.UInt32
Public BatteryChemistry As Byte
End Class 'SYSTEM_POWER_STATUS_EX2
Public Class SYSTEM_POWER_STATUS_EX
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As System.UInt32
Public BatteryFullLifeTime As System.UInt32
Public Reserved2 As Byte
Public BackupBatteryFlag As Byte
Public BackupBatteryLifePercent As Byte
Public Reserved3 As Byte
Public BackupBatteryLifeTime As System.UInt32
Public BackupBatteryFullLifeTime As System.UInt32
End Class 'SYSTEM_POWER_STATUS_EX
'VB
<DllImport("coredll")> _
Private Shared Function GetSystemPowerStatusEx( _
ByVal lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, _
ByVal fUpdate As Boolean) As System.UInt32
End Function
<DllImport("coredll")> _
Private Shared Function GetSystemPowerStatusEx2(ByVal _
lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX2, _
ByVal dwLen As System.UInt32, ByVal fUpdate As Boolean) _
As System.UInt32
End Function
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = System.Windows.Forms.Keys.Up) Then
'Rocker Up
'Up
End If
If (e.KeyCode = System.Windows.Forms.Keys.Down) Then
'Rocker Down
'Down
End If
If (e.KeyCode = System.Windows.Forms.Keys.Left) Then
'Left
End If
If (e.KeyCode = System.Windows.Forms.Keys.Right) Then
'Right
End If
If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
'Enter
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim status As New SYSTEM_POWER_STATUS_EX
Dim status2 As New SYSTEM_POWER_STATUS_EX2
If Convert.ToInt32(GetSystemPowerStatusEx(status, False)) = 1 Then
TextBox1.Text = String.Format("{0}%", status.BatteryLifePercent)
End If
If Convert.ToInt32(GetSystemPowerStatusEx2(status2, _
Convert.ToUInt32(Marshal.SizeOf(status2)), False)) = _
Marshal.SizeOf(status2) Then
TextBox1.Text = String.Format("{0}%",status2.BackupBatteryLifePercent)
End If
End Sub
End Class