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.

428 lines
11 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: AddDone.cpp $
  4. *
  5. * Copyright (C) 1997 Hewlett-Packard Company.
  6. * Copyright (c) 1997 Microsoft Corporation.
  7. * All rights reserved.
  8. *
  9. * 11311 Chinden Blvd.
  10. * Boise, Idaho 83714
  11. *
  12. *****************************************************************************/
  13. /*
  14. * Author: Becky Jacobsen
  15. */
  16. #include "precomp.h"
  17. #include "UIMgr.h"
  18. #include "AddDone.h"
  19. #include "Resource.h"
  20. #include "TCPMonUI.h"
  21. //
  22. // FUNCTION: CSummaryDlg constructor
  23. //
  24. // PURPOSE: initialize a CSummaryDlg class
  25. //
  26. CSummaryDlg::CSummaryDlg()
  27. {
  28. } // constructor
  29. //
  30. // FUNCTION: CSummaryDlg destructor
  31. //
  32. // PURPOSE: deinitialize a CSummaryDlg class
  33. //
  34. CSummaryDlg::~CSummaryDlg()
  35. {
  36. } // destructor
  37. //
  38. // FUNCTION: SummaryDialog(HWND, UINT, WPARAM, LPARAM)
  39. //
  40. // PURPOSE: To process messages from the summary dialog for adding a port.
  41. //
  42. // MESSAGES:
  43. //
  44. // WM_INITDIALOG - intializes the page
  45. // WM_COMMAND - handles button presses and text changes in edit controls.
  46. //
  47. //
  48. INT_PTR CALLBACK SummaryDialog(
  49. HWND hDlg,
  50. UINT message,
  51. WPARAM wParam,
  52. LPARAM lParam)
  53. {
  54. CSummaryDlg *wndDlg = NULL;
  55. wndDlg = (CSummaryDlg *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  56. switch (message) {
  57. case WM_INITDIALOG:
  58. wndDlg = new CSummaryDlg;
  59. if( wndDlg == NULL )
  60. return FALSE;
  61. //
  62. // If the function succeeds, the return value is the previous value of the specified offset.
  63. //
  64. // If the function fails, the return value is zero. To get extended error
  65. // information, call GetLastError.
  66. //
  67. // If the previous value is zero and the function succeeds, the return value is zero,
  68. // but the function does not clear the last error information. To determine success or failure,
  69. // clear the last error information by calling SetLastError(0), then call SetWindowLongPtr.
  70. // Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero.
  71. //
  72. SetLastError (0);
  73. if (!SetWindowLongPtr(hDlg, GWLP_USERDATA, (UINT_PTR)wndDlg) && GetLastError()) {
  74. delete wndDlg;
  75. return FALSE;
  76. }
  77. else
  78. return wndDlg->OnInitDialog(hDlg, wParam, lParam);
  79. break;
  80. case WM_NOTIFY:
  81. return wndDlg->OnNotify(hDlg, wParam, lParam);
  82. break;
  83. case WM_DESTROY:
  84. if (wndDlg)
  85. delete wndDlg;
  86. break;
  87. default:
  88. return FALSE;
  89. }
  90. return TRUE;
  91. } // AddPortDialog
  92. //
  93. // FUNCTION: OnInitDialog(HWND hDlg)
  94. //
  95. // PURPOSE: Initialize the dialog.
  96. //
  97. BOOL CSummaryDlg::OnInitDialog(HWND hDlg, WPARAM, LPARAM lParam)
  98. {
  99. m_pParams = (ADD_PARAM_PACKAGE *) ((PROPSHEETPAGE *) lParam)->lParam;
  100. FillTextFields(hDlg);
  101. m_pParams->UIManager->SetControlFont(hDlg, IDC_TITLE);
  102. return TRUE;
  103. } // OnInitDialog
  104. //
  105. // Function: FillTextFields()
  106. //
  107. // Purpose: To load strings and set the text for all the output fields
  108. // on the Summary page.
  109. //
  110. void CSummaryDlg::FillTextFields(HWND hDlg)
  111. {
  112. TCHAR ptcsYesNo[MAX_YESNO_SIZE] = NULLSTR;
  113. TCHAR ptcsProtocolAndPortNum[MAX_PROTOCOL_AND_PORTNUM_SIZE] = NULLSTR;
  114. // Fill in the protocol field
  115. TCHAR ptcsProtocol[MAX_PROTOCOL_AND_PORTNUM_SIZE] = NULLSTR;
  116. TCHAR ptcsPort[MAX_PROTOCOL_AND_PORTNUM_SIZE] = NULLSTR;
  117. if(m_pParams->pData->dwProtocol == PROTOCOL_RAWTCP_TYPE) {
  118. LoadString(g_hInstance,
  119. IDS_STRING_RAW,
  120. ptcsProtocol,
  121. MAX_PROTOCOL_AND_PORTNUM_SIZE);
  122. LoadString(g_hInstance,
  123. IDS_STRING_PORT,
  124. ptcsPort,
  125. MAX_PROTOCOL_AND_PORTNUM_SIZE);
  126. StringCchPrintf (ptcsProtocolAndPortNum, COUNTOF (ptcsProtocolAndPortNum),
  127. TEXT("%s, %s %d"),
  128. ptcsProtocol,
  129. ptcsPort,
  130. m_pParams->pData->dwPortNumber);
  131. } else {
  132. if(m_pParams->pData->dwProtocol == PROTOCOL_LPR_TYPE) {
  133. LoadString(g_hInstance,
  134. IDS_STRING_LPR,
  135. ptcsProtocol,
  136. MAX_PROTOCOL_AND_PORTNUM_SIZE);
  137. StringCchPrintf (ptcsProtocolAndPortNum, COUNTOF (ptcsProtocolAndPortNum),
  138. TEXT("%s, %s"),
  139. ptcsProtocol,
  140. m_pParams->pData->sztQueue);
  141. }
  142. }
  143. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_PROTOCOL_AND_PORTNUM),
  144. ptcsProtocolAndPortNum);
  145. // Fill in the SNMP Field
  146. if(m_pParams->pData->dwSNMPEnabled != FALSE) {
  147. LoadString(g_hInstance, IDS_STRING_YES, ptcsYesNo, MAX_YESNO_SIZE);
  148. } else {
  149. LoadString(g_hInstance, IDS_STRING_NO, ptcsYesNo, MAX_YESNO_SIZE);
  150. }
  151. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_SNMP_YESNO), ptcsYesNo);
  152. // Fill in the Address field:
  153. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_ADDRESS), m_pParams->pData->sztHostAddress);
  154. // Fill in the PortName field
  155. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_PORTNAME), m_pParams->pData->sztPortName);
  156. // Fill in the Detected type
  157. SetWindowText(GetDlgItem( hDlg, IDC_EDIT_SYSTEMID), m_pParams->sztPortDesc);
  158. } // FillTextFields
  159. //
  160. // FUNCTION: OnNotify()
  161. //
  162. // PURPOSE: Process WM_NOTIFY message
  163. //
  164. BOOL CSummaryDlg::OnNotify(HWND hDlg, WPARAM wParam, LPARAM lParam)
  165. {
  166. switch (((NMHDR FAR *) lParam)->code) {
  167. case PSN_KILLACTIVE:
  168. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  169. break;
  170. case PSN_RESET:
  171. // reset to the original values
  172. #ifdef _WIN64
  173. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  174. #else
  175. SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
  176. #endif
  177. break;
  178. case PSN_SETACTIVE:
  179. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_FINISH);
  180. FillTextFields(hDlg);
  181. PostMessage(GetDlgItem(hDlg, IDC_EDIT_SNMP_YESNO), EM_SETSEL,0,0);
  182. return FALSE;
  183. break;
  184. case PSN_WIZBACK:
  185. // To jump to a page other than the previous or next one,
  186. // an application should set DWL_MSGRESULT to the identifier
  187. // of the dialog box to be displayed.
  188. if(m_pParams->dwDeviceType == SUCCESS_DEVICE_SINGLE_PORT) {
  189. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_ADDPORT);
  190. } else if (m_pParams->bMultiPort == FALSE ) {
  191. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_MORE_INFO);
  192. }
  193. break;
  194. case PSN_WIZFINISH:
  195. OnFinish();
  196. break;
  197. case PSN_QUERYCANCEL:
  198. m_pParams->dwLastError = ERROR_CANCELLED;
  199. return FALSE;
  200. break;
  201. default:
  202. return FALSE;
  203. }
  204. return TRUE;
  205. } // OnNotify
  206. //
  207. // FUNCTION: OnFinish()
  208. //
  209. // PURPOSE: Create the Port
  210. //
  211. BOOL CSummaryDlg::OnFinish()
  212. {
  213. HCURSOR hOldCursor = NULL;
  214. HCURSOR hNewCursor = NULL;
  215. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  216. if ( hNewCursor ) {
  217. hOldCursor = SetCursor(hNewCursor);
  218. }
  219. if ( m_pParams->hXcvPrinter != NULL ) {
  220. RemoteTellPortMonToCreateThePort();
  221. } else {
  222. LocalTellPortMonToCreateThePort();
  223. }
  224. //
  225. // Make sure the port name is returned to the calling module.
  226. //
  227. lstrcpyn(m_pParams->sztPortName,
  228. m_pParams->pData->sztPortName,
  229. MAX_PORTNAME_LEN);
  230. //
  231. // Change the cursor back from an hour glass.
  232. //
  233. if ( hNewCursor ) {
  234. SetCursor(hOldCursor);
  235. }
  236. return TRUE;
  237. } // OnFinish
  238. //
  239. // FUNCTION: RemoteTellPortMonToCreateThePort
  240. //
  241. // PURPOSE: Loads winspool.dll and calls XcvData
  242. //
  243. DWORD CSummaryDlg::RemoteTellPortMonToCreateThePort()
  244. {
  245. DWORD dwReturn = NO_ERROR;
  246. HINSTANCE hLib = NULL;
  247. XCVDATAPARAM pfnXcvData = NULL;
  248. HCURSOR hOldCursor = NULL;
  249. HCURSOR hNewCursor = NULL;
  250. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  251. if ( hNewCursor ) {
  252. hOldCursor = SetCursor(hNewCursor);
  253. }
  254. //
  255. // load & assign the function pointer
  256. //
  257. hLib = ::LoadLibrary(TEXT("WinSpool.drv"));
  258. if( hLib != NULL ) {
  259. //
  260. // initialize the library
  261. //
  262. pfnXcvData = (XCVDATAPARAM)::GetProcAddress(hLib, "XcvDataW");
  263. if ( pfnXcvData != NULL ) {
  264. DWORD dwOutputNeeded = 0;
  265. DWORD dwStatus = NO_ERROR;
  266. //
  267. // here's the call we've all been waiting for:
  268. //
  269. DWORD dwRet = (*pfnXcvData)(m_pParams->hXcvPrinter,
  270. (PCWSTR)TEXT("AddPort"),
  271. (PBYTE)(m_pParams->pData),
  272. m_pParams->pData->cbSize,
  273. NULL,
  274. 0,
  275. &dwOutputNeeded,
  276. &dwStatus);
  277. if ( !dwRet ) {
  278. dwReturn = GetLastError();
  279. DisplayErrorMessage(NULL, dwReturn);
  280. } else {
  281. if ( dwStatus != NO_ERROR )
  282. DisplayErrorMessage(NULL, dwStatus);
  283. }
  284. } else {
  285. dwReturn = ERROR_DLL_NOT_FOUND;
  286. }
  287. } else {
  288. dwReturn = ERROR_DLL_NOT_FOUND;
  289. }
  290. //
  291. // --- Cleanup ---
  292. //
  293. if ( hLib )
  294. FreeLibrary(hLib);
  295. if ( hNewCursor )
  296. SetCursor(hOldCursor);
  297. return(dwReturn);
  298. } // RemoteTellPortMonToCreateThePort
  299. //
  300. // FUNCTION: TellPortMonToCreateThePort
  301. //
  302. // Purpose: To load the port monitor dll and call AddPortUIEx
  303. //
  304. // Return Value:
  305. //
  306. DWORD CSummaryDlg::LocalTellPortMonToCreateThePort()
  307. {
  308. DWORD dwReturn = NO_ERROR;
  309. UIEXPARAM pfnAddPortUIEx = NULL;
  310. HCURSOR hOldCursor = NULL;
  311. HCURSOR hNewCursor = NULL;
  312. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  313. if ( hNewCursor )
  314. hOldCursor = SetCursor(hNewCursor);
  315. //
  316. // load & assign the function pointer
  317. //
  318. if ( g_hPortMonLib != NULL) {
  319. //
  320. // initialize the library
  321. //
  322. pfnAddPortUIEx = (UIEXPARAM)::GetProcAddress(g_hPortMonLib,
  323. "AddPortUIEx");
  324. if ( pfnAddPortUIEx != NULL ) {
  325. //
  326. // here's the call we've all been waiting for:
  327. //
  328. BOOL bReturn = (*pfnAddPortUIEx)(m_pParams->pData);
  329. if(bReturn == FALSE) {
  330. dwReturn = GetLastError();
  331. DisplayErrorMessage(NULL, dwReturn);
  332. }
  333. } else {
  334. dwReturn = ERROR_DLL_NOT_FOUND;
  335. }
  336. } else {
  337. dwReturn = ERROR_DLL_NOT_FOUND;
  338. }
  339. //
  340. // Cleanup
  341. //
  342. if ( hNewCursor )
  343. SetCursor(hOldCursor);
  344. return dwReturn;
  345. } // LocalTellPortMonToCreateThePort