Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

GetSystemPowerStatus

Why do I get "Object reference not set to an instance of an object" when the API is called?




Public Structure SYSTEM_POWER_STATUS
    Public ACLineStatus As Byte
    Public BatteryFlag As Byte
    Public BatteryLifePercent As Byte
    Public Reserved1 As Byte
    Public BatteryLifeTime As Integer
    Public BatteryFullLifeTime As Integer
End Structure



  Public Function BatteryStatus() As SYSTEM_POWER_STATUS



        Try
            Dim ps As New SYSTEM_POWER_STATUS
            GetSystemPowerStatus(ps)
            Return ps

        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try



    End Function


0
Neal Hartman
Asked:
Neal Hartman
1 Solution
 
RonaldBiemansCommented:
How is the api declared  because this worked

 Declare Function GetSystemPowerStatus Lib "kernel32" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Integer

Public Function BatteryStatus() As SYSTEM_POWER_STATUS

        Try
            Dim ps As New SYSTEM_POWER_STATUS
            GetSystemPowerStatus(ps)
            Return ps

        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try

    End Function

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim yy As New SYSTEM_POWER_STATUS
        yy = BatteryStatus()
        Dim x As Integer = GetSystemPowerStatus(yy)
end sub
0
 
Neal HartmanAuthor Commented:
I had byval in the api.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now