GetSystemPowerStatusEx (coredll)
Last changed: -77.79.231.158

.
Summary
This will return the current status of the battery on a mobile device

C# Signature:

[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.U4)]
public static extern int GetSystemPowerStatusEx2(SYSTEM_POWER_STATUS_EX2 pSystemPowerStatusEx2, [MarshalAs(UnmanagedType.U4), In] int dwLen, [MarshalAs(UnmanagedType.Bool), In] bool fUpdate);

VB Signature:

Declare Function GetSystemPowerStatusEx2 Lib "Coredll.dll" (TODO) As TODO

User-Defined Types:

SYSTEM_POWER_STATUS_EX2

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

The return is the size of the structure. It returns 0 if there was an error.

Tips & Tricks:

Please add some!

Sample Code:

SYSTEM_POWER_STATUS_EX2 SystemPowerStatusEx2 = new SYSTEM_POWER_STATUS_EX2();
if (GetSystemPowerStatusEx2(SystemPowerStatusEx2, Marshal.SizeOf(SystemPowerStatusEx2), true) > 0) {
       //run some battery code
}

Documentation