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.

1355 lines
31 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ComPortUI.cpp
  6. * Content: Serial 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. //
  19. // default size of temp strings used to add stuff to dialog
  20. //
  21. #define DEFAULT_DIALOG_STRING_SIZE 100
  22. #define DEFAULT_DEVICE_SELECTION_INDEX 0
  23. #define DEFAULT_BAUD_RATE_SELECTION_INDEX 11
  24. #define DEFAULT_STOP_BITS_SELECTION_INDEX 0
  25. #define DEFAULT_PARITY_SELECTION_INDEX 0
  26. #define DEFAULT_FLOW_CONTROL_SELECTION_INDEX 0
  27. //
  28. // expected return from comport dialog
  29. //
  30. static const INT_PTR g_iExpectedComPortDialogReturn = 0x12345678;
  31. //**********************************************************************
  32. // Macro definitions
  33. //**********************************************************************
  34. //**********************************************************************
  35. // Structure definitions
  36. //**********************************************************************
  37. //**********************************************************************
  38. // Variable definitions
  39. //**********************************************************************
  40. //**********************************************************************
  41. // Function prototypes
  42. //**********************************************************************
  43. static INT_PTR CALLBACK SettingsDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  44. static HRESULT SetDialogDevice( const HWND hDlg, const CModemEndpoint *const pComEndpoint );
  45. static HRESULT SetDialogBaudRate( const HWND hDlg, const CModemEndpoint *const pComEndpoint );
  46. static HRESULT SetDialogStopBits( const HWND hDlg, const CModemEndpoint *const pComEndpoint );
  47. static HRESULT SetDialogParity( const HWND hDlg, const CModemEndpoint *const pComEndpoint );
  48. static HRESULT SetDialogFlowControl( const HWND hDlg, const CModemEndpoint *const pComEndpoint );
  49. static HRESULT GetDialogData( const HWND hDlg, CModemEndpoint *const pComEndpoint );
  50. //**********************************************************************
  51. // Function definitions
  52. //**********************************************************************
  53. //**********************************************************************
  54. // ------------------------------
  55. // DisplayComPortDialog - dialog for comport settings
  56. //
  57. // Entry: Pointer to CModemEndpoint
  58. //
  59. // Exit: Nothing
  60. // ------------------------------
  61. #undef DPF_MODNAME
  62. #define DPF_MODNAME "DisplayComPortSettingsDialog"
  63. void DisplayComPortSettingsDialog( void *const pContext )
  64. {
  65. INT_PTR iDlgReturn;
  66. CModemEndpoint *pComEndpoint;
  67. DNASSERT( pContext != NULL );
  68. //
  69. // intialize
  70. //
  71. pComEndpoint = static_cast<CModemEndpoint*>( pContext );
  72. DBG_CASSERT( sizeof( pComEndpoint ) == sizeof( LPARAM ) );
  73. SetLastError( ERROR_SUCCESS );
  74. iDlgReturn = DialogBoxParam( g_hModemDLLInstance, // handle of module for resources
  75. MAKEINTRESOURCE( IDD_SERIAL_SETTINGS ), // resource for dialog
  76. NULL, // parent (none)
  77. SettingsDialogProc, // dialog message proc
  78. reinterpret_cast<LPARAM>( pComEndpoint ) // startup parameter
  79. );
  80. if ( iDlgReturn != g_iExpectedComPortDialogReturn )
  81. {
  82. DWORD dwError;
  83. dwError = GetLastError();
  84. DPFX(DPFPREP, 0, "Failed to start comport settings dialog!" );
  85. DisplayErrorCode( 0, dwError );
  86. pComEndpoint->SettingsDialogComplete( DPNERR_OUTOFMEMORY );
  87. }
  88. return;
  89. }
  90. //**********************************************************************
  91. //**********************************************************************
  92. // ------------------------------
  93. // StopComPortSettingsDialog - stop dialog dialog for serial settings
  94. //
  95. // Entry: Handle of dialog
  96. //
  97. // Exit: Nothing
  98. // ------------------------------
  99. #undef DPF_MODNAME
  100. #define DPF_MODNAME "StopComPortSettingsDialog"
  101. void StopComPortSettingsDialog( const HWND hDlg )
  102. {
  103. DNASSERT( hDlg != NULL );
  104. if ( PostMessage( hDlg, WM_COMMAND, MAKEWPARAM( IDCANCEL, NULL ), NULL ) == 0 )
  105. {
  106. DWORD dwError;
  107. dwError = GetLastError();
  108. DPFX(DPFPREP, 0, "Failed to stop dialog!" );
  109. DisplayErrorCode( 0, dwError );
  110. DNASSERT( FALSE );
  111. }
  112. }
  113. //**********************************************************************
  114. //**********************************************************************
  115. // ------------------------------
  116. // SettingsDialogProc - dialog proc serial settings
  117. //
  118. // Entry: Window handle
  119. // Message
  120. // Message LPARAM
  121. // Message WPARAM
  122. //
  123. // Exit: Error code
  124. // ------------------------------
  125. #undef DPF_MODNAME
  126. #define DPF_MODNAME "SettingsDialogProc"
  127. static INT_PTR CALLBACK SettingsDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  128. {
  129. HRESULT hr;
  130. CModemEndpoint *pComEndpoint;
  131. //
  132. // initialize
  133. //
  134. hr = DPN_OK;
  135. pComEndpoint = NULL;
  136. //
  137. // note the active comport pointer
  138. //
  139. DBG_CASSERT( sizeof( pComEndpoint ) == sizeof( ULONG_PTR ) );
  140. pComEndpoint = reinterpret_cast<CModemEndpoint*>( GetWindowLongPtr( hDlg, GWLP_USERDATA ) );
  141. switch ( uMsg )
  142. {
  143. // initialize dialog
  144. case WM_INITDIALOG:
  145. {
  146. //
  147. // since this is the first dialog message, the default code to set
  148. // pComEndpoint didn't get valid data so we need to update the pointer
  149. //
  150. DBG_CASSERT( sizeof( pComEndpoint ) == sizeof( lParam ) );
  151. pComEndpoint = reinterpret_cast<CModemEndpoint*>( lParam );
  152. pComEndpoint->SetActiveDialogHandle( hDlg );
  153. //
  154. // SetWindowLong() returns NULL in case of error. It's possible that
  155. // the old value from SetWindowLong() was really NULL in which case it's not
  156. // an error. To be safe, clear any residual error code before calling
  157. // SetWindowLong().
  158. //
  159. SetLastError( 0 );
  160. if ( SetWindowLongPtr( hDlg, GWLP_USERDATA, lParam ) == NULL )
  161. {
  162. DWORD dwError;
  163. dwError = GetLastError();
  164. if ( dwError != ERROR_SUCCESS )
  165. {
  166. DPFX(DPFPREP, 0, "Problem setting user data for window!" );
  167. DisplayErrorCode( 0, dwError );
  168. hr = DPNERR_GENERIC;
  169. goto Failure;
  170. }
  171. }
  172. //
  173. // set dialog parameters
  174. //
  175. hr = SetDialogDevice( hDlg, pComEndpoint );
  176. if ( hr != DPN_OK )
  177. {
  178. DPFX(DPFPREP, 0, "Problem setting device in WM_INITDIALOG!" );
  179. DisplayDNError( 0, hr );
  180. goto Failure;
  181. }
  182. hr = SetDialogBaudRate( hDlg, pComEndpoint );
  183. if ( hr != DPN_OK )
  184. {
  185. DPFX(DPFPREP, 0, "Problem setting baud rate in WM_INITDIALOG!" );
  186. DisplayDNError( 0, hr );
  187. goto Failure;
  188. }
  189. hr = SetDialogStopBits( hDlg, pComEndpoint );
  190. if ( hr != DPN_OK )
  191. {
  192. DPFX(DPFPREP, 0, "Problem setting stop bits in WM_INITDIALOG!" );
  193. DisplayDNError( 0, hr );
  194. goto Failure;
  195. }
  196. hr = SetDialogParity( hDlg, pComEndpoint );
  197. if ( hr != DPN_OK )
  198. {
  199. DPFX(DPFPREP, 0, "Problem setting parity in WM_INITDIALOG!" );
  200. DisplayDNError( 0, hr );
  201. goto Failure;
  202. }
  203. hr = SetDialogFlowControl( hDlg, pComEndpoint );
  204. if ( hr != DPN_OK )
  205. {
  206. DPFX(DPFPREP, 0, "Problem setting flow control in WM_INITDIALOG!" );
  207. DisplayDNError( 0, hr );
  208. goto Failure;
  209. }
  210. return TRUE;
  211. break;
  212. }
  213. // a control did something
  214. case WM_COMMAND:
  215. {
  216. // what was the control?
  217. switch ( LOWORD( wParam ) )
  218. {
  219. case IDOK:
  220. {
  221. hr = GetDialogData( hDlg, pComEndpoint );
  222. if ( hr != DPN_OK )
  223. {
  224. DPFX(DPFPREP, 0, "Problem getting UI data!" );
  225. DisplayDNError( 0, hr );
  226. goto Failure;
  227. }
  228. // pass any error code on to 'DialogComplete'
  229. pComEndpoint->SettingsDialogComplete( hr );
  230. EndDialog( hDlg, g_iExpectedComPortDialogReturn );
  231. break;
  232. }
  233. case IDCANCEL:
  234. {
  235. pComEndpoint->SettingsDialogComplete( DPNERR_USERCANCEL );
  236. EndDialog( hDlg, g_iExpectedComPortDialogReturn );
  237. break;
  238. }
  239. default:
  240. {
  241. break;
  242. }
  243. }
  244. break;
  245. }
  246. // window is closing
  247. case WM_CLOSE:
  248. {
  249. break;
  250. }
  251. }
  252. Exit:
  253. return FALSE;
  254. Failure:
  255. DNASSERT( pComEndpoint != NULL );
  256. DNASSERT( hr != DPN_OK );
  257. pComEndpoint->SettingsDialogComplete( hr );
  258. EndDialog( hDlg, g_iExpectedComPortDialogReturn );
  259. goto Exit;
  260. }
  261. //**********************************************************************
  262. //**********************************************************************
  263. // ------------------------------
  264. // SetDialogDevice - set serial device field
  265. //
  266. // Entry: Window handle
  267. // Pointer to ComEndpoint
  268. //
  269. // Exit: Error code
  270. // ------------------------------
  271. #undef DPF_MODNAME
  272. #define DPF_MODNAME "SetDialogDevice"
  273. static HRESULT SetDialogDevice( const HWND hDlg, const CModemEndpoint *const pComEndpoint )
  274. {
  275. HRESULT hr;
  276. UINT_PTR uIndex;
  277. BOOL fPortAvailable[ MAX_DATA_PORTS ];
  278. DWORD dwPortCount;
  279. TCHAR TempBuffer[ DEFAULT_DIALOG_STRING_SIZE ];
  280. BOOL fSelectionSet;
  281. HWND hSerialDeviceComboBox;
  282. //
  283. // initialize
  284. //
  285. hr = DPN_OK;
  286. fSelectionSet = FALSE;
  287. hSerialDeviceComboBox = GetDlgItem( hDlg, IDC_COMBO_SERIAL_DEVICE );
  288. if ( hSerialDeviceComboBox == NULL )
  289. {
  290. DWORD dwError;
  291. hr = DPNERR_GENERIC;
  292. dwError = GetLastError();
  293. DPFX(DPFPREP, 0, "Problem getting handle of serial device combo box!" );
  294. DisplayErrorCode( 0, dwError );
  295. goto Failure;
  296. }
  297. //
  298. // get list of available com ports
  299. //
  300. hr = GenerateAvailableComPortList( fPortAvailable, ( LENGTHOF( fPortAvailable ) - 1 ), &dwPortCount );
  301. if ( hr != DPN_OK )
  302. {
  303. DPFX(DPFPREP, 0, "Problem generating vaild port list!" );
  304. DisplayDNError( 0, hr );
  305. goto Failure;
  306. }
  307. //
  308. // add all strings to dialog
  309. //
  310. uIndex = LENGTHOF( fPortAvailable );
  311. while ( uIndex > 0 )
  312. {
  313. LRESULT lSendReturn;
  314. uIndex--;
  315. //
  316. // only output all adapters on incoming settings
  317. //
  318. if ( fPortAvailable[ uIndex ] != FALSE )
  319. {
  320. DNASSERT( uIndex != 0 ); // ALL_ADAPTERS is not valid!
  321. ComDeviceIDToString( TempBuffer, uIndex );
  322. DBG_CASSERT( sizeof( &TempBuffer[ 0 ] ) == sizeof( LPARAM ) );
  323. lSendReturn = SendMessage( hSerialDeviceComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>( TempBuffer ) );
  324. switch ( lSendReturn )
  325. {
  326. case CB_ERR:
  327. {
  328. hr = DPNERR_GENERIC;
  329. DPFX(DPFPREP, 0, "Problem adding serial device to combo box!" );
  330. goto Failure;
  331. break;
  332. }
  333. case CB_ERRSPACE:
  334. {
  335. hr = DPNERR_OUTOFMEMORY;
  336. DPFX(DPFPREP, 0, "Out of memory when ading serial device to combo box!" );
  337. goto Failure;
  338. break;
  339. }
  340. //
  341. // we added the string OK, set the associated device id and check
  342. // to see if this is the current value to set selection
  343. //
  344. default:
  345. {
  346. LRESULT lTempReturn;
  347. lTempReturn = SendMessage ( hSerialDeviceComboBox, CB_SETITEMDATA, lSendReturn, uIndex );
  348. if ( lTempReturn == CB_ERR )
  349. {
  350. DWORD dwError;
  351. hr = DPNERR_OUTOFMEMORY;
  352. dwError = GetLastError();
  353. DPFX(DPFPREP, 0, "Problem setting device info!" );
  354. DisplayErrorCode( 0, dwError );
  355. goto Failure;
  356. }
  357. if ( pComEndpoint->GetDeviceID() == uIndex )
  358. {
  359. lTempReturn = SendMessage( hSerialDeviceComboBox, CB_SETCURSEL, lSendReturn, 0 );
  360. switch ( lTempReturn )
  361. {
  362. case CB_ERR:
  363. {
  364. DWORD dwError;
  365. hr = DPNERR_GENERIC;
  366. dwError = GetLastError();
  367. DPFX(DPFPREP, 0, "Problem setting default serial device selection!" );
  368. DisplayErrorCode( 0, dwError );
  369. DNASSERT( FALSE );
  370. goto Failure;
  371. break;
  372. }
  373. default:
  374. {
  375. fSelectionSet = TRUE;
  376. break;
  377. }
  378. }
  379. }
  380. break;
  381. }
  382. }
  383. }
  384. }
  385. //
  386. // was a selection set? If not, set default
  387. //
  388. if ( fSelectionSet == FALSE )
  389. {
  390. LRESULT lSendReturn;
  391. DPFX(DPFPREP, 8, "Serial device not set, using default!" );
  392. lSendReturn = SendMessage( hSerialDeviceComboBox, CB_SETCURSEL, DEFAULT_DEVICE_SELECTION_INDEX, 0 );
  393. switch ( lSendReturn )
  394. {
  395. case CB_ERR:
  396. {
  397. hr = DPNERR_GENERIC;
  398. DPFX(DPFPREP, 0, "Cannot set default serial device selection!" );
  399. DisplayErrorCode( 0, GetLastError() );
  400. DNASSERT( FALSE );
  401. goto Failure;
  402. break;
  403. }
  404. default:
  405. {
  406. break;
  407. }
  408. }
  409. }
  410. Exit:
  411. return hr;
  412. Failure:
  413. goto Exit;
  414. }
  415. //**********************************************************************
  416. //**********************************************************************
  417. // ------------------------------
  418. // SetDialogBaudRate - set serial baud rate fields
  419. //
  420. // Entry: Window handle
  421. // Pointer to com port
  422. //
  423. // Exit: Error code
  424. // ------------------------------
  425. #undef DPF_MODNAME
  426. #define DPF_MODNAME "SetDialogBaudRate"
  427. static HRESULT SetDialogBaudRate( const HWND hDlg, const CModemEndpoint *const pComEndpoint )
  428. {
  429. HRESULT hr;
  430. UINT_PTR uIndex;
  431. BOOL fSelectionSet;
  432. HWND hBaudRateComboBox;
  433. //
  434. // initialize
  435. //
  436. hr = DPN_OK;
  437. uIndex = g_dwBaudRateCount;
  438. fSelectionSet = FALSE;
  439. hBaudRateComboBox = GetDlgItem( hDlg, IDC_COMBO_SERIAL_BAUDRATE );
  440. if ( hBaudRateComboBox == NULL )
  441. {
  442. hr = DPNERR_GENERIC;
  443. DPFX(DPFPREP, 0, "Problem getting handle of serial baud rate combo box!" );
  444. DisplayErrorCode( 0, GetLastError() );
  445. goto Failure;
  446. }
  447. //
  448. // add all strings to dialog
  449. //
  450. while ( uIndex > 0 )
  451. {
  452. LRESULT lSendReturn;
  453. uIndex--;
  454. DBG_CASSERT( sizeof( g_BaudRate[ uIndex ].pASCIIKey ) == sizeof( LPARAM ) );
  455. lSendReturn = SendMessage( hBaudRateComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>( g_BaudRate[ uIndex ].szLocalizedKey ) );
  456. switch ( lSendReturn )
  457. {
  458. case CB_ERR:
  459. {
  460. hr = DPNERR_GENERIC;
  461. DPFX(DPFPREP, 0, "Problem adding baud rate to combo box!" );
  462. goto Failure;
  463. break;
  464. }
  465. case CB_ERRSPACE:
  466. {
  467. hr = DPNERR_OUTOFMEMORY;
  468. DPFX(DPFPREP, 0, "Out of memory adding baud rate to combo box!" );
  469. goto Failure;
  470. break;
  471. }
  472. default:
  473. {
  474. LRESULT lTempReturn;
  475. //
  476. // we added the string OK, attemt to set the item data and
  477. // check to see if this is the current value
  478. //
  479. lTempReturn = SendMessage( hBaudRateComboBox, CB_SETITEMDATA, lSendReturn, g_BaudRate[ uIndex ].dwEnumValue );
  480. if ( lTempReturn == CB_ERR )
  481. {
  482. hr = DPNERR_OUTOFMEMORY;
  483. DPFX(DPFPREP, 0, "Failed to set baud rate item data!" );
  484. goto Failure;
  485. }
  486. if ( pComEndpoint->GetBaudRate() == g_BaudRate[ uIndex ].dwEnumValue )
  487. {
  488. // set current selection to this item
  489. lTempReturn = SendMessage( hBaudRateComboBox, CB_SETCURSEL, lSendReturn, 0 );
  490. switch ( lTempReturn )
  491. {
  492. case CB_ERR:
  493. {
  494. hr = DPNERR_GENERIC;
  495. DPFX(DPFPREP, 0, "Problem setting default serial baud rate selection!" );
  496. DisplayErrorCode( 0, GetLastError() );
  497. DNASSERT( FALSE );
  498. goto Failure;
  499. break;
  500. }
  501. default:
  502. {
  503. fSelectionSet = TRUE;
  504. break;
  505. }
  506. }
  507. }
  508. break;
  509. }
  510. }
  511. }
  512. //
  513. // was a selection set? If not, set default
  514. //
  515. if ( fSelectionSet == FALSE )
  516. {
  517. LRESULT lSendReturn;
  518. DPFX(DPFPREP, 8, "Serial baud rate not set, using default!" );
  519. lSendReturn = SendMessage( hBaudRateComboBox, CB_SETCURSEL, DEFAULT_BAUD_RATE_SELECTION_INDEX, 0 );
  520. switch ( lSendReturn )
  521. {
  522. case CB_ERR:
  523. {
  524. hr = DPNERR_GENERIC;
  525. DPFX(DPFPREP, 0, "Cannot set default serial baud rate selection!" );
  526. DisplayErrorCode( 0, GetLastError() );
  527. DNASSERT( FALSE );
  528. goto Failure;
  529. break;
  530. }
  531. default:
  532. {
  533. break;
  534. }
  535. }
  536. }
  537. Exit:
  538. return hr;
  539. Failure:
  540. goto Exit;
  541. }
  542. //**********************************************************************
  543. //**********************************************************************
  544. // ------------------------------
  545. // SetDialogStopBits - set serial stop bits fields
  546. //
  547. // Entry: Window handle
  548. // Pointer to ComEndpoint
  549. //
  550. // Exit: Error code
  551. // ------------------------------
  552. #undef DPF_MODNAME
  553. #define DPF_MODNAME "SetDialogStopBits"
  554. static HRESULT SetDialogStopBits( const HWND hDlg, const CModemEndpoint *const pComEndpoint )
  555. {
  556. HRESULT hr;
  557. UINT_PTR uIndex;
  558. BOOL fSelectionSet;
  559. HWND hStopBitsComboBox;
  560. //
  561. // initialize
  562. //
  563. hr = DPN_OK;
  564. uIndex = g_dwStopBitsCount;
  565. fSelectionSet = FALSE;
  566. hStopBitsComboBox = GetDlgItem( hDlg, IDC_COMBO_SERIAL_STOPBITS );
  567. if ( hStopBitsComboBox == NULL )
  568. {
  569. hr = DPNERR_GENERIC;
  570. DPFX(DPFPREP, 0, "Problem getting handle of serial stop bits combo box!" );
  571. DisplayErrorCode( 0, GetLastError() );
  572. goto Failure;
  573. }
  574. //
  575. // add all strings to dialog
  576. //
  577. while ( uIndex > 0 )
  578. {
  579. LRESULT lSendReturn;
  580. uIndex--;
  581. DBG_CASSERT( sizeof( g_StopBits[ uIndex ].pASCIIKey ) == sizeof( LPARAM ) );
  582. lSendReturn = SendMessage( hStopBitsComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>( g_StopBits[ uIndex ].szLocalizedKey ) );
  583. switch ( lSendReturn )
  584. {
  585. case CB_ERR:
  586. {
  587. hr = DPNERR_GENERIC;
  588. DPFX(DPFPREP, 0, "Problem adding stop bits to combo box!" );
  589. goto Failure;
  590. break;
  591. }
  592. case CB_ERRSPACE:
  593. {
  594. hr = DPNERR_OUTOFMEMORY;
  595. DPFX(DPFPREP, 0, "Out of memory adding stop bits to combo box!" );
  596. goto Failure;
  597. break;
  598. }
  599. default:
  600. {
  601. LRESULT lTempReturn;
  602. //
  603. // we added the string OK attempt to set the associated data and
  604. // check to see if this is the current value
  605. //
  606. lTempReturn = SendMessage( hStopBitsComboBox, CB_SETITEMDATA, lSendReturn, g_StopBits[ uIndex ].dwEnumValue);
  607. if ( lTempReturn == CB_ERR )
  608. {
  609. hr = DPNERR_OUTOFMEMORY;
  610. DPFX(DPFPREP, 0, "Failed to set associated data for stop bits!" );
  611. goto Failure;
  612. }
  613. if ( pComEndpoint->GetStopBits() == g_StopBits[ uIndex ].dwEnumValue )
  614. {
  615. // set current selection to this item
  616. lTempReturn = SendMessage( hStopBitsComboBox, CB_SETCURSEL, lSendReturn, 0 );
  617. switch ( lTempReturn )
  618. {
  619. case CB_ERR:
  620. {
  621. hr = DPNERR_GENERIC;
  622. DPFX(DPFPREP, 0, "Problem setting default serial stop bits selection!" );
  623. DisplayErrorCode( 0, GetLastError() );
  624. DNASSERT( FALSE );
  625. goto Failure;
  626. break;
  627. }
  628. default:
  629. {
  630. fSelectionSet = TRUE;
  631. break;
  632. }
  633. }
  634. }
  635. break;
  636. }
  637. }
  638. }
  639. //
  640. // was a selection set? If not, set default
  641. //
  642. if ( fSelectionSet == FALSE )
  643. {
  644. LRESULT lSendReturn;
  645. DPFX(DPFPREP, 8, "Serial stop bits not set, using default!" );
  646. lSendReturn = SendMessage( hStopBitsComboBox, CB_SETCURSEL, DEFAULT_STOP_BITS_SELECTION_INDEX, 0 );
  647. switch ( lSendReturn )
  648. {
  649. case CB_ERR:
  650. {
  651. hr = DPNERR_GENERIC;
  652. DPFX(DPFPREP, 0, "Cannot set default serial stop bits selection!" );
  653. DisplayErrorCode( 0, GetLastError() );
  654. DNASSERT( FALSE );
  655. goto Failure;
  656. break;
  657. }
  658. default:
  659. {
  660. break;
  661. }
  662. }
  663. }
  664. Exit:
  665. return hr;
  666. Failure:
  667. goto Exit;
  668. }
  669. //**********************************************************************
  670. //**********************************************************************
  671. // ------------------------------
  672. // SetDialogParity - set serial parity fields
  673. //
  674. // Entry: Window handle
  675. // Pointer to ComEndpoint
  676. //
  677. // Exit: Error code
  678. // ------------------------------
  679. #undef DPF_MODNAME
  680. #define DPF_MODNAME "SetDialogParity"
  681. static HRESULT SetDialogParity( const HWND hDlg, const CModemEndpoint *const pComEndpoint )
  682. {
  683. HRESULT hr;
  684. UINT_PTR uIndex;
  685. BOOL fSelectionSet;
  686. HWND hParityComboBox;
  687. //
  688. // initialize
  689. //
  690. hr = DPN_OK;
  691. uIndex = g_dwParityCount;
  692. fSelectionSet = FALSE;
  693. hParityComboBox = GetDlgItem( hDlg, IDC_COMBO_SERIAL_PARITY );
  694. if ( hParityComboBox == NULL )
  695. {
  696. hr = DPNERR_GENERIC;
  697. DPFX(DPFPREP, 0, "Problem getting handle of serial parity combo box!" );
  698. DisplayErrorCode( 0, GetLastError() );
  699. goto Failure;
  700. }
  701. //
  702. // add all strings to dialog
  703. //
  704. while ( uIndex > 0 )
  705. {
  706. LRESULT lSendReturn;
  707. uIndex--;
  708. DBG_CASSERT( sizeof( g_Parity[ uIndex ].pASCIIKey ) == sizeof( LPARAM ) );
  709. lSendReturn = SendMessage( hParityComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>( g_Parity[ uIndex ].szLocalizedKey ) );
  710. switch ( lSendReturn )
  711. {
  712. case CB_ERR:
  713. {
  714. hr = DPNERR_GENERIC;
  715. DPFX(DPFPREP, 0, "Problem adding parity to combo box!" );
  716. goto Failure;
  717. break;
  718. }
  719. case CB_ERRSPACE:
  720. {
  721. hr = DPNERR_OUTOFMEMORY;
  722. DPFX(DPFPREP, 0, "Out of memory adding parity to combo box!" );
  723. goto Failure;
  724. break;
  725. }
  726. default:
  727. {
  728. LRESULT lTempReturn;
  729. //
  730. // we added the string OK, attempt to set the associated data and
  731. // check to see if this is the current value
  732. //
  733. lTempReturn = SendMessage( hParityComboBox, CB_SETITEMDATA, lSendReturn, g_Parity[ uIndex ].dwEnumValue );
  734. if ( lTempReturn == CB_ERR )
  735. {
  736. hr = DPNERR_OUTOFMEMORY;
  737. DPFX(DPFPREP, 0, "Failed to set associated data for parity." );
  738. goto Failure;
  739. }
  740. if ( pComEndpoint->GetParity() == g_Parity[ uIndex ].dwEnumValue )
  741. {
  742. //
  743. // set current selection to this item
  744. //
  745. lTempReturn = SendMessage( hParityComboBox, CB_SETCURSEL, lSendReturn, 0 );
  746. switch ( lTempReturn )
  747. {
  748. case CB_ERR:
  749. {
  750. hr = DPNERR_GENERIC;
  751. DPFX(DPFPREP, 0, "Problem setting default serial parity selection!" );
  752. DisplayErrorCode( 0, GetLastError() );
  753. DNASSERT( FALSE );
  754. goto Failure;
  755. break;
  756. }
  757. default:
  758. {
  759. fSelectionSet = TRUE;
  760. break;
  761. }
  762. }
  763. }
  764. break;
  765. }
  766. }
  767. }
  768. //
  769. // was a selection set? If not, set default
  770. //
  771. if ( fSelectionSet == FALSE )
  772. {
  773. LRESULT lSendReturn;
  774. DPFX(DPFPREP, 8, "Serial parity not set, using default!" );
  775. lSendReturn = SendMessage( hParityComboBox, CB_SETCURSEL, DEFAULT_PARITY_SELECTION_INDEX, 0 );
  776. switch ( lSendReturn )
  777. {
  778. case CB_ERR:
  779. {
  780. hr = DPNERR_GENERIC;
  781. DPFX(DPFPREP, 0, "Cannot set default serial parity selection!" );
  782. DisplayErrorCode( 0, GetLastError() );
  783. DNASSERT( FALSE );
  784. goto Failure;
  785. break;
  786. }
  787. default:
  788. {
  789. break;
  790. }
  791. }
  792. }
  793. Exit:
  794. return hr;
  795. Failure:
  796. goto Exit;
  797. }
  798. //**********************************************************************
  799. //**********************************************************************
  800. // ------------------------------
  801. // SetDialogFlowControl - set serial flow control
  802. //
  803. // Entry: Window handle
  804. // Pointer to ComEndpoint
  805. //
  806. // Exit: Error code
  807. // ------------------------------
  808. #undef DPF_MODNAME
  809. #define DPF_MODNAME "SetDialogFlowControl"
  810. static HRESULT SetDialogFlowControl( const HWND hDlg, const CModemEndpoint *const pComEndpoint )
  811. {
  812. HRESULT hr;
  813. UINT_PTR uIndex;
  814. BOOL fSelectionSet;
  815. HWND hFlowControlComboBox;
  816. //
  817. // initialize
  818. //
  819. hr = DPN_OK;
  820. uIndex = g_dwFlowControlCount;
  821. fSelectionSet = FALSE;
  822. hFlowControlComboBox = GetDlgItem( hDlg, IDC_COMBO_SERIAL_FLOWCONTROL );
  823. if ( hFlowControlComboBox == NULL )
  824. {
  825. hr = DPNERR_GENERIC;
  826. DPFX(DPFPREP, 0, "Problem getting handle of serial flow control combo box!" );
  827. DisplayErrorCode( 0, GetLastError() );
  828. goto Failure;
  829. }
  830. //
  831. // add all strings to dialog
  832. //
  833. while ( uIndex > 0 )
  834. {
  835. LRESULT lSendReturn;
  836. uIndex--;
  837. DBG_CASSERT( sizeof( g_FlowControl[ uIndex ].pASCIIKey ) == sizeof( LPARAM ) );
  838. lSendReturn = SendMessage( hFlowControlComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>( g_FlowControl[ uIndex ].szLocalizedKey ) );
  839. switch ( lSendReturn )
  840. {
  841. case CB_ERR:
  842. {
  843. hr = DPNERR_GENERIC;
  844. DPFX(DPFPREP, 0, "Problem adding flow control to combo box!" );
  845. goto Failure;
  846. break;
  847. }
  848. case CB_ERRSPACE:
  849. {
  850. hr = DPNERR_OUTOFMEMORY;
  851. DPFX(DPFPREP, 0, "Out of memory adding flow control to combo box!" );
  852. goto Failure;
  853. break;
  854. }
  855. default:
  856. {
  857. LRESULT lTempReturn;
  858. //
  859. // we added the string OK, attempt to set the associated data and
  860. // check to see if this is the current value
  861. //
  862. lTempReturn = SendMessage( hFlowControlComboBox, CB_SETITEMDATA, lSendReturn, g_FlowControl[ uIndex ].dwEnumValue );
  863. if ( lTempReturn == CB_ERR )
  864. {
  865. hr = DPNERR_OUTOFMEMORY;
  866. DPFX(DPFPREP, 0, "Failed to set associated data for flow control!" );
  867. goto Failure;
  868. }
  869. if ( pComEndpoint->GetFlowControl() == static_cast<SP_FLOW_CONTROL>( g_FlowControl[ uIndex ].dwEnumValue ) )
  870. {
  871. // set current selection to this item
  872. lTempReturn = SendMessage( hFlowControlComboBox, CB_SETCURSEL, lSendReturn, 0 );
  873. switch ( lTempReturn )
  874. {
  875. case CB_ERR:
  876. {
  877. hr = DPNERR_GENERIC;
  878. DPFX(DPFPREP, 0, "Problem setting default flow control selection!" );
  879. DisplayErrorCode( 0, GetLastError() );
  880. DNASSERT( FALSE );
  881. goto Failure;
  882. break;
  883. }
  884. default:
  885. {
  886. fSelectionSet = TRUE;
  887. break;
  888. }
  889. }
  890. }
  891. break;
  892. }
  893. }
  894. }
  895. //
  896. // was a selection set? If not, set default
  897. //
  898. if ( fSelectionSet == FALSE )
  899. {
  900. LRESULT lSendReturn;
  901. DPFX(DPFPREP, 8, "Serial flow control not set, using default!" );
  902. lSendReturn = SendMessage( hFlowControlComboBox, CB_SETCURSEL, DEFAULT_FLOW_CONTROL_SELECTION_INDEX, 0 );
  903. switch ( lSendReturn )
  904. {
  905. case CB_ERR:
  906. {
  907. hr = DPNERR_GENERIC;
  908. DPFX(DPFPREP, 0, "Cannot set default serial flow control selection!" );
  909. DisplayErrorCode( 0, GetLastError() );
  910. DNASSERT( FALSE );
  911. goto Failure;
  912. break;
  913. }
  914. default:
  915. {
  916. break;
  917. }
  918. }
  919. }
  920. Exit:
  921. return hr;
  922. Failure:
  923. goto Exit;
  924. }
  925. //**********************************************************************
  926. //**********************************************************************
  927. // ------------------------------
  928. // GetDialogData - set ComEndpoint data from serial dialog
  929. //
  930. // Entry: Window handle
  931. // Pointer to ComEndpoint
  932. //
  933. // Exit: Error code
  934. // ------------------------------
  935. #undef DPF_MODNAME
  936. #define DPF_MODNAME "GetDialogData"
  937. static HRESULT GetDialogData( const HWND hDlg, CModemEndpoint *const pComEndpoint )
  938. {
  939. HRESULT hr;
  940. LRESULT lSelection;
  941. //
  942. // initialize
  943. //
  944. hr = DPN_OK;
  945. //
  946. // get comm device
  947. //
  948. lSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_DEVICE ), CB_GETCURSEL, 0, 0 );
  949. switch ( lSelection )
  950. {
  951. case CB_ERR:
  952. {
  953. hr = DPNERR_GENERIC;
  954. DPFX(DPFPREP, 0, "Failed to determine serial device selection!" );
  955. DNASSERT( FALSE );
  956. goto Failure;
  957. break;
  958. }
  959. default:
  960. {
  961. LRESULT lItemData;
  962. HRESULT hTempResult;
  963. lItemData = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_DEVICE ), CB_GETITEMDATA, lSelection, 0 );
  964. if ( lItemData == CB_ERR )
  965. {
  966. hr = DPNERR_GENERIC;
  967. DPFX(DPFPREP, 0, "Failed to get associated device data!" );
  968. DNASSERT( FALSE );
  969. goto Failure;
  970. }
  971. DNASSERT( hr == DPN_OK );
  972. DNASSERT( lItemData != 0 );
  973. DNASSERT( lItemData <= UINT32_MAX );
  974. hTempResult = pComEndpoint->SetDeviceID( static_cast<DWORD>( lItemData ) );
  975. DNASSERT( hTempResult == DPN_OK );
  976. break;
  977. }
  978. }
  979. //
  980. // get baud rate
  981. //
  982. lSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_BAUDRATE ), CB_GETCURSEL, 0, 0 );
  983. switch ( lSelection )
  984. {
  985. case CB_ERR:
  986. {
  987. hr = DPNERR_GENERIC;
  988. DPFX(DPFPREP, 0, "Failed to determine serial baud rate selection!" );
  989. DNASSERT( FALSE );
  990. goto Failure;
  991. break;
  992. }
  993. default:
  994. {
  995. LRESULT lItemData;
  996. HRESULT hTempResult;
  997. DNASSERT( hr == DPN_OK );
  998. lItemData = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_BAUDRATE ), CB_GETITEMDATA, lSelection, 0 );
  999. if ( lItemData == CB_ERR )
  1000. {
  1001. hr = DPNERR_GENERIC;
  1002. DPFX(DPFPREP, 0, "Failed to get associated baudrate data!" );
  1003. DNASSERT( FALSE );
  1004. goto Failure;
  1005. }
  1006. DNASSERT( lItemData <= UINT32_MAX );
  1007. hTempResult = pComEndpoint->SetBaudRate( static_cast<DWORD>( lItemData ) );
  1008. DNASSERT( hTempResult == DPN_OK );
  1009. break;
  1010. }
  1011. }
  1012. //
  1013. // get stop bits
  1014. //
  1015. lSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_STOPBITS ), CB_GETCURSEL, 0, 0 );
  1016. switch ( lSelection )
  1017. {
  1018. case CB_ERR:
  1019. {
  1020. hr = DPNERR_GENERIC;
  1021. DPFX(DPFPREP, 0, "Failed to determine serial stop bits selection!" );
  1022. DNASSERT( FALSE );
  1023. goto Failure;
  1024. break;
  1025. }
  1026. default:
  1027. {
  1028. LRESULT lItemData;
  1029. HRESULT hTempResult;
  1030. lItemData = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_STOPBITS ), CB_GETITEMDATA, lSelection, 0 );
  1031. if ( lItemData == CB_ERR )
  1032. {
  1033. hr = DPNERR_GENERIC;
  1034. DPFX(DPFPREP, 0, "Failed to get associated stop bits data!" );
  1035. goto Failure;
  1036. }
  1037. DNASSERT( hr == DPN_OK );
  1038. DNASSERT( lItemData <= UINT32_MAX );
  1039. hTempResult = pComEndpoint->SetStopBits( static_cast<DWORD>( lItemData ) );
  1040. DNASSERT( hTempResult == DPN_OK );
  1041. break;
  1042. }
  1043. }
  1044. //
  1045. // get parity
  1046. //
  1047. lSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_PARITY ), CB_GETCURSEL, 0, 0 );
  1048. switch ( lSelection )
  1049. {
  1050. case CB_ERR:
  1051. {
  1052. hr = DPNERR_GENERIC;
  1053. DPFX(DPFPREP, 0, "Failed to determine serial parity selection!" );
  1054. DNASSERT( FALSE );
  1055. goto Failure;
  1056. break;
  1057. }
  1058. default:
  1059. {
  1060. LRESULT lItemData;
  1061. HRESULT hTempResult;
  1062. lItemData = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_PARITY ), CB_GETITEMDATA, lSelection, 0 );
  1063. if ( lItemData == CB_ERR )
  1064. {
  1065. hr = DPNERR_GENERIC;
  1066. DPFX(DPFPREP, 0, "Failed to get associated parity data!" );
  1067. goto Failure;
  1068. }
  1069. DNASSERT( hr == DPN_OK );
  1070. DNASSERT( lItemData <= UINT32_MAX );
  1071. hTempResult = pComEndpoint->SetParity( static_cast<DWORD>( lItemData ) );
  1072. DNASSERT( hTempResult == DPN_OK );
  1073. break;
  1074. }
  1075. }
  1076. //
  1077. // get flow control
  1078. //
  1079. lSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_FLOWCONTROL ), CB_GETCURSEL, 0, 0 );
  1080. switch ( lSelection )
  1081. {
  1082. case CB_ERR:
  1083. {
  1084. hr = DPNERR_GENERIC;
  1085. DPFX(DPFPREP, 0, "Failed to determine serial flow control selection!" );
  1086. DNASSERT( FALSE );
  1087. goto Failure;
  1088. break;
  1089. }
  1090. default:
  1091. {
  1092. LRESULT lItemData;
  1093. HRESULT hTempResult;
  1094. lItemData = SendMessage( GetDlgItem( hDlg, IDC_COMBO_SERIAL_FLOWCONTROL ), CB_GETITEMDATA, lSelection, 0 );
  1095. if ( lItemData == CB_ERR )
  1096. {
  1097. hr = DPNERR_GENERIC;
  1098. DPFX(DPFPREP, 0, "Failed to get associated flow control data!" );
  1099. goto Failure;
  1100. }
  1101. DNASSERT( hr == DPN_OK );
  1102. hTempResult = pComEndpoint->SetFlowControl( static_cast<SP_FLOW_CONTROL>( lItemData ) );
  1103. DNASSERT( hTempResult == DPN_OK );
  1104. break;
  1105. }
  1106. }
  1107. Exit:
  1108. return hr;
  1109. Failure:
  1110. goto Exit;
  1111. }
  1112. //**********************************************************************