locked
GetSystemPowerStatusEx2 gave Error Code 87?? Invalid parameter. What does that mean? RRS feed

  • Question

  •  

    Hi all,

    I am also facing another problem on GetSystemPowerStatusEx2. I dont understand what is wrong in the code as I have tried many ways to fix it. I also found that there is not enough information on the usage of this function. Can anyone shed some lights what I have done wrong which cause the error code 87? What does this mean? Why the function always return 0? Thanks.

     

    In C#:
    =====
    public

    In C#:
    =====
    public

     

    struct _SYSTEM_POWER_STATUS_EX2
    {
    public byte ACLineStatus;
    public byte BatteryFlag;
    public byte BatteryLifePercent;
    public byte Reserved1;
    public uint BatteryLifeTime;
    public uint BatteryFullLifeTime;
    public byte Reserved2;
    public byte BackupBatteryFlag;
    public byte BackupBatteryLifePercent;
    public byte Reserved3;
    public uint BackupBatteryLifeTime;
    public uint BackupBatteryFullLifeTime;
    public uint BatteryVoltage;
    public uint BatteryCurrent;
    public uint BatteryAverageCurrent;
    public uint BatteryAverageInterval;
    public uint BatterymAHourConsumed;
    public uint BatteryTemperature;
    public uint BackupBatteryVoltage;
    public byte BatteryChemistry;
    [
    MarshalAs(UnmanagedType.ByValArray, SizeConst=128)]
    public byte[] ExtraInfo;
    }

    private

     

    _SYSTEM_POWER_STATUS_EX2 SystemPowerStatusEX2;
    SystemPowerStatusEX2 = new _SYSTEM_POWER_STATUS_EX2();

     

    public bool MS_GetSystemPowerStatusEx2()
    {
    bool ret_value = false;

     

    if (GetSystemPowerStatusEx2(SystemPowerStatusEX2, (uint)Marshal.SizeOf(typeof   (_SYSTEM_POWER_STATUS_EX2)), false) != 0)
     {
         ret_value =
    true;
     }
     return ret_value;
    }

    [

    DllImport("coredll.dll", EntryPoint = "GetSystemPowerStatusEx2", SetLastError = true)]
    private static extern uint GetSystemPowerStatusEx2(_SYSTEM_POWER_STATUS_EX2 pSystemPowerStatusEx2, uint dwLen, bool fUpdate);

    Tuesday, February 23, 2010 7:57 AM

Answers


  • Please read the following article on how to P/Invoke the GetSystemPowerStatusEx2 function:

    HOWTO: Get the Device Power Status
    http://msdn.microsoft.com/en-us/library/aa457088.aspx 

    If you have further questions, please don't forget to mention the dev environment (the type of the device and the version of .NET CF, etc.). 
     
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by warrentang Monday, March 1, 2010 5:08 AM
    Friday, February 26, 2010 6:01 AM

All replies


  • Please read the following article on how to P/Invoke the GetSystemPowerStatusEx2 function:

    HOWTO: Get the Device Power Status
    http://msdn.microsoft.com/en-us/library/aa457088.aspx 

    If you have further questions, please don't forget to mention the dev environment (the type of the device and the version of .NET CF, etc.). 
     
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by warrentang Monday, March 1, 2010 5:08 AM
    Friday, February 26, 2010 6:01 AM
  • Thanks Chun Sheng for your reply.

    I have followed both of the articles but, still fail
    Monday, March 1, 2010 8:29 AM


  • If you have further questions, please don't forget to mention the dev environment (the type of the device and the version of .NET CF, etc.). 
      
    You added little information with your last reply. Could you be more specific about " still fail"? What kind of information do you want to get with the GetSystemPowerStatusEx2 function?

    Here are my thoughts for now:

    1. Replace "(uint)Marshal.SizeOf(typeof   (_SYSTEM_POWER_STATUS_EX2))" with "(uint)Marshal.SizeOf(SystemPowerStatusEX2)" as you declared _SYSTEM_POWER_STATUS_EX2 as a structure type.

    2. Try GetSystemPowerStatusEx instead of GetSystemPowerStatusEx2.

    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Monday, March 1, 2010 8:53 AM