Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
8.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: RasApiDll.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Dynamicly link to RASAPI32.dll
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: fengsun Created 03/12/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef RASAPIALL_H
  15. #define RASAPIALL_H
  16. #include <ras.h>
  17. #include "DynamicLib.h"
  18. //
  19. // The statistics structure used with RasGetConnectionStatistics API
  20. //
  21. typedef struct _RAS_STATS
  22. {
  23. DWORD dwSize;
  24. DWORD dwBytesXmited;
  25. DWORD dwBytesRcved;
  26. DWORD dwFramesXmited;
  27. DWORD dwFramesRcved;
  28. DWORD dwCrcErr;
  29. DWORD dwTimeoutErr;
  30. DWORD dwAlignmentErr;
  31. DWORD dwHardwareOverrunErr;
  32. DWORD dwFramingErr;
  33. DWORD dwBufferOverrunErr;
  34. DWORD dwCompressionRatioIn;
  35. DWORD dwCompressionRatioOut;
  36. DWORD dwBps;
  37. DWORD dwConnectDuration;
  38. } RAS_STATS, *PRAS_STATS;
  39. //+---------------------------------------------------------------------------
  40. //
  41. // class : CRasApiDll
  42. //
  43. // Synopsis: A class to dynamic link to RASAPI32.DLL, derived from CDynamicLibrary
  44. // Calling any of the RAS function will load the DLL
  45. //
  46. // History: fengsun created 3/12/98
  47. //
  48. //----------------------------------------------------------------------------
  49. class CRasApiDll : public CDynamicLibrary
  50. {
  51. public:
  52. CRasApiDll();
  53. DWORD RasGetConnectStatus(HRASCONN hrasconn, LPRASCONNSTATUS lprasconnstatus);
  54. DWORD RasConnectionNotification(HRASCONN hrasconn,
  55. HANDLE hEvent,
  56. DWORD dwFlags);
  57. DWORD RasGetConnectionStatistics(HRASCONN hrasconn, PRAS_STATS pRasStats);
  58. BOOL Load();
  59. BOOL HasRasConnectionNotification() const;
  60. protected:
  61. typedef DWORD (WINAPI* RasGetConnectStatusFUNC)(HRASCONN, LPRASCONNSTATUS);
  62. typedef DWORD (WINAPI* RasConnectionNotificationFUNC)(HRASCONN hrasconn,
  63. HANDLE hEvent,
  64. DWORD dwFlags);
  65. typedef DWORD (WINAPI* RasGetConnectionStatisticsFUNC) (HRASCONN, PRAS_STATS);
  66. RasGetConnectStatusFUNC m_pfnRasGetConnectStatus;
  67. RasConnectionNotificationFUNC m_pfnRasConnectionNotification;
  68. RasGetConnectionStatisticsFUNC m_pfnRasGetConnectionStatistics;
  69. };
  70. //
  71. // Constructor
  72. //
  73. inline CRasApiDll::CRasApiDll() : CDynamicLibrary()
  74. {
  75. m_pfnRasGetConnectStatus = NULL;
  76. m_pfnRasConnectionNotification = NULL;
  77. }
  78. //+----------------------------------------------------------------------------
  79. //
  80. // Function: CRasApiDll::Load
  81. //
  82. // Synopsis: Load RASAPI32.dll
  83. //
  84. // Arguments: None
  85. //
  86. // Returns: BOOL - TRUE if load successfully
  87. //
  88. // History: fengsun Created Header 3/12/98
  89. //
  90. //+----------------------------------------------------------------------------
  91. inline
  92. BOOL CRasApiDll::Load()
  93. {
  94. if(IsLoaded())
  95. {
  96. return TRUE;
  97. }
  98. if (!CDynamicLibrary::Load(TEXT("RASAPI32.DLL")))
  99. {
  100. return FALSE;
  101. }
  102. LPSTR pszGetConnectStatusFuncName;
  103. LPSTR pszConnectionNotificationFuncName;
  104. LPSTR pszGetConnectionStatisticsFuncName;
  105. if (OS_NT)
  106. {
  107. pszGetConnectStatusFuncName = "RasGetConnectStatusW";
  108. pszConnectionNotificationFuncName = "RasConnectionNotificationW";
  109. }
  110. else
  111. {
  112. pszGetConnectStatusFuncName = "RasGetConnectStatusA";
  113. pszConnectionNotificationFuncName = "RasConnectionNotificationA";
  114. }
  115. m_pfnRasGetConnectStatus = (RasGetConnectStatusFUNC)CDynamicLibrary::GetProcAddress
  116. (pszGetConnectStatusFuncName);
  117. m_pfnRasConnectionNotification = (RasConnectionNotificationFUNC)CDynamicLibrary::GetProcAddress
  118. (pszConnectionNotificationFuncName);
  119. //
  120. // Only on NT5, we load the statistics retrieval API
  121. //
  122. if (OS_NT5)
  123. {
  124. pszGetConnectionStatisticsFuncName = "RasGetConnectionStatistics";
  125. m_pfnRasGetConnectionStatistics = (RasGetConnectionStatisticsFUNC)CDynamicLibrary::GetProcAddress
  126. (pszGetConnectionStatisticsFuncName);
  127. }
  128. MYDBGASSERT(m_pfnRasGetConnectStatus);
  129. return TRUE;
  130. }
  131. //+----------------------------------------------------------------------------
  132. //
  133. // Function: CRasApiDll::RasGetConnectionStatistics
  134. //
  135. // Synopsis: Call the ras function RasGetConnectionStatistics.
  136. // Load the Dll, if not loaded yet
  137. //
  138. // Arguments: HRASCONN hrasconn - Same as ::RasGetConnectStatus
  139. // RAS_STATS RasStats - The Ras statistics
  140. //
  141. // Returns: DWORD - Same as ::RasGetConnectStatus
  142. //
  143. // History: nickball 03/04/00 Created. Cloned from RasGetConnectStatus
  144. //
  145. //+----------------------------------------------------------------------------
  146. inline
  147. DWORD CRasApiDll::RasGetConnectionStatistics(HRASCONN hRasConn, PRAS_STATS pRasStats)
  148. {
  149. DWORD dwReturn = ERROR_INVALID_FUNCTION;
  150. MYDBGASSERT(hRasConn);
  151. MYDBGASSERT(pRasStats);
  152. MYVERIFY(Load());
  153. if (IsLoaded() && m_pfnRasGetConnectionStatistics)
  154. {
  155. return (m_pfnRasGetConnectionStatistics(hRasConn, pRasStats));
  156. }
  157. return ERROR_INVALID_FUNCTION;
  158. }
  159. //+----------------------------------------------------------------------------
  160. //
  161. // Function: CRasApiDll::RasGetConnectStatus
  162. //
  163. // Synopsis: Call the ras function RasGetConnectStatus.
  164. // Load the Dll, if not loaded yet
  165. //
  166. // Arguments: HRASCONN hrasconn - Same as ::RasGetConnectStatus
  167. // LPRASCONNSTATUSA lprasconnstatus - Same as ::RasGetConnectStatus
  168. //
  169. // Returns: DWORD - Same as ::RasGetConnectStatus
  170. //
  171. // History: fengsun Created Header 3/12/98
  172. //
  173. //+----------------------------------------------------------------------------
  174. inline
  175. DWORD CRasApiDll::RasGetConnectStatus(HRASCONN hrasconn, LPRASCONNSTATUS lprasconnstatus)
  176. {
  177. DWORD dwReturn = ERROR_INVALID_FUNCTION;
  178. MYDBGASSERT(hrasconn);
  179. MYDBGASSERT(lprasconnstatus);
  180. MYVERIFY(Load());
  181. if (IsLoaded() && m_pfnRasGetConnectStatus != NULL)
  182. {
  183. if (OS_NT)
  184. {
  185. dwReturn = m_pfnRasGetConnectStatus(hrasconn, lprasconnstatus);
  186. }
  187. else
  188. {
  189. RASCONNSTATUSA RasConnStatusA;
  190. ZeroMemory(&RasConnStatusA, sizeof(RASCONNSTATUSA));
  191. RasConnStatusA.dwSize = sizeof(RASCONNSTATUSA);
  192. //
  193. // We cast this here because we only have one function declaration. We should
  194. // probably have one for Unicode and one for ANSI but for now the cast works
  195. // fine.
  196. //
  197. dwReturn = m_pfnRasGetConnectStatus(hrasconn, (LPRASCONNSTATUS)&RasConnStatusA);
  198. if (ERROR_SUCCESS == dwReturn)
  199. {
  200. lprasconnstatus->rasconnstate = RasConnStatusA.rasconnstate;
  201. lprasconnstatus->dwError = RasConnStatusA.dwError;
  202. SzToWz(RasConnStatusA.szDeviceType, lprasconnstatus->szDeviceType, RAS_MaxDeviceType);
  203. SzToWz(RasConnStatusA.szDeviceName, lprasconnstatus->szDeviceName, RAS_MaxDeviceName);
  204. }
  205. }
  206. }
  207. return dwReturn;
  208. }
  209. //+----------------------------------------------------------------------------
  210. //
  211. // Function: CRasApiDll::RasConnectionNotification
  212. //
  213. // Synopsis: Call the ras function RasConnectionNotification.
  214. // Load the Dll, if not loaded yet
  215. //
  216. // Arguments: HRASCONN hrasconn - Same as ::RasConnectionNotification
  217. // HANDLE hEvent - Same as ::RasConnectionNotification
  218. // DWORD dwFlags - Same as ::RasConnectionNotification
  219. //
  220. // Returns: DWORD - Same as ::RasConnectionNotification
  221. //
  222. // History: fengsun Created Header 3/12/98
  223. //
  224. //+----------------------------------------------------------------------------
  225. inline
  226. DWORD CRasApiDll::RasConnectionNotification(HRASCONN hrasconn,
  227. HANDLE hEvent,
  228. DWORD dwFlags)
  229. {
  230. MYDBGASSERT(hrasconn);
  231. MYDBGASSERT(hEvent);
  232. MYDBGASSERT(dwFlags);
  233. MYVERIFY(Load());
  234. if(!IsLoaded() || m_pfnRasConnectionNotification == NULL)
  235. {
  236. return ERROR_INVALID_FUNCTION;
  237. }
  238. return m_pfnRasConnectionNotification(hrasconn, hEvent, dwFlags);
  239. }
  240. //+----------------------------------------------------------------------------
  241. //
  242. // Function: CRasApiDll::HasRasConnectionNotification
  243. //
  244. // Synopsis: Whether the dll has the function RasConnectionNotification()
  245. // which is not available for WIN9x w/ DUN1.0
  246. //
  247. // Arguments: None
  248. //
  249. // Returns: BOOL - TRUE if the function is avalaible
  250. //
  251. // History: fengsun Created Header 3/13/98
  252. //
  253. //+----------------------------------------------------------------------------
  254. inline
  255. BOOL CRasApiDll::HasRasConnectionNotification() const
  256. {
  257. MYDBGASSERT(m_hInst);
  258. return m_pfnRasConnectionNotification != NULL;
  259. }
  260. #endif