JwaBatClass.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:11k
源码类别:

Windows编程

开发平台:

Delphi

  1. {******************************************************************************}
  2. {                                                                       }
  3. { Battery class driver API interface Unit for Object Pascal                    }
  4. {                                                                       }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          }
  6. { Corporation. All Rights Reserved.                                            }
  7. {                 }
  8. { The original file is: batclass.h, released June 2000. The original Pascal    }
  9. { code is: BatClass.pas, released December 2000. The initial developer of the  }
  10. { Pascal code is Marcel van Brakel (brakelm@chello.nl).                        }
  11. {                                                                              }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001            }
  13. { Marcel van Brakel. All Rights Reserved.                                      }
  14. {                 }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
  16. {                }
  17. { You may retrieve the latest version of this file at the Project JEDI home    }
  18. { page, located at http://delphi-jedi.org or my personal homepage located at   }
  19. { http://members.chello.nl/m.vanbrakel2                                        }
  20. {                }
  21. { The contents of this file are used with permission, subject to the Mozilla   }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at      }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html                                      }
  25. {                                                                              }
  26. { Software distributed under the License is distributed on an "AS IS" basis,   }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License.    }
  29. {                                                                              }
  30. { Alternatively, the contents of this file may be used under the terms of the  }
  31. { GNU Lesser General Public License (the  "LGPL License"), in which case the   }
  32. { provisions of the LGPL License are applicable instead of those above.        }
  33. { If you wish to allow use of your version of this file only under the terms   }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting  the provisions above and  }
  36. { replace  them with the notice and other provisions required by the LGPL      }
  37. { License.  If you do not delete the provisions above, a recipient may use     }
  38. { your version of this file under either the MPL or the LGPL License.          }
  39. {                 }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. {                 }
  42. {******************************************************************************}
  43. unit JwaBatClass;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "BatClass.h"'}
  47. {$HPPEMIT ''}
  48. {$I WINDEFINES.INC}
  49. interface
  50. uses
  51.   JwaWinIoctl, JwaWinType;
  52. //
  53. // Battery device GUID
  54. //
  55. const
  56.   GUID_DEVICE_BATTERY: TGUID = (D1:$72631e54; D2:$78A4; D3:$11d0; D4:($bc, $f7, $00, $aa, $00, $b7, $b3, $2a));
  57.   {$EXTERNALSYM GUID_DEVICE_BATTERY}
  58.   BATTERY_STATUS_WMI_GUID: TGUID = (D1:$fc4670d1; D2:$ebbf; D3:$416e; D4:($87, $ce, $37, $4a, $4e, $bc, $11, $1a));
  59.   {$EXTERNALSYM BATTERY_STATUS_WMI_GUID}
  60.   BATTERY_RUNTIME_WMI_GUID: TGUID = (D1:$535a3767; D2:$1ac2; D3:$49bc; D4:($a0, $77, $3f, $7a, $02, $e4, $0a, $ec));
  61.   {$EXTERNALSYM BATTERY_RUNTIME_WMI_GUID}
  62.   BATTERY_TEMPERATURE_WMI_GUID: TGUID = (D1:$1a52a14d; D2:$adce; D3:$4a44; D4:($9a, $3e, $c8, $d8, $f1, $5f, $f2, $c2));
  63.   {$EXTERNALSYM BATTERY_TEMPERATURE_WMI_GUID}
  64.   BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID: TGUID = (D1:$40b40565; D2:$96f7; D3:$4435; D4:($86, $94, $97, $e0, $e4, $39, $59, $05));
  65.   {$EXTERNALSYM BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID}
  66.   BATTERY_CYCLE_COUNT_WMI_GUID: TGUID = (D1:$ef98db24; D2:$0014; D3:$4c25; D4:($a5, $0b, $c7, $24, $ae, $5c, $d3, $71));
  67.   {$EXTERNALSYM BATTERY_CYCLE_COUNT_WMI_GUID}
  68.   BATTERY_STATIC_DATA_WMI_GUID: TGUID = (D1:$05e1e463; D2:$e4e2; D3:$4ea9; D4:($80, $cb, $9b, $d4, $b3, $ca, $06, $55));
  69.   {$EXTERNALSYM BATTERY_STATIC_DATA_WMI_GUID}
  70.   BATTERY_STATUS_CHANGE_WMI_GUID: TGUID = (D1:$cddfa0c3; D2:$7c5b; D3:$4e43; D4:($a0, $34, $05, $9f, $a5, $b8, $43, $64));
  71.   {$EXTERNALSYM BATTERY_STATUS_CHANGE_WMI_GUID}
  72.   BATTERY_TAG_CHANGE_WMI_GUID: TGUID = (D1:$5e1f6e19; D2:$8786; D3:$4d23; D4:($94, $fc, $9e, $74, $6b, $d5, $d8, $88));
  73.   {$EXTERNALSYM BATTERY_TAG_CHANGE_WMI_GUID}
  74. //
  75. // Battery driver interface
  76. //
  77. // IOCTL_BATTERY_QUERY_TAG
  78. // IOCTL_BATTERY_QUERY_INFORMATION
  79. // IOCTL_BATTERY_SET_INFORMATION
  80. // IOCTL_BATTERY_QUERY_STATUS
  81. //
  82. //
  83. // IOCTL_BATTERY_QUERY_TAG
  84. //
  85.   IOCTL_BATTERY_QUERY_TAG = (FILE_DEVICE_BATTERY shl 16) or (FILE_READ_ACCESS shl 14) or ($10 shl 2) or METHOD_BUFFERED;
  86.   {$EXTERNALSYM IOCTL_BATTERY_QUERY_TAG}
  87.   BATTERY_TAG_INVALID = 0;
  88.   {$EXTERNALSYM BATTERY_TAG_INVALID}
  89. //
  90. // IOCTL_BATTERY_QUERY_INFORMATION
  91. //
  92.   IOCTL_BATTERY_QUERY_INFORMATION = (FILE_DEVICE_BATTERY shl 16) or (FILE_READ_ACCESS shl 14) or ($11 shl 2) or METHOD_BUFFERED;
  93.   {$EXTERNALSYM IOCTL_BATTERY_QUERY_INFORMATION}
  94. type
  95.   BATTERY_QUERY_INFORMATION_LEVEL = (
  96.     BatteryInformation,
  97.     BatteryGranularityInformation,
  98.     BatteryTemperature,
  99.     BatteryEstimatedTime,
  100.     BatteryDeviceName,
  101.     BatteryManufactureDate,
  102.     BatteryManufactureName,
  103.     BatteryUniqueID,
  104.     BatterySerialNumber);
  105.   {$EXTERNALSYM BATTERY_QUERY_INFORMATION_LEVEL}
  106.   TBatteryQueryInformationLevel = BATTERY_QUERY_INFORMATION_LEVEL;
  107.   _BATTERY_QUERY_INFORMATION = record
  108.     BatteryTag: ULONG;
  109.     InformationLevel: BATTERY_QUERY_INFORMATION_LEVEL;
  110.     AtRate: LONG;
  111.   end;
  112.   {$EXTERNALSYM _BATTERY_QUERY_INFORMATION}
  113.   BATTERY_QUERY_INFORMATION = _BATTERY_QUERY_INFORMATION;
  114.   {$EXTERNALSYM BATTERY_QUERY_INFORMATION}
  115.   PBATTERY_QUERY_INFORMATION = ^BATTERY_QUERY_INFORMATION;
  116.   {$EXTERNALSYM PBATTERY_QUERY_INFORMATION}
  117.   TBatteryQueryInformation = BATTERY_QUERY_INFORMATION;
  118.   PBatteryQueryInformation = PBATTERY_QUERY_INFORMATION;
  119. //
  120. // Format of data returned when
  121. // BATTERY_INFORMATION_LEVEL = BatteryInformation
  122. //
  123.   _BATTERY_INFORMATION = record
  124.     Capabilities: ULONG;
  125.     Technology: UCHAR;
  126.     Reserved: array [0..2] of UCHAR;
  127.     Chemistry: array [0..3] of UCHAR;
  128.     DesignedCapacity: ULONG;
  129.     FullChargedCapacity: ULONG;
  130.     DefaultAlert1: ULONG;
  131.     DefaultAlert2: ULONG;
  132.     CriticalBias: ULONG;
  133.     CycleCount: ULONG;
  134.   end;
  135.   {$EXTERNALSYM _BATTERY_INFORMATION}
  136.   BATTERY_INFORMATION = _BATTERY_INFORMATION;
  137.   {$EXTERNALSYM BATTERY_INFORMATION}
  138.   PBATTERY_INFORMATION = ^BATTERY_INFORMATION;
  139.   {$EXTERNALSYM PBATTERY_INFORMATION}
  140.   TBatteryInformation = BATTERY_INFORMATION;
  141.   PBatteryInformation = PBATTERY_INFORMATION;
  142. //
  143. // BATTERY_INFORMATION.Capabilities flags
  144. //
  145. const
  146.   BATTERY_SYSTEM_BATTERY          = DWORD($80000000);
  147.   {$EXTERNALSYM BATTERY_SYSTEM_BATTERY}
  148.   BATTERY_CAPACITY_RELATIVE       = $40000000;
  149.   {$EXTERNALSYM BATTERY_CAPACITY_RELATIVE}
  150.   BATTERY_IS_SHORT_TERM           = $20000000;
  151.   {$EXTERNALSYM BATTERY_IS_SHORT_TERM}
  152.   BATTERY_SET_CHARGE_SUPPORTED    = $00000001;
  153.   {$EXTERNALSYM BATTERY_SET_CHARGE_SUPPORTED}
  154.   BATTERY_SET_DISCHARGE_SUPPORTED = $00000002;
  155.   {$EXTERNALSYM BATTERY_SET_DISCHARGE_SUPPORTED}
  156.   BATTERY_SET_RESUME_SUPPORTED    = $00000004;
  157.   {$EXTERNALSYM BATTERY_SET_RESUME_SUPPORTED}
  158. //
  159. // BATTERY_INFORMATION.XXXCapacity constants
  160. //
  161.   BATTERY_UNKNOWN_CAPACITY = DWORD($FFFFFFFF);
  162.   {$EXTERNALSYM BATTERY_UNKNOWN_CAPACITY}
  163. //
  164. // BatteryEstimatedTime constant
  165. //
  166.   BATTERY_UNKNOWN_TIME = DWORD($FFFFFFFF);
  167.   {$EXTERNALSYM BATTERY_UNKNOWN_TIME}
  168. //
  169. // Max battery driver BATTERY_QUERY_INFORMATION_LEVEL string storage
  170. // size in bytes.
  171. //
  172.   MAX_BATTERY_STRING_SIZE = 128;
  173.   {$EXTERNALSYM MAX_BATTERY_STRING_SIZE}
  174. //
  175. // Struct for accessing the packed date format in BatteryManufactureDate.
  176. //
  177. type
  178.   _BATTERY_MANUFACTURE_DATE = record
  179.     Day: UCHAR;
  180.     Month: UCHAR;
  181.     Year: USHORT;
  182.   end;
  183.   {$EXTERNALSYM _BATTERY_MANUFACTURE_DATE}
  184.   BATTERY_MANUFACTURE_DATE = _BATTERY_MANUFACTURE_DATE;
  185.   {$EXTERNALSYM BATTERY_MANUFACTURE_DATE}
  186.   PBATTERY_MANUFACTURE_DATE = ^BATTERY_MANUFACTURE_DATE;
  187.   {$EXTERNALSYM PBATTERY_MANUFACTURE_DATE}
  188.   TBatteryManufactureDate = BATTERY_MANUFACTURE_DATE;
  189.   PBatteryManufactureDate = PBATTERY_MANUFACTURE_DATE;
  190. //
  191. // IOCTL_BATTERY_SET_INFORMATION
  192. //
  193. const
  194.   IOCTL_BATTERY_SET_INFORMATION = (FILE_DEVICE_BATTERY shl 16) or (FILE_WRITE_ACCESS shl 14) or ($12 shl 2) or METHOD_BUFFERED;
  195.   {$EXTERNALSYM IOCTL_BATTERY_SET_INFORMATION}
  196. type
  197.   BATTERY_SET_INFORMATION_LEVEL = (
  198.     BatteryCriticalBias,
  199.     BatteryCharge,
  200.     BatteryDischarge);
  201.   {$EXTERNALSYM BATTERY_SET_INFORMATION_LEVEL}
  202.   TBatterySetInformationLevel = BATTERY_SET_INFORMATION_LEVEL;
  203.   _BATTERY_SET_INFORMATION = record
  204.     BatteryTag: ULONG;
  205.     InformationLevel: BATTERY_SET_INFORMATION_LEVEL;
  206.     Buffer: array [0..0] of UCHAR;
  207.   end;
  208.   {$EXTERNALSYM _BATTERY_SET_INFORMATION}
  209.   BATTERY_SET_INFORMATION = _BATTERY_SET_INFORMATION;
  210.   {$EXTERNALSYM BATTERY_SET_INFORMATION}
  211.   PBATTERY_SET_INFORMATION = ^BATTERY_SET_INFORMATION;
  212.   {$EXTERNALSYM PBATTERY_SET_INFORMATION}
  213.   TBatterySetInformation = BATTERY_SET_INFORMATION;
  214.   PBatterySetInformation = PBATTERY_SET_INFORMATION;
  215. //
  216. // IOCTL_BATTERY_QUERY_STATUS
  217. //
  218. const
  219.   IOCTL_BATTERY_QUERY_STATUS = (FILE_DEVICE_BATTERY shl 16) or (FILE_READ_ACCESS shl 14) or ($13 shl 2) or METHOD_BUFFERED;
  220.   {$EXTERNALSYM IOCTL_BATTERY_QUERY_STATUS}
  221. //
  222. // Structure of input buffer to IOCTL_BATTERY_QUERY_STATUS
  223. //
  224. type
  225.   _BATTERY_WAIT_STATUS = record
  226.     BatteryTag: ULONG;
  227.     Timeout: ULONG;
  228.     PowerState: ULONG;
  229.     LowCapacity: ULONG;
  230.     HighCapacity: ULONG;
  231.   end;
  232.   {$EXTERNALSYM _BATTERY_WAIT_STATUS}
  233.   BATTERY_WAIT_STATUS = _BATTERY_WAIT_STATUS;
  234.   {$EXTERNALSYM BATTERY_WAIT_STATUS}
  235.   PBATTERY_WAIT_STATUS = ^BATTERY_WAIT_STATUS;
  236.   {$EXTERNALSYM PBATTERY_WAIT_STATUS}
  237.   TBatteryWaitStatus = BATTERY_WAIT_STATUS;
  238.   PBatteryWaitStatus = PBATTERY_WAIT_STATUS;
  239. //
  240. // Structure of output buffer from IOCTL_BATTERY_QUERY_STATUS
  241. //
  242.   _BATTERY_STATUS = record
  243.     PowerState: ULONG;
  244.     Capacity: ULONG;
  245.     Voltage: ULONG;
  246.     Rate: LONG;
  247.   end;
  248.   {$EXTERNALSYM _BATTERY_STATUS}
  249.   BATTERY_STATUS = _BATTERY_STATUS;
  250.   {$EXTERNALSYM BATTERY_STATUS}
  251.   PBATTERY_STATUS = ^BATTERY_STATUS;
  252.   {$EXTERNALSYM PBATTERY_STATUS}
  253.   TBatteryStatus = BATTERY_STATUS;
  254.   PBatteryStatus = PBATTERY_STATUS;
  255. //
  256. // BATTERY_STATUS.PowerState flags
  257. //
  258. const
  259.   BATTERY_POWER_ON_LINE = $00000001;
  260.   {$EXTERNALSYM BATTERY_POWER_ON_LINE}
  261.   BATTERY_DISCHARGING   = $00000002;
  262.   {$EXTERNALSYM BATTERY_DISCHARGING}
  263.   BATTERY_CHARGING      = $00000004;
  264.   {$EXTERNALSYM BATTERY_CHARGING}
  265.   BATTERY_CRITICAL      = $00000008;
  266.   {$EXTERNALSYM BATTERY_CRITICAL}
  267. //
  268. // BATTERY_STATUS Constant
  269. // BATTERY_UNKNOWN_CAPACITY defined above for IOCTL_BATTERY_QUERY_INFORMATION
  270. //
  271.   BATTERY_UNKNOWN_VOLTAGE = DWORD($FFFFFFFF);
  272.   {$EXTERNALSYM BATTERY_UNKNOWN_VOLTAGE}
  273.   BATTERY_UNKNOWN_RATE    = DWORD($80000000);
  274.   {$EXTERNALSYM BATTERY_UNKNOWN_RATE}
  275. // mvb remainder of header file is kernel mode only
  276. implementation
  277. end.