Leaked source code of windows server 2003
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.

1203 lines
31 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ModemUI.cpp
  6. * Content: Modem service provider UI functions
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 03/24/99 jtk Created
  13. ***************************************************************************/
  14. #include "dnmdmi.h"
  15. //**********************************************************************
  16. // Constant definitions
  17. //**********************************************************************
  18. // default size of temp strings used to add stuff to dialog
  19. #define DEFAULT_DIALOG_STRING_SIZE 100
  20. #define DEFAULT_DEVICE_SELECTION_INDEX 0
  21. #define MAX_MODEM_NAME_LENGTH 255
  22. //**********************************************************************
  23. // Macro definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Structure definitions
  27. //**********************************************************************
  28. //**********************************************************************
  29. // Variable definitions
  30. //**********************************************************************
  31. static const INT_PTR g_iExpectedIncomingModemSettingsReturn = 0x23456789;
  32. static const INT_PTR g_iExpectedOutgoingModemSettingsReturn = 0x3456789A;
  33. //**********************************************************************
  34. // Function prototypes
  35. //**********************************************************************
  36. static INT_PTR CALLBACK IncomingSettingsDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam );
  37. static HRESULT SetAddressParametersFromIncomingDialogData( const HWND hDialog, CModemEndpoint *const pModemEndpoint );
  38. static INT_PTR CALLBACK OutgoingSettingsDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam );
  39. static HRESULT SetOutgoingPhoneNumber( const HWND hDialog, const CModemEndpoint *const pModemEndpoint );
  40. static HRESULT SetAddressParametersFromOutgoingDialogData( const HWND hDialog, CModemEndpoint *const pModemEndpoint );
  41. static HRESULT DisplayModemConfigDialog( const HWND hDialog, const HWND hDeviceComboBox, const CModemEndpoint *const pModemEndpoint );
  42. static HRESULT SetModemDataInDialog( const HWND hComboBox, const CModemEndpoint *const pModemEndpoint );
  43. static HRESULT GetModemSelectionFromDialog( const HWND hComboBox, CModemEndpoint *const pModemEndpoint );
  44. static INT_PTR CALLBACK ModemStatusDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam );
  45. //**********************************************************************
  46. // Function definitions
  47. //**********************************************************************
  48. //**********************************************************************
  49. // ------------------------------
  50. // DisplayIncomingModemSettingsDialog - dialog for incoming modem connection
  51. //
  52. // Entry: Pointer to startup param
  53. //
  54. // Exit: Error code
  55. // ------------------------------
  56. #undef DPF_MODNAME
  57. #define DPF_MODNAME "DisplayIncomingModemSettingsDialog"
  58. void DisplayIncomingModemSettingsDialog( void *const pContext )
  59. {
  60. INT_PTR iDlgReturn;
  61. CModemEndpoint *pModemEndpoint;
  62. DNASSERT( pContext != NULL );
  63. //
  64. // intialize
  65. //
  66. pModemEndpoint = static_cast<CModemEndpoint*>( pContext );
  67. DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( LPARAM ) );
  68. SetLastError( ERROR_SUCCESS );
  69. iDlgReturn = DialogBoxParam( g_hModemDLLInstance, // handle of module for resources
  70. MAKEINTRESOURCE( IDD_INCOMING_MODEM_SETTINGS ), // resource for dialog
  71. NULL, // no parent
  72. IncomingSettingsDialogProc, // dialog message proc
  73. reinterpret_cast<LPARAM>( pModemEndpoint ) // startup parameter
  74. );
  75. if ( iDlgReturn != g_iExpectedIncomingModemSettingsReturn )
  76. {
  77. DWORD dwError;
  78. dwError = GetLastError();
  79. DPFX(DPFPREP, 0, "Failed to start incoming modem settings dialog!" );
  80. DisplayErrorCode( 0, dwError );
  81. pModemEndpoint->SettingsDialogComplete( DPNERR_OUTOFMEMORY );
  82. }
  83. return;
  84. }
  85. //**********************************************************************
  86. //**********************************************************************
  87. // ------------------------------
  88. // DisplayOutgoingModemSettingsDialog - dialog for Outgoing modem connection
  89. //
  90. // Entry: Pointer to startup param
  91. //
  92. // Exit: Error code
  93. // ------------------------------
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "DisplayOutgoingModemSettingsDialog"
  96. void DisplayOutgoingModemSettingsDialog( void *const pContext )
  97. {
  98. INT_PTR iDlgReturn;
  99. CModemEndpoint *pModemEndpoint;
  100. DNASSERT( pContext != NULL );
  101. //
  102. // intialize
  103. //
  104. pModemEndpoint = static_cast<CModemEndpoint*>( pContext );
  105. DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( LPARAM ) );
  106. SetLastError( ERROR_SUCCESS );
  107. iDlgReturn = DialogBoxParam( g_hModemDLLInstance, // handle of module for resources
  108. MAKEINTRESOURCE( IDD_OUTGOING_MODEM_SETTINGS ), // resource for dialog
  109. NULL, //
  110. OutgoingSettingsDialogProc, // dialog message proc
  111. reinterpret_cast<LPARAM>( pModemEndpoint ) // startup parameter
  112. );
  113. if ( iDlgReturn != g_iExpectedOutgoingModemSettingsReturn )
  114. {
  115. DWORD dwError;
  116. dwError = GetLastError();
  117. DPFX(DPFPREP, 0, "Failed to start outgoing modem settings dialog!" );
  118. DisplayErrorCode( 0, dwError );
  119. pModemEndpoint->SettingsDialogComplete( DPNERR_OUTOFMEMORY );
  120. }
  121. return;
  122. }
  123. //**********************************************************************
  124. //**********************************************************************
  125. // ------------------------------
  126. // StopModemSettingsDialog - stop dialog dialog for modem settings
  127. //
  128. // Entry: Handle of dialog
  129. //
  130. // Exit: Nothing
  131. // ------------------------------
  132. #undef DPF_MODNAME
  133. #define DPF_MODNAME "StopModemSettingsDialog"
  134. void StopModemSettingsDialog( const HWND hDlg )
  135. {
  136. DNASSERT( hDlg != NULL );
  137. if ( PostMessage( hDlg, WM_COMMAND, MAKEWPARAM( IDCANCEL, NULL ), NULL ) == 0 )
  138. {
  139. DWORD dwError;
  140. dwError = GetLastError();
  141. DPFX(DPFPREP, 0, "Failed to stop dialog!" );
  142. DisplayErrorCode( 0, dwError );
  143. DNASSERT( FALSE );
  144. }
  145. }
  146. //**********************************************************************
  147. ////**********************************************************************
  148. //// ------------------------------
  149. //// DisplayModemStatusDialog - dialog for modem status
  150. ////
  151. //// Entry: Pointer to destination for dialog handle
  152. //// Pointer to startup param
  153. ////
  154. //// Exit: Error code
  155. //// ------------------------------
  156. //HRESULT DisplayModemStatusDialog( HWND *const phDialog, CModemEndpoint *const pEndpoint )
  157. //{
  158. // HRESULT hr;
  159. // HWND hDialog;
  160. //
  161. //
  162. // // intialize
  163. // hr = DPN_OK;
  164. //
  165. // DBG_CASSERT( sizeof( pEndpoint ) == sizeof( LPARAM ) );
  166. // hDialog = CreateDialogParam( g_hModemDLLInstance, // handle of module for resources
  167. // MAKEINTRESOURCE( IDD_MODEM_STATUS ), // resource for dialog
  168. // GetForegroundWindow(), // parent window (whatever is on top)
  169. // ModemStatusDialogProc, // dialog message proc
  170. // reinterpret_cast<LPARAM>( pEndpoint ) // startup parameter
  171. // );
  172. // if ( hDialog == NULL )
  173. // {
  174. // DPFX(DPFPREP, 0, "Could not create modem status dialog!" );
  175. // DisplayErrorCode( 0, GetLastError() );
  176. // goto Failure;
  177. // }
  178. //
  179. // *phDialog = hDialog;
  180. // ShowWindow( hDialog, SW_SHOW );
  181. // UpdateWindow( hDialog );
  182. //
  183. //Exit:
  184. // return hr;
  185. //
  186. //Failure:
  187. // goto Exit;
  188. //}
  189. ////**********************************************************************
  190. //
  191. //
  192. ////**********************************************************************
  193. //// ------------------------------
  194. //// StopModemStatusDialog - stop dialog for modem connection status
  195. ////
  196. //// Entry: Handle of dialog
  197. ////
  198. //// Exit: Nothing
  199. //// ------------------------------
  200. //void StopModemStatusDialog( const HWND hDialog )
  201. //{
  202. // DNASSERT( hDialog != NULL );
  203. //
  204. // if ( SendMessage( hDialog, WM_COMMAND, MAKEWPARAM( IDCANCEL, NULL ), NULL ) != 0 )
  205. // {
  206. // // we didn't handle the message
  207. // DNASSERT( FALSE );
  208. // }
  209. //}
  210. ////**********************************************************************
  211. //**********************************************************************
  212. // ------------------------------
  213. // OutgoingSettingsDialogProc - dialog proc for outgoing modem connection
  214. //
  215. // Entry: Window handle
  216. // Message LPARAM
  217. // Message WPARAM
  218. //
  219. // Exit: Error code
  220. // ------------------------------
  221. #undef DPF_MODNAME
  222. #define DPF_MODNAME "OutgoingSettingsDialogProc"
  223. static INT_PTR CALLBACK OutgoingSettingsDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam )
  224. {
  225. CModemEndpoint *pModemEndpoint;
  226. HRESULT hr;
  227. //
  228. // initialize
  229. //
  230. hr = DPN_OK;
  231. // note the active endpoint pointer
  232. DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( LONG_PTR ) );
  233. pModemEndpoint = reinterpret_cast<CModemEndpoint*>( GetWindowLongPtr( hDialog, GWLP_USERDATA ) );
  234. switch ( uMsg )
  235. {
  236. // initialize dialog
  237. case WM_INITDIALOG:
  238. {
  239. // since this is the first dialog message, the default code to set
  240. // pModemEndpoint isn't getting valid data
  241. DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( lParam ) );
  242. pModemEndpoint = reinterpret_cast<CModemEndpoint*>( lParam );
  243. pModemEndpoint->SetActiveDialogHandle( hDialog );
  244. //
  245. // SetWindowLongPtr() returns NULL in case of error. It's possible
  246. // that the old value from SetWindowLongPtr() was really NULL in
  247. // which case it's not an error. To be safe, clear any residual
  248. // error code before calling SetWindowLongPtr().
  249. //
  250. SetLastError( 0 );
  251. if ( SetWindowLongPtr( hDialog, GWLP_USERDATA, lParam ) == NULL )
  252. {
  253. DWORD dwError;
  254. dwError = GetLastError();
  255. if ( dwError != ERROR_SUCCESS )
  256. {
  257. DPFX(DPFPREP, 0, "Problem setting user data for window!" );
  258. DisplayErrorCode( 0, dwError );
  259. goto Failure;
  260. }
  261. }
  262. //
  263. // set dialog information
  264. //
  265. hr = SetModemDataInDialog( GetDlgItem( hDialog, IDC_COMBO_OUTGOING_MODEM_DEVICE ), pModemEndpoint );
  266. if ( hr != DPN_OK )
  267. {
  268. DPFX(DPFPREP, 0, "Problem setting modem device!" );
  269. DisplayDNError( 0, hr );
  270. goto Failure;
  271. }
  272. hr = SetOutgoingPhoneNumber( hDialog, pModemEndpoint );
  273. if ( hr != DPN_OK )
  274. {
  275. DPFX(DPFPREP, 0, "Problem setting phone number!" );
  276. DisplayDNError( 0, hr );
  277. goto Failure;
  278. }
  279. return TRUE;
  280. break;
  281. }
  282. // a control did something
  283. case WM_COMMAND:
  284. {
  285. // what was the control?
  286. switch ( LOWORD( wParam ) )
  287. {
  288. case IDOK:
  289. {
  290. hr = SetAddressParametersFromOutgoingDialogData( hDialog, pModemEndpoint );
  291. if ( hr != DPN_OK )
  292. {
  293. DPFX(DPFPREP, 0, "Problem getting dialog data!" );
  294. DisplayDNError( 0, hr );
  295. goto Failure;
  296. }
  297. // pass any error code on to 'DialogComplete'
  298. pModemEndpoint->SettingsDialogComplete( hr );
  299. EndDialog( hDialog, g_iExpectedOutgoingModemSettingsReturn );
  300. break;
  301. }
  302. case IDCANCEL:
  303. {
  304. pModemEndpoint->SettingsDialogComplete( DPNERR_USERCANCEL );
  305. EndDialog( hDialog, g_iExpectedOutgoingModemSettingsReturn );
  306. break;
  307. }
  308. case IDC_BUTTON_MODEM_CONFIGURE:
  309. {
  310. hr = DisplayModemConfigDialog( hDialog, GetDlgItem( hDialog, IDC_COMBO_OUTGOING_MODEM_DEVICE ), pModemEndpoint );
  311. if ( hr != DPN_OK )
  312. {
  313. DPFX(DPFPREP, 0, "Problem with DisplayModemConfigDialog in outgoing dialog!" );
  314. DisplayDNError( 0, hr );
  315. }
  316. break;
  317. }
  318. }
  319. break;
  320. }
  321. // window is closing
  322. case WM_CLOSE:
  323. {
  324. break;
  325. }
  326. }
  327. Exit:
  328. return FALSE;
  329. Failure:
  330. DNASSERT( pModemEndpoint != NULL );
  331. DNASSERT( hr != DPN_OK );
  332. pModemEndpoint->SettingsDialogComplete( hr );
  333. EndDialog( hDialog, g_iExpectedOutgoingModemSettingsReturn );
  334. goto Exit;
  335. }
  336. //**********************************************************************
  337. //**********************************************************************
  338. // ------------------------------
  339. // IncomingSettingsDialogProc - dialog proc for incoming modem connection
  340. //
  341. // Entry: Window handle
  342. // Message LPARAM
  343. // Message WPARAM
  344. //
  345. // Exit: Error code
  346. // ------------------------------
  347. #undef DPF_MODNAME
  348. #define DPF_MODNAME "IncomingSettingsDialogProc"
  349. static INT_PTR CALLBACK IncomingSettingsDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam )
  350. {
  351. CModemEndpoint *pModemEndpoint;
  352. HRESULT hr;
  353. //
  354. // initialize
  355. //
  356. hr = DPN_OK;
  357. //
  358. // note the modem port pointer
  359. //
  360. DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( LONG_PTR ) );
  361. pModemEndpoint = reinterpret_cast<CModemEndpoint*>( GetWindowLongPtr( hDialog, GWLP_USERDATA ) );
  362. switch ( uMsg )
  363. {
  364. //
  365. // initialize dialog
  366. //
  367. case WM_INITDIALOG:
  368. {
  369. //
  370. // since this is the first dialog message, the default code to set
  371. // pModemEndpoint isn't getting valid data
  372. //
  373. DBG_CASSERT( sizeof( pModemEndpoint) == sizeof( lParam ) );
  374. pModemEndpoint = reinterpret_cast<CModemEndpoint*>( lParam );
  375. pModemEndpoint->SetActiveDialogHandle( hDialog );
  376. //
  377. // SetWindowLongPtr() returns NULL in case of error. It's possible
  378. // that the old value from SetWindowLongPtr() was really NULL in
  379. // which case it's not an error. To be safe, clear any residual
  380. // error code before calling SetWindowLongPtr().
  381. //
  382. SetLastError( 0 );
  383. if ( SetWindowLongPtr( hDialog, GWLP_USERDATA, lParam ) == NULL )
  384. {
  385. DWORD dwError;
  386. dwError = GetLastError();
  387. if ( dwError != ERROR_SUCCESS )
  388. {
  389. DPFX(DPFPREP, 0, "Problem setting user data for window!" );
  390. DisplayErrorCode( 0, dwError );
  391. goto Failure;
  392. }
  393. }
  394. //
  395. // set dialog information
  396. //
  397. hr = SetModemDataInDialog( GetDlgItem( hDialog, IDC_COMBO_INCOMING_MODEM_DEVICE ), pModemEndpoint );
  398. if ( hr != DPN_OK )
  399. {
  400. DPFX(DPFPREP, 0, "Problem setting modem device!" );
  401. DisplayDNError( 0, hr );
  402. goto Failure;
  403. }
  404. return TRUE;
  405. break;
  406. }
  407. //
  408. // a control did something
  409. //
  410. case WM_COMMAND:
  411. {
  412. // what was the control?
  413. switch ( LOWORD( wParam ) )
  414. {
  415. case IDOK:
  416. {
  417. hr = SetAddressParametersFromIncomingDialogData( hDialog, pModemEndpoint );
  418. if ( hr != DPN_OK )
  419. {
  420. DPFX(DPFPREP, 0, "Problem getting dialog data!" );
  421. DisplayDNError( 0, hr );
  422. goto Failure;
  423. }
  424. //
  425. // pass any error code on to 'DialogComplete'
  426. //
  427. pModemEndpoint->SettingsDialogComplete( hr );
  428. EndDialog( hDialog, g_iExpectedIncomingModemSettingsReturn );
  429. break;
  430. }
  431. case IDCANCEL:
  432. {
  433. pModemEndpoint->SettingsDialogComplete( DPNERR_USERCANCEL );
  434. EndDialog( hDialog, g_iExpectedIncomingModemSettingsReturn );
  435. break;
  436. }
  437. case IDC_BUTTON_MODEM_CONFIGURE:
  438. {
  439. hr = DisplayModemConfigDialog( hDialog,
  440. GetDlgItem( hDialog, IDC_COMBO_INCOMING_MODEM_DEVICE ),
  441. pModemEndpoint );
  442. if ( hr != DPN_OK )
  443. {
  444. DPFX(DPFPREP, 0, "Problem with DisplayModemConfigDialog in incoming dialog!" );
  445. DisplayDNError( 0, hr );
  446. }
  447. break;
  448. }
  449. }
  450. break;
  451. }
  452. //
  453. // window is closing
  454. //
  455. case WM_CLOSE:
  456. {
  457. DNASSERT( FALSE );
  458. break;
  459. }
  460. }
  461. Exit:
  462. return FALSE;
  463. Failure:
  464. DNASSERT( pModemEndpoint != NULL );
  465. DNASSERT( hr != DPN_OK );
  466. pModemEndpoint->SettingsDialogComplete( hr );
  467. EndDialog( hDialog, g_iExpectedIncomingModemSettingsReturn );
  468. goto Exit;
  469. }
  470. //**********************************************************************
  471. ////**********************************************************************
  472. //// ------------------------------
  473. //// ModemStatusDialogProc - dialog proc for modem status
  474. ////
  475. //// Entry: Window handle
  476. //// Message LPARAM
  477. //// Message WPARAM
  478. ////
  479. //// Exit: Error code
  480. //// ------------------------------
  481. //static INT_PTR CALLBACK ModemStatusDialogProc( HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam )
  482. //{
  483. // CModemEndpoint *pModemEndpoint;
  484. // HRESULT hr;
  485. //
  486. // // initialize
  487. // hr = DPN_OK;
  488. //
  489. // // note the active endpoint pointer
  490. // DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( LONG_PTR ) );
  491. // pModemEndpoint = reinterpret_cast<CModemEndpoint*>( GetWindowLongPtr( hDialog, GWLP_USERDATA ) );
  492. //
  493. // switch ( uMsg )
  494. // {
  495. // // initialize dialog
  496. // case WM_INITDIALOG:
  497. // {
  498. // // since this is the first dialog message, the default code to set
  499. // // pModemEndpoint isn't getting valid data
  500. // DBG_CASSERT( sizeof( pModemEndpoint ) == sizeof( lParam ) );
  501. // pModemEndpoint = reinterpret_cast<CModemEndpoint*>( lParam );
  502. //
  503. // //
  504. // // SetWindowLongPtr() returns NULL in case of error. It's possible
  505. // // that the old value from SetWindowLongPtr() was really NULL in
  506. // // which case it's not an error. To be safe, clear any residual
  507. // // error code before calling SetWindowLongPtr().
  508. // //
  509. // SetLastError( 0 );
  510. // if ( SetWindowLongPtr( hDialog, GWLP_USERDATA, lParam ) == NULL )
  511. // {
  512. // DWORD dwError;
  513. //
  514. // dwError = GetLastError();
  515. // if ( dwError != ERROR_SUCCESS )
  516. // {
  517. // DPFX(DPFPREP, 0, "Problem setting user data for window!" );
  518. // DisplayErrorCode( 0, dwError );
  519. // goto Failure;
  520. // }
  521. // }
  522. //
  523. // // set dialog information
  524. //
  525. // return TRUE;
  526. //
  527. // break;
  528. // }
  529. //
  530. // // a control did something
  531. // case WM_COMMAND:
  532. // {
  533. // // what was the control?
  534. // switch ( LOWORD( wParam ) )
  535. // {
  536. // case IDOK:
  537. // {
  538. //// HRESULT hr;
  539. //
  540. //
  541. //// if ( ( hr = GetDialogData( hDialog, pModemEndpoint ) ) != DPN_OK )
  542. //// {
  543. //// DPFX(DPFPREP, 0, "Problem getting dialog data!" );
  544. //// DisplayDNError( 0, hr );
  545. //// goto Failure;
  546. //// }
  547. //
  548. //// // pass any error code on to 'DialogComplete'
  549. //// pModemEndpoint->DialogComplete( hr );
  550. // DestroyWindow( hDialog );
  551. //
  552. // break;
  553. // }
  554. //
  555. //// case IDCANCEL:
  556. //// {
  557. //// pModemEndpoint->DialogComplete( DPNERR_USERCANCEL );
  558. //// DestroyWindow( hDialog );
  559. ////
  560. //// break;
  561. //// }
  562. // }
  563. //
  564. // break;
  565. // }
  566. //
  567. // // window is closing
  568. // case WM_CLOSE:
  569. // {
  570. // break;
  571. // }
  572. // }
  573. //
  574. //Exit:
  575. // return FALSE;
  576. //
  577. //Failure:
  578. // DNASSERT( pModemEndpoint != NULL );
  579. // DNASSERT( hr != DPN_OK );
  580. //// pModemEndpoint->StatusDialogComplete( hr );
  581. // DestroyWindow( hDialog );
  582. //
  583. // goto Exit;
  584. //}
  585. ////**********************************************************************
  586. //**********************************************************************
  587. // ------------------------------
  588. // SetModemDataInDialog - set device for modem dialog
  589. //
  590. // Entry: Window handle of modem combo box
  591. // Pointer to modem port
  592. //
  593. // Exit: Error code
  594. // ------------------------------
  595. #undef DPF_MODNAME
  596. #define DPF_MODNAME "SetModemDataInDialog"
  597. HRESULT SetModemDataInDialog( const HWND hComboBox, const CModemEndpoint *const pModemEndpoint )
  598. {
  599. HRESULT hr;
  600. LRESULT lResult;
  601. DWORD dwModemCount;
  602. MODEM_NAME_DATA *pModemNameData;
  603. DWORD dwModemNameDataSize;
  604. BOOL fSelectionSet;
  605. UINT_PTR uIndex;
  606. DNASSERT( hComboBox != NULL );
  607. DNASSERT( pModemEndpoint != NULL );
  608. //
  609. // initialize
  610. //
  611. hr = DPN_OK;
  612. pModemNameData = NULL;
  613. dwModemNameDataSize = 0;
  614. fSelectionSet = FALSE;
  615. lResult = SendMessage( hComboBox, CB_RESETCONTENT, 0, 0 );
  616. // DNASSERT( lResult == CB_OKAY ); // <-- Win2K is busted!!!!
  617. hr = GenerateAvailableModemList( pModemEndpoint->GetSPData()->GetThreadPool()->GetTAPIInfo(),
  618. &dwModemCount,
  619. pModemNameData,
  620. &dwModemNameDataSize );
  621. switch ( hr )
  622. {
  623. //
  624. // no modems to list, no more processing to be done
  625. //
  626. case DPN_OK:
  627. {
  628. goto Exit;
  629. }
  630. //
  631. // expected return
  632. //
  633. case DPNERR_BUFFERTOOSMALL:
  634. {
  635. break;
  636. }
  637. //
  638. // error
  639. //
  640. default:
  641. {
  642. DPFX(DPFPREP, 0, "SetModemDataInDialog: Failed to get size of modem list!" );
  643. DisplayDNError( 0, hr );
  644. goto Failure;
  645. break;
  646. }
  647. }
  648. pModemNameData = static_cast<MODEM_NAME_DATA*>( DNMalloc( dwModemNameDataSize ) );
  649. if ( pModemNameData == NULL )
  650. {
  651. hr = DPNERR_OUTOFMEMORY;
  652. DPFX(DPFPREP, 0, "SetModemDataInDialog: Failed to allocate memory to fill modem dialog list!" );
  653. goto Failure;
  654. }
  655. hr = GenerateAvailableModemList( pModemEndpoint->GetSPData()->GetThreadPool()->GetTAPIInfo(),
  656. &dwModemCount,
  657. pModemNameData,
  658. &dwModemNameDataSize );
  659. if ( hr != DPN_OK )
  660. {
  661. DPFX(DPFPREP, 0, "SetModemDataInDialog: Failed to get size of modem list!" );
  662. DisplayDNError( 0, hr );
  663. goto Failure;
  664. }
  665. for ( uIndex = 0; uIndex < dwModemCount; uIndex++ )
  666. {
  667. LRESULT AddResult;
  668. DBG_CASSERT( sizeof( pModemNameData[ uIndex ].pModemName ) == sizeof( LPARAM ) );
  669. AddResult = SendMessage( hComboBox, CB_INSERTSTRING, 0, reinterpret_cast<const LPARAM>( pModemNameData[ uIndex ].pModemName ) );
  670. switch ( AddResult )
  671. {
  672. case CB_ERR:
  673. {
  674. hr = DPNERR_GENERIC;
  675. DPFX(DPFPREP, 0, "Problem adding serial device to combo box!" );
  676. goto Failure;
  677. break;
  678. }
  679. case CB_ERRSPACE:
  680. {
  681. hr = DPNERR_OUTOFMEMORY;
  682. DPFX(DPFPREP, 0, "Out of memory when ading serial device to combo box!" );
  683. goto Failure;
  684. break;
  685. }
  686. //
  687. // we added the string OK, set the associated device id and check
  688. // to see if this is the current value to set selection
  689. //
  690. default:
  691. {
  692. LRESULT SetResult;
  693. SetResult = SendMessage ( hComboBox, CB_SETITEMDATA, AddResult, pModemNameData[ uIndex ].dwModemID );
  694. if ( SetResult == CB_ERR )
  695. {
  696. DWORD dwError;
  697. hr = DPNERR_OUTOFMEMORY;
  698. dwError = GetLastError();
  699. DPFX(DPFPREP, 0, "Problem setting modem device info!" );
  700. DisplayErrorCode( 0, dwError );
  701. goto Failure;
  702. }
  703. if ( pModemEndpoint->GetDeviceID() == uIndex )
  704. {
  705. LRESULT SetSelectionResult;
  706. SetSelectionResult = SendMessage( hComboBox, CB_SETCURSEL, AddResult, 0 );
  707. if ( SetSelectionResult == CB_ERR )
  708. {
  709. DWORD dwError;
  710. hr = DPNERR_GENERIC;
  711. dwError = GetLastError();
  712. DPFX(DPFPREP, 0, "Problem setting default modem device selection!" );
  713. DisplayErrorCode( 0, dwError );
  714. DNASSERT( FALSE );
  715. goto Failure;
  716. }
  717. fSelectionSet = TRUE;
  718. }
  719. break;
  720. }
  721. }
  722. }
  723. if ( fSelectionSet == FALSE )
  724. {
  725. LRESULT SetSelectionResult;
  726. SetSelectionResult = SendMessage( hComboBox, CB_SETCURSEL, 0, 0 );
  727. if ( SetSelectionResult == CB_ERR )
  728. {
  729. DWORD dwError;
  730. dwError = GetLastError();
  731. DPFX(DPFPREP, 0, "Problem setting default modem selection!" );
  732. DisplayErrorCode( 0, dwError );
  733. }
  734. }
  735. Exit:
  736. if ( pModemNameData != NULL )
  737. {
  738. DNFree( pModemNameData );
  739. pModemNameData = NULL;
  740. }
  741. return hr;
  742. Failure:
  743. goto Exit;
  744. }
  745. //**********************************************************************
  746. //**********************************************************************
  747. // ------------------------------
  748. // GetModemSelectionFromDialog - get modem selection from dialog
  749. //
  750. // Entry: Window handle of modem combo box
  751. // Pointer to modem port
  752. //
  753. // Exit: Error code
  754. // ------------------------------
  755. #undef DPF_MODNAME
  756. #define DPF_MODNAME "GetModemSelectionFromDialog"
  757. static HRESULT GetModemSelectionFromDialog( const HWND hComboBox, CModemEndpoint *const pModemEndpoint )
  758. {
  759. HRESULT hr;
  760. LRESULT Selection;
  761. LRESULT DeviceID;
  762. //
  763. // initialize
  764. //
  765. hr = DPN_OK;
  766. if ( hComboBox == NULL )
  767. {
  768. hr = DPNERR_GENERIC;
  769. DPFX(DPFPREP, 0, "Invalid control handle passed to GetModemSelectionFromDialog!" );
  770. goto Failure;
  771. }
  772. //
  773. // get modem selection
  774. //
  775. Selection = SendMessage( hComboBox, CB_GETCURSEL, 0, 0 );
  776. if ( Selection == CB_ERR )
  777. {
  778. hr = DPNERR_GENERIC;
  779. DPFX(DPFPREP, 0, "Could not get current modem selection!" );
  780. DNASSERT( FALSE );
  781. goto Failure;
  782. }
  783. //
  784. // get device ID
  785. //
  786. DeviceID = SendMessage( hComboBox, CB_GETITEMDATA, Selection, 0 );
  787. if ( DeviceID == CB_ERR )
  788. {
  789. hr = DPNERR_GENERIC;
  790. DPFX(DPFPREP, 0, "Could not get selection item data!" );
  791. DNASSERT( FALSE );
  792. goto Failure;
  793. }
  794. //
  795. // Now that we finally have the device ID, set it. Make sure
  796. // we clear any existing ID first, or the ID setting code will
  797. // complain. I like paranoid code, so work around the ASSERT.
  798. //
  799. DNASSERT( DeviceID <= UINT32_MAX );
  800. hr = pModemEndpoint->SetDeviceID( INVALID_DEVICE_ID );
  801. DNASSERT( hr == DPN_OK );
  802. hr = pModemEndpoint->SetDeviceID( static_cast<DWORD>( DeviceID ) );
  803. if ( hr != DPN_OK )
  804. {
  805. DPFX(DPFPREP, 0, "Problem setting modem device ID!" );
  806. DisplayDNError( 0, hr );
  807. goto Failure;
  808. }
  809. Exit:
  810. return hr;
  811. Failure:
  812. goto Exit;
  813. }
  814. //**********************************************************************
  815. //**********************************************************************
  816. // ------------------------------
  817. // SetOutgoingPhoneNumber - set phone number for modem dialog
  818. //
  819. // Entry: Window handle
  820. // Pointer to modem port
  821. //
  822. // Exit: Error code
  823. // ------------------------------
  824. #undef DPF_MODNAME
  825. #define DPF_MODNAME "SetOutgoingPhoneNumber"
  826. HRESULT SetOutgoingPhoneNumber( const HWND hDialog, const CModemEndpoint *const pModemEndpoint )
  827. {
  828. HRESULT hr;
  829. //
  830. // initialize
  831. //
  832. hr = DPN_OK;
  833. if ( SetWindowText( GetDlgItem( hDialog, IDC_EDIT_MODEM_PHONE_NUMBER ), pModemEndpoint->GetPhoneNumber() ) == FALSE )
  834. {
  835. DPFX(DPFPREP, 0, "Problem setting default phone number!" );
  836. DisplayErrorCode( 0, GetLastError() );
  837. goto Exit;
  838. }
  839. Exit:
  840. return hr;
  841. }
  842. //**********************************************************************
  843. //**********************************************************************
  844. // ------------------------------
  845. // SetAddressParamtersFromIncomingDialogData - set address data from incoming modem settings dialog
  846. //
  847. // Entry: Window handle
  848. // Pointer to modem port
  849. //
  850. // Exit: Error code
  851. // ------------------------------
  852. #undef DPF_MODNAME
  853. #define DPF_MODNAME "SetAddressParametersFromIncomingDialogData"
  854. static HRESULT SetAddressParametersFromIncomingDialogData( const HWND hDialog, CModemEndpoint *const pModemEndpoint )
  855. {
  856. HRESULT hr;
  857. HWND hControl;
  858. //
  859. // initialize
  860. //
  861. hr = DPN_OK;
  862. hControl = GetDlgItem( hDialog, IDC_COMBO_INCOMING_MODEM_DEVICE );
  863. if ( hControl == NULL )
  864. {
  865. hr = DPNERR_GENERIC;
  866. DPFX(DPFPREP, 0, "Problem getting handle of combo box!" );
  867. DisplayErrorCode( 0, GetLastError() );
  868. goto Failure;
  869. }
  870. hr = GetModemSelectionFromDialog( hControl, pModemEndpoint );
  871. if ( hr != DPN_OK )
  872. {
  873. DPFX(DPFPREP, 0, "Problem getting modem device!" );
  874. DisplayDNError( 0, hr );
  875. goto Failure;
  876. }
  877. Failure:
  878. return hr;
  879. }
  880. //**********************************************************************
  881. //**********************************************************************
  882. // ------------------------------
  883. // SetAddressParamtersFromOutgoingDialogData - set endpoint data from outgoing modem settings dialog
  884. //
  885. // Entry: Window handle
  886. // Pointer to modem port
  887. //
  888. // Exit: Error code
  889. // ------------------------------
  890. #undef DPF_MODNAME
  891. #define DPF_MODNAME "SetAddressParametersFromOutgoingDialogData"
  892. static HRESULT SetAddressParametersFromOutgoingDialogData( const HWND hDialog, CModemEndpoint *const pModemEndpoint )
  893. {
  894. HRESULT hr;
  895. HWND hControl;
  896. DWORD dwPhoneNumberLength;
  897. TCHAR TempBuffer[ MAX_PHONE_NUMBER_LENGTH + 1 ];
  898. DNASSERT( hDialog != NULL );
  899. DNASSERT( pModemEndpoint != NULL );
  900. // initialize
  901. hr = DPN_OK;
  902. hControl = GetDlgItem( hDialog, IDC_COMBO_OUTGOING_MODEM_DEVICE );
  903. if ( hControl == NULL )
  904. {
  905. hr = DPNERR_GENERIC;
  906. DPFX(DPFPREP, 0, "Problem getting handle of combo box!" );
  907. DisplayErrorCode( 0, GetLastError() );
  908. goto Failure;
  909. }
  910. hr = GetModemSelectionFromDialog( hControl, pModemEndpoint );
  911. if ( hr != DPN_OK )
  912. {
  913. DPFX(DPFPREP, 0, "Problem getting modem device!" );
  914. DisplayDNError( 0, hr );
  915. goto Failure;
  916. }
  917. // get phone number from dialog
  918. hControl = GetDlgItem( hDialog, IDC_EDIT_MODEM_PHONE_NUMBER );
  919. if ( hControl == NULL )
  920. {
  921. hr = DPNERR_GENERIC;
  922. DPFX(DPFPREP, 0, "Problem getting handle of phone number edit field!" );
  923. DisplayErrorCode( 0, GetLastError() );
  924. goto Failure;
  925. }
  926. dwPhoneNumberLength = GetWindowText( hControl, TempBuffer, (sizeof(TempBuffer)/sizeof(TCHAR)) - 1 );
  927. if ( dwPhoneNumberLength == 0 )
  928. {
  929. #ifdef DBG
  930. DWORD dwErrorReturn;
  931. dwErrorReturn = GetLastError();
  932. DPFX(DPFPREP, 0, "User entered an invalid phone number in dialog (err = %u)!", dwErrorReturn );
  933. #endif // DBG
  934. hr = DPNERR_ADDRESSING;
  935. goto Failure;
  936. }
  937. else
  938. {
  939. hr = pModemEndpoint->SetPhoneNumber( TempBuffer );
  940. if ( hr != DPN_OK )
  941. {
  942. DPFX(DPFPREP, 0, "Problem setting new phone number!" );
  943. DisplayDNError( 0, hr );
  944. goto Failure;
  945. }
  946. }
  947. Failure:
  948. return hr;
  949. }
  950. //**********************************************************************
  951. //**********************************************************************
  952. // ------------------------------
  953. // DisplayModemConfigDialog - display dialog to configure modem
  954. //
  955. // Entry: Window handle
  956. // Pointer to modem port
  957. //
  958. // Exit: Error code
  959. // ------------------------------
  960. #undef DPF_MODNAME
  961. #define DPF_MODNAME "DisplayModemConfigDialog"
  962. static HRESULT DisplayModemConfigDialog( const HWND hDialog, const HWND hDeviceComboBox, const CModemEndpoint *const pModemEndpoint )
  963. {
  964. HRESULT hr;
  965. LRESULT lSelection;
  966. LRESULT lDeviceID;
  967. LONG lTAPIReturn;
  968. DNASSERT( hDialog != NULL );
  969. DNASSERT( pModemEndpoint != NULL );
  970. //
  971. // initialize
  972. //
  973. hr = DPN_OK;
  974. if ( hDeviceComboBox == NULL )
  975. {
  976. hr = DPNERR_GENERIC;
  977. DPFX(DPFPREP, 0, "Invalid device combo box handle!" );
  978. goto Exit;
  979. }
  980. //
  981. // ask for current selection in combo box
  982. //
  983. lSelection = SendMessage( hDeviceComboBox, CB_GETCURSEL, 0, 0 );
  984. if ( lSelection == CB_ERR )
  985. {
  986. hr = DPNERR_GENERIC;
  987. DPFX(DPFPREP, 0, "Failed to get current modem selection when configuring modem!" );
  988. DNASSERT( FALSE );
  989. goto Exit;
  990. }
  991. //
  992. // ask for the device ID for this selection, note that the device IDs are
  993. //
  994. lDeviceID = SendMessage( hDeviceComboBox, CB_GETITEMDATA, lSelection, 0 );
  995. if ( lDeviceID == CB_ERR )
  996. {
  997. hr = DPNERR_GENERIC;
  998. DPFX(DPFPREP, 0, "Problem getting device ID from selected modem when calling for config dialog!" );
  999. goto Exit;
  1000. }
  1001. // display dialog
  1002. DNASSERT( lDeviceID <= UINT32_MAX );
  1003. lTAPIReturn = p_lineConfigDialog( TAPIIDFromModemID( static_cast<DWORD>( lDeviceID ) ),
  1004. hDialog,
  1005. TEXT("comm/datamodem") );
  1006. if ( lTAPIReturn != LINEERR_NONE )
  1007. {
  1008. hr = DPNERR_GENERIC;
  1009. DPFX(DPFPREP, 0, "Problem with modem config dialog!" );
  1010. DisplayTAPIError( 0, lTAPIReturn );
  1011. goto Exit;
  1012. }
  1013. Exit:
  1014. return hr;
  1015. }
  1016. //**********************************************************************