?
Solved

GetSystemPowerStatus

Posted on 2005-03-17
2
Medium Priority
?
597 Views
Last Modified: 2008-01-09
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
Comment
Question by:Neal Hartman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 2000 total points
ID: 13565753
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
 
LVL 1

Author Comment

by:Neal Hartman
ID: 13565862
I had byval in the api.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question