jwasensapi.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. {******************************************************************************}
  2. { }
  3. { System Event Notification Services 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: sensapi.h, released March 2003. The original Pascal }
  9. { code is: SensAPI.pas, released April 2003. 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 JwaSensAPI;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "SensAPI.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinNT, JwaWinType;
  51. const
  52. NETWORK_ALIVE_LAN = $00000001;
  53. {$EXTERNALSYM NETWORK_ALIVE_LAN}
  54. NETWORK_ALIVE_WAN = $00000002;
  55. {$EXTERNALSYM NETWORK_ALIVE_WAN}
  56. NETWORK_ALIVE_AOL = $00000004;
  57. {$EXTERNALSYM NETWORK_ALIVE_AOL}
  58. type
  59. tagQOCINFO = record
  60. dwSize: DWORD;
  61. dwFlags: DWORD;
  62. dwInSpeed: DWORD;
  63. dwOutSpeed: DWORD;
  64. end;
  65. {$EXTERNALSYM tagQOCINFO}
  66. QOCINFO = tagQOCINFO;
  67. {$EXTERNALSYM QOCINFO}
  68. LPQOCINFO = ^QOCINFO;
  69. {$EXTERNALSYM LPQOCINFO}
  70. TQocInfo = QOCINFO;
  71. PQocInfo = LPQOCINFO;
  72. function IsDestinationReachableA(lpszDestination: LPCSTR; lpQOCInfo: LPQOCINFO): BOOL; stdcall;
  73. {$EXTERNALSYM IsDestinationReachableA}
  74. function IsDestinationReachableW(lpszDestination: LPCWSTR; lpQOCInfo: LPQOCINFO): BOOL; stdcall;
  75. {$EXTERNALSYM IsDestinationReachableW}
  76. function IsDestinationReachable(lpszDestination: LPCTSTR; lpQOCInfo: LPQOCINFO): BOOL; stdcall;
  77. {$EXTERNALSYM IsDestinationReachable}
  78. function IsNetworkAlive(out lpdwFlags: DWORD): BOOL; stdcall;
  79. {$EXTERNALSYM IsNetworkAlive}
  80. implementation
  81. const
  82. sensapilib = 'sensapi.dll';
  83. {$IFDEF UNICODE}
  84. AWSuffix = 'W';
  85. {$ELSE}
  86. AWSuffix = 'A';
  87. {$ENDIF UNICODE}
  88. {$IFDEF DYNAMIC_LINK}
  89. var
  90. _IsDestinationReachableA: Pointer;
  91. function IsDestinationReachableA;
  92. begin
  93. GetProcedureAddress(_IsDestinationReachableA, sensapilib, 'IsDestinationReachableA');
  94. asm
  95. MOV ESP, EBP
  96. POP EBP
  97. JMP [_IsDestinationReachableA]
  98. end;
  99. end;
  100. var
  101. _IsDestinationReachableW: Pointer;
  102. function IsDestinationReachableW;
  103. begin
  104. GetProcedureAddress(_IsDestinationReachableW, sensapilib, 'IsDestinationReachableW');
  105. asm
  106. MOV ESP, EBP
  107. POP EBP
  108. JMP [_IsDestinationReachableW]
  109. end;
  110. end;
  111. var
  112. _IsDestinationReachable: Pointer;
  113. function IsDestinationReachable;
  114. begin
  115. GetProcedureAddress(_IsDestinationReachable, sensapilib, 'IsDestinationReachable' + AWSuffix);
  116. asm
  117. MOV ESP, EBP
  118. POP EBP
  119. JMP [_IsDestinationReachable]
  120. end;
  121. end;
  122. var
  123. _IsNetworkAlive: Pointer;
  124. function IsNetworkAlive;
  125. begin
  126. GetProcedureAddress(_IsNetworkAlive, sensapilib, 'IsNetworkAlive');
  127. asm
  128. MOV ESP, EBP
  129. POP EBP
  130. JMP [_IsNetworkAlive]
  131. end;
  132. end;
  133. {$ELSE}
  134. function IsDestinationReachableA; external sensapilib name 'IsDestinationReachableA';
  135. function IsDestinationReachableW; external sensapilib name 'IsDestinationReachableW';
  136. function IsDestinationReachable; external sensapilib name 'IsDestinationReachable' + AWSuffix;
  137. function IsNetworkAlive; external sensapilib name 'IsNetworkAlive';
  138. {$ENDIF DYNAMIC_LINK}
  139. end.