jwalmalert.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. {******************************************************************************}
  2. { }
  3. { Lan Manager Alterter 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: lmalert.h, released November 2001. The original Pascal }
  9. { code is: LmAlert.pas, released Februari 2002. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott 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 }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaLmAlert;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "lmalert.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaLmCons, JwaWinType;
  51. //
  52. // Function Prototypes
  53. //
  54. function NetAlertRaise(AlertEventName: LPCWSTR; Buffer: LPVOID; BufferSize: DWORD): NET_API_STATUS; stdcall;
  55. {$EXTERNALSYM NetAlertRaise}
  56. function NetAlertRaiseEx(AlertEventName: LPCWSTR; VariableInfo: LPVOID; VariableInfoSize: DWORD; ServiceName: LPCWSTR): NET_API_STATUS; stdcall;
  57. {$EXTERNALSYM NetAlertRaiseEx}
  58. //
  59. // Data Structures
  60. //
  61. type
  62. _STD_ALERT = record
  63. alrt_timestamp: DWORD;
  64. alrt_eventname: array [0..EVLEN] of WCHAR;
  65. alrt_servicename: array [0..SNLEN] of WCHAR;
  66. end;
  67. {$EXTERNALSYM _STD_ALERT}
  68. STD_ALERT = _STD_ALERT;
  69. {$EXTERNALSYM STD_ALERT}
  70. PSTD_ALERT = ^STD_ALERT;
  71. {$EXTERNALSYM PSTD_ALERT}
  72. LPSTD_ALERT = ^STD_ALERT;
  73. {$EXTERNALSYM LPSTD_ALERT}
  74. TStdAlert = STD_ALERT;
  75. PStdAlert = PSTD_ALERT;
  76. _ADMIN_OTHER_INFO = record
  77. alrtad_errcode: DWORD;
  78. alrtad_numstrings: DWORD;
  79. end;
  80. {$EXTERNALSYM _ADMIN_OTHER_INFO}
  81. ADMIN_OTHER_INFO = _ADMIN_OTHER_INFO;
  82. {$EXTERNALSYM ADMIN_OTHER_INFO}
  83. PADMIN_OTHER_INFO = ^ADMIN_OTHER_INFO;
  84. {$EXTERNALSYM PADMIN_OTHER_INFO}
  85. LPADMIN_OTHER_INFO = ^ADMIN_OTHER_INFO;
  86. {$EXTERNALSYM LPADMIN_OTHER_INFO}
  87. TAdminOtherInfo = ADMIN_OTHER_INFO;
  88. PAdminOtherInfo = PADMIN_OTHER_INFO;
  89. _ERRLOG_OTHER_INFO = record
  90. alrter_errcode: DWORD;
  91. alrter_offset: DWORD;
  92. end;
  93. {$EXTERNALSYM _ERRLOG_OTHER_INFO}
  94. ERRLOG_OTHER_INFO = _ERRLOG_OTHER_INFO;
  95. {$EXTERNALSYM ERRLOG_OTHER_INFO}
  96. PERRLOG_OTHER_INFO = ^ERRLOG_OTHER_INFO;
  97. {$EXTERNALSYM PERRLOG_OTHER_INFO}
  98. LPERRLOG_OTHER_INFO = ^ERRLOG_OTHER_INFO;
  99. {$EXTERNALSYM LPERRLOG_OTHER_INFO}
  100. TErrlogOtherInfo = ERRLOG_OTHER_INFO;
  101. PErrlogOtherInfo = PERRLOG_OTHER_INFO;
  102. _PRINT_OTHER_INFO = record
  103. alrtpr_jobid: DWORD;
  104. alrtpr_status: DWORD;
  105. alrtpr_submitted: DWORD;
  106. alrtpr_size: DWORD;
  107. end;
  108. {$EXTERNALSYM _PRINT_OTHER_INFO}
  109. PRINT_OTHER_INFO = _PRINT_OTHER_INFO;
  110. {$EXTERNALSYM PRINT_OTHER_INFO}
  111. PPRINT_OTHER_INFO = ^PRINT_OTHER_INFO;
  112. {$EXTERNALSYM PPRINT_OTHER_INFO}
  113. LPPRINT_OTHER_INFO = ^PRINT_OTHER_INFO;
  114. {$EXTERNALSYM LPPRINT_OTHER_INFO}
  115. TPrintOtherInfo = PRINT_OTHER_INFO;
  116. PPrintOtherInfo = PPRINT_OTHER_INFO;
  117. _USER_OTHER_INFO = record
  118. alrtus_errcode: DWORD;
  119. alrtus_numstrings: DWORD;
  120. end;
  121. {$EXTERNALSYM _USER_OTHER_INFO}
  122. USER_OTHER_INFO = _USER_OTHER_INFO;
  123. {$EXTERNALSYM USER_OTHER_INFO}
  124. PUSER_OTHER_INFO = ^USER_OTHER_INFO;
  125. {$EXTERNALSYM PUSER_OTHER_INFO}
  126. LPUSER_OTHER_INFO = ^USER_OTHER_INFO;
  127. {$EXTERNALSYM LPUSER_OTHER_INFO}
  128. TUserOtherInfo = USER_OTHER_INFO;
  129. PUserOtherInfo = PUSER_OTHER_INFO;
  130. //
  131. // Special Values and Constants
  132. //
  133. //
  134. // Name of mailslot to send alert notifications
  135. //
  136. const
  137. ALERTER_MAILSLOT = WideString('\\.\MAILSLOT\Alerter');
  138. {$EXTERNALSYM ALERTER_MAILSLOT}
  139. //
  140. // The following macro gives a pointer to the other_info data.
  141. // It takes an alert structure and returns a pointer to structure
  142. // beyond the standard portion.
  143. //
  144. function ALERT_OTHER_INFO(x: Pointer): Pointer;
  145. {$EXTERNALSYM ALERT_OTHER_INFO}
  146. //
  147. // The following macro gives a pointer to the variable-length data.
  148. // It takes a pointer to one of the other-info structs and returns a
  149. // pointer to the variable data portion.
  150. //
  151. // (rom) cannot be implemented in Delphi
  152. //function ALERT_VAR_DATA(const p): Pointer;
  153. //
  154. // Names of standard Microsoft-defined alert events.
  155. //
  156. const
  157. ALERT_PRINT_EVENT = WideString('PRINTING');
  158. {$EXTERNALSYM ALERT_PRINT_EVENT}
  159. ALERT_MESSAGE_EVENT = WideString('MESSAGE');
  160. {$EXTERNALSYM ALERT_MESSAGE_EVENT}
  161. ALERT_ERRORLOG_EVENT = WideString('ERRORLOG');
  162. {$EXTERNALSYM ALERT_ERRORLOG_EVENT}
  163. ALERT_ADMIN_EVENT = WideString('ADMIN');
  164. {$EXTERNALSYM ALERT_ADMIN_EVENT}
  165. ALERT_USER_EVENT = WideString('USER');
  166. {$EXTERNALSYM ALERT_USER_EVENT}
  167. //
  168. // Bitmap masks for prjob_status field of PRINTJOB.
  169. //
  170. // 2-7 bits also used in device status
  171. PRJOB_QSTATUS = $3; // Bits 0,1
  172. {$EXTERNALSYM PRJOB_QSTATUS}
  173. PRJOB_DEVSTATUS = $1fc; // 2-8 bits
  174. {$EXTERNALSYM PRJOB_DEVSTATUS}
  175. PRJOB_COMPLETE = $4; // Bit 2
  176. {$EXTERNALSYM PRJOB_COMPLETE}
  177. PRJOB_INTERV = $8; // Bit 3
  178. {$EXTERNALSYM PRJOB_INTERV}
  179. PRJOB_ERROR = $10; // Bit 4
  180. {$EXTERNALSYM PRJOB_ERROR}
  181. PRJOB_DESTOFFLINE = $20; // Bit 5
  182. {$EXTERNALSYM PRJOB_DESTOFFLINE}
  183. PRJOB_DESTPAUSED = $40; // Bit 6
  184. {$EXTERNALSYM PRJOB_DESTPAUSED}
  185. PRJOB_NOTIFY = $80; // BIT 7
  186. {$EXTERNALSYM PRJOB_NOTIFY}
  187. PRJOB_DESTNOPAPER = $100; // BIT 8
  188. {$EXTERNALSYM PRJOB_DESTNOPAPER}
  189. PRJOB_DELETED = $8000; // BIT 15
  190. {$EXTERNALSYM PRJOB_DELETED}
  191. //
  192. // Values of PRJOB_QSTATUS bits in prjob_status field of PRINTJOB.
  193. //
  194. PRJOB_QS_QUEUED = 0;
  195. {$EXTERNALSYM PRJOB_QS_QUEUED}
  196. PRJOB_QS_PAUSED = 1;
  197. {$EXTERNALSYM PRJOB_QS_PAUSED}
  198. PRJOB_QS_SPOOLING = 2;
  199. {$EXTERNALSYM PRJOB_QS_SPOOLING}
  200. PRJOB_QS_PRINTING = 3;
  201. {$EXTERNALSYM PRJOB_QS_PRINTING}
  202. implementation
  203. function ALERT_OTHER_INFO(x: Pointer): Pointer;
  204. begin
  205. Result := Pointer(PChar(x) + SizeOf(STD_ALERT));
  206. end;
  207. {$IFDEF DYNAMIC_LINK}
  208. var
  209. _NetAlertRaise: Pointer;
  210. function NetAlertRaise;
  211. begin
  212. GetProcedureAddress(_NetAlertRaise, netapi32, 'NetAlertRaise');
  213. asm
  214. MOV ESP, EBP
  215. POP EBP
  216. JMP [_NetAlertRaise]
  217. end;
  218. end;
  219. var
  220. _NetAlertRaiseEx: Pointer;
  221. function NetAlertRaiseEx;
  222. begin
  223. GetProcedureAddress(_NetAlertRaiseEx, netapi32, 'NetAlertRaiseEx');
  224. asm
  225. MOV ESP, EBP
  226. POP EBP
  227. JMP [_NetAlertRaiseEx]
  228. end;
  229. end;
  230. {$ELSE}
  231. function NetAlertRaise; external netapi32 name 'NetAlertRaise';
  232. function NetAlertRaiseEx; external netapi32 name 'NetAlertRaiseEx';
  233. {$ENDIF DYNAMIC_LINK}
  234. end.