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.

313 lines
7.5 KiB

  1. /*-----------------------------------------------------------------------------
  2. enumodem.cpp
  3. Holds code that deals with the "Choose a modem" dialog needed when user has
  4. multiple modems installed
  5. Copyright (C) 1996-1998 Microsoft Corporation
  6. All rights reserved
  7. Authors:
  8. jmazner Jeremy Mazner
  9. History:
  10. 10/19/96 jmazner Created, cloned almost verbatim from
  11. INETCFG's rnacall.cpp and export.cpp
  12. 1-9-98 donaldm Adapted from ICWCONN1
  13. -----------------------------------------------------------------------------*/
  14. #include <windowsx.h>
  15. #include "obcomglb.h"
  16. #include "enumodem.h"
  17. #include "rnaapi.h"
  18. #include "util.h"
  19. // from psheet.cpp
  20. extern void ProcessDBCS(HWND hDlg, int ctlID);
  21. /*******************************************************************
  22. NAME: CEnumModem::CEnumModem
  23. SYNOPSIS: Constructor for class to enumerate modems
  24. NOTES: Useful to have a class rather than C functions for
  25. this, due to how the enumerators function
  26. ********************************************************************/
  27. CEnumModem::CEnumModem() :
  28. m_dwError(ERROR_SUCCESS), m_lpData(NULL),m_dwIndex(0)
  29. {
  30. DWORD cbSize = 0;
  31. m_lpData = NULL;
  32. }
  33. /*******************************************************************
  34. NAME: CEnumModem::ReInit
  35. SYNOPSIS: Re-enumerate the modems, freeing the old memory.
  36. ********************************************************************/
  37. DWORD CEnumModem::ReInit()
  38. {
  39. DWORD cbSize = 0;
  40. RNAAPI cRnaapi;
  41. // Clean up the old list
  42. if (m_lpData)
  43. {
  44. delete m_lpData;
  45. m_lpData = NULL;
  46. }
  47. m_dwNumEntries = 0;
  48. m_dwIndex = 0;
  49. // call RasEnumDevices with no buffer to find out required buffer size
  50. m_dwError = cRnaapi.RasEnumDevices(NULL, &cbSize, &m_dwNumEntries);
  51. // Special case check to work around RNA bug where ERROR_BUFFER_TOO_SMALL
  52. // is returned even if there are no devices.
  53. // If there are no devices, we are finished.
  54. if (0 == m_dwNumEntries)
  55. {
  56. m_dwError = ERROR_SUCCESS;
  57. return m_dwError;
  58. }
  59. // Since we were just checking how much mem we needed, we expect
  60. // a return value of ERROR_BUFFER_TOO_SMALL, or it may just return
  61. // ERROR_SUCCESS (ChrisK 7/9/96).
  62. if (ERROR_BUFFER_TOO_SMALL != m_dwError && ERROR_SUCCESS != m_dwError)
  63. {
  64. return m_dwError;
  65. }
  66. // Allocate the space for the data
  67. m_lpData = (LPRASDEVINFO) new BYTE[cbSize];
  68. if (NULL == m_lpData)
  69. {
  70. //TraceMsg(TF_GENERAL, L"ICWCONN1: CEnumModem: Failed to allocate device list buffer\n");
  71. m_dwError = ERROR_NOT_ENOUGH_MEMORY;
  72. return m_dwError;
  73. }
  74. m_lpData->dwSize = sizeof(RASDEVINFO);
  75. m_dwNumEntries = 0;
  76. // enumerate the modems into buffer
  77. m_dwError = cRnaapi.RasEnumDevices(m_lpData, &cbSize,
  78. &m_dwNumEntries);
  79. if (ERROR_SUCCESS != m_dwError)
  80. return m_dwError;
  81. //
  82. // ChrisK Olympus 4560 do not include VPN's in the list
  83. //
  84. DWORD dwTempNumEntries;
  85. DWORD idx;
  86. LPRASDEVINFO lpNextValidDevice;
  87. dwTempNumEntries = m_dwNumEntries;
  88. lpNextValidDevice = m_lpData;
  89. //
  90. // Walk through the list of devices and copy non-VPN device to the first
  91. // available element of the array.
  92. //
  93. for (idx = 0;idx < dwTempNumEntries; idx++)
  94. {
  95. TRACE2(L"Modem device %s %s",
  96. m_lpData[idx].szDeviceType, m_lpData[idx].szDeviceName);
  97. if ((0 == lstrcmpi(RASDT_Modem, m_lpData[idx].szDeviceType)) ||
  98. (0 == lstrcmpi(RASDT_Isdn, m_lpData[idx].szDeviceType)) ||
  99. (0 == lstrcmpi(RASDT_PPPoE, m_lpData[idx].szDeviceType)) ||
  100. (0 == lstrcmpi(RASDT_Atm, m_lpData[idx].szDeviceType)))
  101. {
  102. if (lpNextValidDevice != &m_lpData[idx])
  103. {
  104. MoveMemory(lpNextValidDevice , &m_lpData[idx],sizeof(RASDEVINFO));
  105. }
  106. lpNextValidDevice++;
  107. }
  108. else
  109. {
  110. m_dwNumEntries--;
  111. }
  112. }
  113. return m_dwError;
  114. }
  115. /*******************************************************************
  116. NAME: CEnumModem::~CEnumModem
  117. SYNOPSIS: Destructor for class
  118. ********************************************************************/
  119. CEnumModem::~CEnumModem()
  120. {
  121. if (m_lpData)
  122. {
  123. delete m_lpData;
  124. m_lpData = NULL;
  125. }
  126. }
  127. /*******************************************************************
  128. NAME: CEnumModem::Next
  129. SYNOPSIS: Enumerates next modem
  130. EXIT: Returns a pointer to device info structure. Returns
  131. NULL if no more modems or error occurred. Call GetError
  132. to determine if error occurred.
  133. ********************************************************************/
  134. WCHAR * CEnumModem::Next()
  135. {
  136. if (m_dwIndex < m_dwNumEntries)
  137. {
  138. return m_lpData[m_dwIndex++].szDeviceName;
  139. }
  140. return NULL;
  141. }
  142. /*******************************************************************
  143. NAME: CEnumModem::GetDeviceTypeFromName
  144. SYNOPSIS: Returns type string for specified device.
  145. EXIT: Returns a pointer to device type string for first
  146. device name that matches. Returns
  147. NULL if no device with specified name is found
  148. ********************************************************************/
  149. WCHAR * CEnumModem::GetDeviceTypeFromName(LPWSTR szDeviceName)
  150. {
  151. DWORD dwIndex = 0;
  152. while (dwIndex < m_dwNumEntries)
  153. {
  154. if (!lstrcmpi(m_lpData[dwIndex].szDeviceName, szDeviceName))
  155. {
  156. return m_lpData[dwIndex].szDeviceType;
  157. }
  158. dwIndex++;
  159. }
  160. return NULL;
  161. }
  162. /*******************************************************************
  163. NAME: CEnumModem::GetDeviceNameFromType
  164. SYNOPSIS: Returns type string for specified device.
  165. EXIT: Returns a pointer to device name string for first
  166. device type that matches. Returns
  167. NULL if no device with specified Type is found
  168. ********************************************************************/
  169. WCHAR * CEnumModem::GetDeviceNameFromType(LPWSTR szDeviceType)
  170. {
  171. DWORD dwIndex = 0;
  172. while (dwIndex < m_dwNumEntries)
  173. {
  174. if (!lstrcmpi(m_lpData[dwIndex].szDeviceType, szDeviceType))
  175. {
  176. return m_lpData[dwIndex].szDeviceName;
  177. }
  178. dwIndex++;
  179. }
  180. return NULL;
  181. }
  182. /*******************************************************************
  183. NAME: CEnumModem::GetDeviceName
  184. CEnumModem::GetDeviceType
  185. SYNOPSIS: Returns the device name or type for the selected device.
  186. REMARKS:
  187. ONLY call this function after calling ReInit to initialize
  188. the device list. The device index is relative to the
  189. current copy of the device list.
  190. EXIT: Returns a pointer to the device name or type.
  191. donsc - 3/11/98
  192. Added this function because we need to be able to select a device
  193. from the list.
  194. ********************************************************************/
  195. WCHAR * CEnumModem::GetDeviceName(DWORD dwIndex)
  196. {
  197. if(dwIndex>=m_dwNumEntries)
  198. return NULL;
  199. return m_lpData[dwIndex].szDeviceName;
  200. }
  201. WCHAR * CEnumModem::GetDeviceType(DWORD dwIndex)
  202. {
  203. if(dwIndex>=m_dwNumEntries)
  204. return NULL;
  205. return m_lpData[dwIndex].szDeviceType;
  206. }
  207. /*******************************************************************
  208. NAME: CEnumModem::VerifyDeviceNameAndType
  209. SYNOPSIS: Determines whether there is a device with the name
  210. and type given.
  211. EXIT: Returns TRUE if the specified device was found,
  212. FALSE otherwise.
  213. ********************************************************************/
  214. BOOL CEnumModem::VerifyDeviceNameAndType(LPWSTR szDeviceName, LPWSTR szDeviceType)
  215. {
  216. DWORD dwIndex = 0;
  217. while (dwIndex < m_dwNumEntries)
  218. {
  219. if (!lstrcmpi(m_lpData[dwIndex].szDeviceType, szDeviceType) &&
  220. !lstrcmpi(m_lpData[dwIndex].szDeviceName, szDeviceName))
  221. {
  222. return TRUE;
  223. }
  224. dwIndex++;
  225. }
  226. return FALSE;
  227. }