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.

1349 lines
52 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. faxvrfy.c
  5. Abstract:
  6. This module verifies the minimal functionality of the Windows NT Fax Service.
  7. Author:
  8. Steven Kehrli (steveke) 11/15/1997
  9. --*/
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include <commctrl.h>
  13. #include <shellapi.h>
  14. #include <winfax.h>
  15. #include "faxrcv.h"
  16. #include "faxvrfy.h"
  17. #include "macros.h"
  18. #include "macros.c"
  19. #include "resource.h"
  20. #include "startup.c"
  21. #include "util.c"
  22. #include "events.c"
  23. #include "sndthrd.c"
  24. // fnDialogProcSetup is the Setup Dialog Procedure
  25. LRESULT CALLBACK fnDialogProcSetup (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
  26. VOID
  27. fnUsageInfo(
  28. HWND hWnd
  29. )
  30. /*++
  31. Routine Description:
  32. Displays the usage info
  33. Return Value:
  34. None
  35. --*/
  36. {
  37. // szHelpFile is the name of the help file
  38. WCHAR szHelpFile[MAX_PATH];
  39. DWORD cb;
  40. GetCurrentDirectory(sizeof(szHelpFile) / sizeof(WCHAR), szHelpFile);
  41. lstrcat(szHelpFile, L"\\");
  42. lstrcat(szHelpFile, FAXVRFY_HLP);
  43. WinHelp(hWnd, szHelpFile, HELP_FINDER, 0);
  44. }
  45. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  46. {
  47. WNDCLASSEX wndclass;
  48. MSG msg;
  49. // hMutex is the handle to the mutex
  50. HANDLE hMutex;
  51. // argvW are the command line parameters
  52. LPWSTR *argvW;
  53. // argc is the count of command line parameters
  54. INT argc;
  55. INT iIndex;
  56. // pFaxPortsConfigLocal is a pointer to the Fax Ports Configuration
  57. PFAX_PORT_INFO pFaxPortsConfigLocal;
  58. // pFaxSvcConfigLocal is a pointer to the fax service configuration
  59. PFAX_CONFIGURATION pFaxSvcConfigLocal;
  60. // hFaxPortHandle is the handle to a port
  61. HANDLE hFaxPortHandle;
  62. DWORD dwIndex;
  63. UINT uRslt;
  64. // hFaxDevicesKey is the handle to the fax devices registry key
  65. HKEY hFaxDevicesKey;
  66. // hFaxPortKey is the handle to the fax port registry key
  67. HKEY hFaxPortKey;
  68. // szFaxPortKey is the name of the fax port registry key
  69. TCHAR szFaxPortKey[15];
  70. // szFixModemClass is the modem class of the fax port
  71. LPWSTR szFixModemClass;
  72. DWORD cb;
  73. // szText is a text string
  74. WCHAR szText[MAX_STRINGLEN + 2];
  75. // Set g_hInstance
  76. g_hInstance = hInstance;
  77. // Initialize the wndclass
  78. wndclass.cbSize = sizeof(wndclass);
  79. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  80. wndclass.lpfnWndProc = fnDialogProcSetup;
  81. wndclass.cbClsExtra = 0;
  82. wndclass.cbWndExtra = DLGWINDOWEXTRA;
  83. wndclass.hInstance = g_hInstance;
  84. wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  85. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  86. wndclass.hbrBackground = (HBRUSH) (COLOR_INACTIVEBORDER + 1);
  87. wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
  88. wndclass.lpszClassName = FAXVRFY_NAME;
  89. wndclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
  90. // See if FaxVrfy is already running
  91. hMutex = CreateMutex(NULL, FALSE, FAXVRFY_NAME);
  92. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  93. while (TRUE) {
  94. // Wait for access to the mutex
  95. WaitForSingleObject(hMutex, INFINITE);
  96. // Find the window
  97. g_hWndDlg = FindWindow(FAXVRFY_NAME, NULL);
  98. if (g_hWndDlg) {
  99. // Switch to that window
  100. ShowWindow(g_hWndDlg, SW_RESTORE);
  101. SetForegroundWindow(g_hWndDlg);
  102. // Release access to the mutex
  103. ReleaseMutex(hMutex);
  104. return 0;
  105. }
  106. // Release access to the mutex
  107. ReleaseMutex(hMutex);
  108. // See if FaxVrfy is still running
  109. CloseHandle(hMutex);
  110. hMutex = CreateMutex(NULL, FALSE, FAXVRFY_NAME);
  111. if (GetLastError() == ERROR_SUCCESS) {
  112. break;
  113. }
  114. }
  115. }
  116. // Initialize the local mem
  117. MemInitializeMacro();
  118. // Set the default caption
  119. SetDefaultCaptionMacro(FAXVRFY_NAME);
  120. // Initialize the common controls
  121. InitCommonControls();
  122. argvW = CommandLineToArgvW(GetCommandLine(), &argc);
  123. for (iIndex = 0; iIndex < argc; iIndex++) {
  124. if ((!lstrcmpi(FAXVRFY_CMD_HELP_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_HELP_2, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_HELP_3, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_HELP_4, argvW[iIndex]))) {
  125. fnUsageInfo(NULL);
  126. return 0;
  127. }
  128. else if ((!lstrcmpi(FAXVRFY_CMD_BVT_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_BVT_2, argvW[iIndex]))) {
  129. g_bBVT = TRUE;
  130. g_bGo = FALSE;
  131. g_bNoCheck = FALSE;
  132. g_bRasAvailable = FALSE;
  133. }
  134. else if ((!lstrcmpi(FAXVRFY_CMD_SEND_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_SEND_2, argvW[iIndex]))) {
  135. g_bSend = TRUE;
  136. }
  137. else if ((!lstrcmpi(FAXVRFY_CMD_RECEIVE_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_RECEIVE_2, argvW[iIndex]))) {
  138. g_bSend = FALSE;
  139. }
  140. else if ((!g_bBVT) && ((!lstrcmpi(FAXVRFY_CMD_GO_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_GO_2, argvW[iIndex])))) {
  141. g_bGo = TRUE;
  142. }
  143. else if ((!g_bBVT) && ((!lstrcmpi(FAXVRFY_CMD_NO_CHECK_1, argvW[iIndex])) || (!lstrcmpi(FAXVRFY_CMD_NO_CHECK_2, argvW[iIndex])))) {
  144. g_bNoCheck = TRUE;
  145. }
  146. }
  147. MemFreeMacro(argvW);
  148. // Initialize NTLog
  149. g_bNTLogAvailable = fnInitializeNTLog();
  150. // Start the log file
  151. fnStartLogFile();
  152. // Verify fax is installed
  153. uRslt = fnIsFaxInstalled();
  154. if (uRslt) {
  155. if (!g_bBVT) {
  156. MessageBoxMacro(NULL, uRslt, MB_ICONERROR);
  157. }
  158. g_bTestFailed = TRUE;
  159. LoadString(g_hInstance, uRslt, szText, MAX_STRINGLEN);
  160. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  161. if (g_bNTLogAvailable) {
  162. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  163. }
  164. goto ExitLevel0;
  165. }
  166. // Verify com objects are installed
  167. uRslt = fnIsComInstalled();
  168. if (uRslt) {
  169. if (!g_bBVT) {
  170. MessageBoxMacro(NULL, uRslt, MB_ICONERROR);
  171. }
  172. g_bTestFailed = TRUE;
  173. LoadString(g_hInstance, uRslt, szText, MAX_STRINGLEN);
  174. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  175. if (g_bNTLogAvailable) {
  176. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  177. }
  178. goto ExitLevel0;
  179. }
  180. // Initialize FaxRcv
  181. uRslt = fnInitializeFaxRcv();
  182. if (uRslt) {
  183. if (!g_bBVT) {
  184. MessageBoxMacro(NULL, uRslt, MB_ICONERROR);
  185. }
  186. g_bTestFailed = TRUE;
  187. LoadString(g_hInstance, uRslt, szText, MAX_STRINGLEN);
  188. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  189. if (g_bNTLogAvailable) {
  190. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  191. }
  192. goto ExitLevel0;
  193. }
  194. if (!g_bBVT) {
  195. g_bRasAvailable = fnInitializeRas();
  196. }
  197. // Create the Start event
  198. g_hStartEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  199. // Create the Stop event
  200. g_hStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  201. // Create the Exit event
  202. g_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  203. // Create the Fax event
  204. g_hFaxEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  205. // Create the RAS Passed event
  206. g_hRasPassedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  207. // Create the RAS Failed event
  208. g_hRasFailedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  209. // Create the Send Passed event
  210. g_hSendPassedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  211. // Create the Send Failed event
  212. g_hSendFailedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  213. // Connect to the Fax Service
  214. if (!FaxConnectFaxServer(NULL, &g_hFaxSvcHandle)) {
  215. if (!g_bBVT) {
  216. MessageBoxMacro(NULL, IDS_FAX_CONNECT_FAILED, MB_ICONERROR);
  217. }
  218. g_bTestFailed = TRUE;
  219. LoadString(g_hInstance, IDS_FAX_CONNECT_FAILED, szText, MAX_STRINGLEN);
  220. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  221. if (g_bNTLogAvailable) {
  222. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  223. }
  224. goto ExitLevel1;
  225. }
  226. // Get the Fax Ports Configuration
  227. if (!FaxEnumPorts(g_hFaxSvcHandle, &g_pFaxPortsConfig, &g_dwNumPorts)) {
  228. if (!g_bBVT) {
  229. MessageBoxMacro(NULL, IDS_FAX_ENUM_PORTS_FAILED, MB_ICONERROR);
  230. }
  231. g_bTestFailed = TRUE;
  232. LoadString(g_hInstance, IDS_FAX_ENUM_PORTS_FAILED, szText, MAX_STRINGLEN);
  233. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  234. if (g_bNTLogAvailable) {
  235. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  236. }
  237. goto ExitLevel2;
  238. }
  239. if (!g_dwNumPorts) {
  240. if (!g_bBVT) {
  241. MessageBoxMacro(NULL, IDS_FAX_PORTS_NOT_INSTALLED, MB_ICONERROR);
  242. }
  243. g_bTestFailed = TRUE;
  244. LoadString(g_hInstance, IDS_FAX_PORTS_NOT_INSTALLED, szText, MAX_STRINGLEN);
  245. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  246. if (g_bNTLogAvailable) {
  247. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  248. }
  249. goto ExitLevel3;
  250. }
  251. g_dwNumAvailPorts = g_dwNumPorts;
  252. // Get the Fax Ports Configuration
  253. if (!FaxEnumPorts(g_hFaxSvcHandle, &pFaxPortsConfigLocal, &g_dwNumPorts)) {
  254. if (!g_bBVT) {
  255. MessageBoxMacro(NULL, IDS_FAX_ENUM_PORTS_FAILED, MB_ICONERROR);
  256. }
  257. g_bTestFailed = TRUE;
  258. LoadString(g_hInstance, IDS_FAX_ENUM_PORTS_FAILED, szText, MAX_STRINGLEN);
  259. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  260. if (g_bNTLogAvailable) {
  261. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  262. }
  263. goto ExitLevel3;
  264. }
  265. // Set the Fax Ports Configuration
  266. for (dwIndex = 0; dwIndex < g_dwNumPorts; dwIndex++) {
  267. pFaxPortsConfigLocal[dwIndex].Flags = FPF_RECEIVE | FPF_SEND;
  268. if (!FaxOpenPort(g_hFaxSvcHandle, pFaxPortsConfigLocal[dwIndex].DeviceId, PORT_OPEN_MODIFY, &hFaxPortHandle)) {
  269. if (!g_bBVT) {
  270. MessageBoxMacro(NULL, IDS_FAX_SET_PORT_FAILED, MB_ICONERROR, pFaxPortsConfigLocal[dwIndex].DeviceName);
  271. }
  272. g_bTestFailed = TRUE;
  273. LoadString(g_hInstance, IDS_FAX_SET_PORT_FAILED, szText, MAX_STRINGLEN);
  274. lstrcat(szText, L"\r\n");
  275. fnWriteLogFile(TRUE, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  276. if (g_bNTLogAvailable) {
  277. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  278. }
  279. // Free the Fax Ports Configuration
  280. FaxFreeBuffer(pFaxPortsConfigLocal);
  281. goto ExitLevel4;
  282. }
  283. if (!FaxSetPort(hFaxPortHandle, (PFAX_PORT_INFO) &pFaxPortsConfigLocal[dwIndex])) {
  284. FaxClose(hFaxPortHandle);
  285. if (!g_bBVT) {
  286. MessageBoxMacro(NULL, IDS_FAX_SET_PORT_FAILED, MB_ICONERROR, pFaxPortsConfigLocal[dwIndex].DeviceName);
  287. }
  288. g_bTestFailed = TRUE;
  289. LoadString(g_hInstance, IDS_FAX_SET_PORT_FAILED, szText, MAX_STRINGLEN);
  290. lstrcat(szText, L"\r\n");
  291. fnWriteLogFile(TRUE, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  292. if (g_bNTLogAvailable) {
  293. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  294. }
  295. // Free the Fax Ports Configuration
  296. FaxFreeBuffer(pFaxPortsConfigLocal);
  297. goto ExitLevel4;
  298. }
  299. FaxClose(hFaxPortHandle);
  300. }
  301. // Free the Fax Ports Configuration
  302. FaxFreeBuffer(pFaxPortsConfigLocal);
  303. // Get the modem fax class
  304. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, FAXDEVICES_REGKEY, 0, KEY_ALL_ACCESS, &hFaxDevicesKey)) {
  305. if (!g_bBVT) {
  306. MessageBoxMacro(NULL, IDS_OPEN_FAXDEVICES_REGKEY_FAILED, MB_ICONERROR);
  307. }
  308. g_bTestFailed = TRUE;
  309. LoadString(g_hInstance, IDS_OPEN_FAXDEVICES_REGKEY_FAILED, szText, MAX_STRINGLEN);
  310. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  311. if (g_bNTLogAvailable) {
  312. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  313. }
  314. goto ExitLevel4;
  315. }
  316. for (dwIndex = 0; dwIndex < g_dwNumPorts; dwIndex++) {
  317. // Initialize the string representation of the DeviceId
  318. ZeroMemory(szFaxPortKey, sizeof(szFaxPortKey));
  319. // Set the string representation of the DeviceId
  320. wsprintf(szFaxPortKey, L"%08u", g_pFaxPortsConfig[dwIndex].DeviceId);
  321. lstrcat(szFaxPortKey, MODEM_REGKEY);
  322. szFixModemClass = NULL;
  323. if (!RegOpenKeyEx(hFaxDevicesKey, szFaxPortKey, 0, KEY_ALL_ACCESS, &hFaxPortKey)) {
  324. if (!RegQueryValueEx(hFaxPortKey, FIXMODEMCLASS_REGVALUE, NULL, NULL, NULL, &cb)) {
  325. if (cb) {
  326. szFixModemClass = MemAllocMacro(cb);
  327. if (RegQueryValueEx(hFaxPortKey, FIXMODEMCLASS_REGVALUE, NULL, NULL, (PBYTE) szFixModemClass, &cb)) {
  328. MemFreeMacro(szFixModemClass);
  329. szFixModemClass = NULL;
  330. }
  331. else if (!lstrcmp(L"", szFixModemClass)) {
  332. MemFreeMacro(szFixModemClass);
  333. szFixModemClass = NULL;
  334. }
  335. }
  336. }
  337. RegCloseKey(hFaxPortKey);
  338. }
  339. if (!szFixModemClass) {
  340. szFixModemClass = MemAllocMacro(2 * sizeof(WCHAR));
  341. lstrcpy(szFixModemClass, L"1");
  342. }
  343. LoadString(g_hInstance, IDS_FIXMODEMCLASS_DATA, szText, MAX_STRINGLEN);
  344. lstrcat(szText, L"\r\n");
  345. fnWriteLogFile(TRUE, szText, g_pFaxPortsConfig[dwIndex].DeviceName, szFixModemClass);
  346. if (g_bNTLogAvailable) {
  347. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, szText, g_pFaxPortsConfig[dwIndex].DeviceName, szFixModemClass);
  348. }
  349. MemFreeMacro(szFixModemClass);
  350. }
  351. RegCloseKey(hFaxDevicesKey);
  352. fnWriteLogFile(FALSE, L"\r\n");
  353. if (g_bNTLogAvailable) {
  354. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"\r\n");
  355. }
  356. // Get the Fax Service Configuration
  357. if (!FaxGetConfiguration(g_hFaxSvcHandle, &g_pFaxSvcConfig)) {
  358. if (!g_bBVT) {
  359. MessageBoxMacro(NULL, IDS_FAX_GET_CONFIG_FAILED, MB_ICONERROR);
  360. }
  361. g_bTestFailed = TRUE;
  362. LoadString(g_hInstance, IDS_FAX_GET_CONFIG_FAILED, szText, MAX_STRINGLEN);
  363. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  364. if (g_bNTLogAvailable) {
  365. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  366. }
  367. goto ExitLevel4;
  368. }
  369. // Get the Fax Service Configuration
  370. if (!FaxGetConfiguration(g_hFaxSvcHandle, &pFaxSvcConfigLocal)) {
  371. if (!g_bBVT) {
  372. MessageBoxMacro(NULL, IDS_FAX_GET_CONFIG_FAILED, MB_ICONERROR);
  373. }
  374. g_bTestFailed = TRUE;
  375. LoadString(g_hInstance, IDS_FAX_GET_CONFIG_FAILED, szText, MAX_STRINGLEN);
  376. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  377. if (g_bNTLogAvailable) {
  378. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  379. }
  380. goto ExitLevel5;
  381. }
  382. // Set the Fax Service Configuration
  383. pFaxSvcConfigLocal->Retries = FAXSVC_RETRIES;
  384. pFaxSvcConfigLocal->RetryDelay = FAXSVC_RETRYDELAY;
  385. pFaxSvcConfigLocal->UseDeviceTsid = FALSE;
  386. if (!FaxSetConfiguration(g_hFaxSvcHandle, pFaxSvcConfigLocal)) {
  387. if (!g_bBVT) {
  388. MessageBoxMacro(NULL, IDS_FAX_SET_CONFIG_FAILED, MB_ICONERROR);
  389. }
  390. g_bTestFailed = TRUE;
  391. LoadString(g_hInstance, IDS_FAX_SET_CONFIG_FAILED, szText, MAX_STRINGLEN);
  392. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  393. if (g_bNTLogAvailable) {
  394. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  395. }
  396. // Free the Fax Service Configuration
  397. FaxFreeBuffer(pFaxSvcConfigLocal);
  398. goto ExitLevel5;
  399. }
  400. // Free the Fax Service Configuration
  401. FaxFreeBuffer(pFaxSvcConfigLocal);
  402. // Create the completion port
  403. g_hCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
  404. // Initialize the Fax Event Queue
  405. if (!FaxInitializeEventQueue(g_hFaxSvcHandle, g_hCompletionPort, 0, NULL, 0)) {
  406. if (!g_bBVT) {
  407. MessageBoxMacro(NULL, IDS_FAX_EVENT_QUEUE_FAILED, MB_ICONERROR);
  408. }
  409. g_bTestFailed = TRUE;
  410. LoadString(g_hInstance, IDS_FAX_EVENT_QUEUE_FAILED, szText, MAX_STRINGLEN);
  411. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  412. if (g_bNTLogAvailable) {
  413. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  414. }
  415. goto ExitLevel6;
  416. }
  417. // Create the Fax Event Queue thread
  418. CreateThread(NULL, 0, fnFaxEventQueueProc, NULL, 0, NULL);
  419. // Create the Send thread
  420. CreateThread(NULL, 0, fnSendProc, NULL, 0, NULL);
  421. if (g_bBVT) {
  422. wndclass.lpszMenuName = NULL;
  423. }
  424. RegisterClassEx(&wndclass);
  425. // Create the Setup Dialog
  426. g_hWndDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_SETUP), NULL, NULL);
  427. SendMessage(g_hWndDlg, UM_FAXVRFY_INITIALIZE, 0, 0);
  428. ShowWindow(g_hWndDlg, iCmdShow);
  429. UpdateWindow(g_hWndDlg);
  430. if ((g_bBVT) || (g_bGo)) {
  431. PostMessage(GetDlgItem(g_hWndDlg, IDC_START_BUTTON), BM_CLICK, 0, 0);
  432. }
  433. while (GetMessage(&msg, NULL, 0, 0)) {
  434. if (!IsDialogMessage(g_hWndDlg, &msg)) {
  435. TranslateMessage(&msg);
  436. DispatchMessage(&msg);
  437. }
  438. }
  439. ExitLevel6:
  440. if (g_hCompletionPort) {
  441. CloseHandle(g_hCompletionPort);
  442. }
  443. // Restore the Fax Service Configuration
  444. if (!FaxSetConfiguration(g_hFaxSvcHandle, g_pFaxSvcConfig)) {
  445. if (!g_bBVT) {
  446. MessageBoxMacro(NULL, IDS_FAX_RESTORE_CONFIG_FAILED, MB_ICONERROR);
  447. }
  448. g_bTestFailed = TRUE;
  449. LoadString(g_hInstance, IDS_FAX_RESTORE_CONFIG_FAILED, szText, MAX_STRINGLEN);
  450. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  451. if (g_bNTLogAvailable) {
  452. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, L"%s\r\n", szText);
  453. }
  454. }
  455. ExitLevel5:
  456. // Free the Fax Service Configuration
  457. FaxFreeBuffer(g_pFaxSvcConfig);
  458. ExitLevel4:
  459. // Restore the Fax Ports Configuration
  460. for (dwIndex = 0; dwIndex < g_dwNumPorts; dwIndex++) {
  461. if (!FaxOpenPort(g_hFaxSvcHandle, g_pFaxPortsConfig[dwIndex].DeviceId, PORT_OPEN_MODIFY, &hFaxPortHandle)) {
  462. if (!g_bBVT) {
  463. MessageBoxMacro(NULL, IDS_FAX_RESTORE_PORT_FAILED, MB_ICONERROR, g_pFaxPortsConfig[dwIndex].DeviceName);
  464. }
  465. g_bTestFailed = TRUE;
  466. LoadString(g_hInstance, IDS_FAX_RESTORE_PORT_FAILED, szText, MAX_STRINGLEN);
  467. lstrcat(szText, L"\r\n");
  468. fnWriteLogFile(TRUE, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  469. if (g_bNTLogAvailable) {
  470. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  471. }
  472. continue;
  473. }
  474. if (!FaxSetPort(hFaxPortHandle, &g_pFaxPortsConfig[dwIndex])) {
  475. if (!g_bBVT) {
  476. MessageBoxMacro(NULL, IDS_FAX_RESTORE_PORT_FAILED, MB_ICONERROR, g_pFaxPortsConfig[dwIndex].DeviceName);
  477. }
  478. g_bTestFailed = TRUE;
  479. LoadString(g_hInstance, IDS_FAX_RESTORE_PORT_FAILED, szText, MAX_STRINGLEN);
  480. lstrcat(szText, L"\r\n");
  481. fnWriteLogFile(TRUE, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  482. if (g_bNTLogAvailable) {
  483. g_NTLogApi.ptlLog(g_hLogFile, TLS_SEV2 | TL_TEST, szText, g_pFaxPortsConfig[dwIndex].DeviceName);
  484. }
  485. }
  486. FaxClose(hFaxPortHandle);
  487. }
  488. ExitLevel3:
  489. // Free the Fax Ports Configuration
  490. FaxFreeBuffer(g_pFaxPortsConfig);
  491. ExitLevel2:
  492. // Disconnect from the Fax Service
  493. FaxClose(g_hFaxSvcHandle);
  494. ExitLevel1:
  495. CloseHandle(g_hSendFailedEvent);
  496. CloseHandle(g_hSendPassedEvent);
  497. CloseHandle(g_hRasFailedEvent);
  498. CloseHandle(g_hRasPassedEvent);
  499. CloseHandle(g_hFaxEvent);
  500. CloseHandle(g_hExitEvent);
  501. CloseHandle(g_hStopEvent);
  502. CloseHandle(g_hStartEvent);
  503. if (g_bRasAvailable) {
  504. FreeLibrary(g_RasApi.hInstance);
  505. }
  506. ExitLevel0:
  507. fnWriteLogFile(FALSE, L"\r\n");
  508. if (g_bNTLogAvailable) {
  509. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"\r\n");
  510. }
  511. if ((g_bTestFailed) || (g_dwNumTotal)) {
  512. if (g_dwNumTotal) {
  513. // Log the results
  514. LoadString(g_hInstance, IDS_NUM_PASSED, szText, MAX_STRINGLEN);
  515. fnWriteLogFile(FALSE, szText, g_dwNumPassed);
  516. if (g_bNTLogAvailable) {
  517. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, szText, g_dwNumPassed);
  518. }
  519. LoadString(g_hInstance, IDS_NUM_FAILED, szText, MAX_STRINGLEN);
  520. fnWriteLogFile(FALSE, szText, g_dwNumFailed);
  521. if (g_bNTLogAvailable) {
  522. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, szText, g_dwNumFailed);
  523. }
  524. LoadString(g_hInstance, IDS_NUM_TOTAL, szText, MAX_STRINGLEN);
  525. fnWriteLogFile(FALSE, szText, g_dwNumTotal);
  526. if (g_bNTLogAvailable) {
  527. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, szText, g_dwNumTotal);
  528. }
  529. }
  530. if ((g_bTestFailed) || (g_dwNumFailed)) {
  531. fnWriteLogFile(FALSE, L"\r\n");
  532. if (g_bNTLogAvailable) {
  533. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"\r\n");
  534. }
  535. LoadString(g_hInstance, IDS_STATUS_TEST_FAILED, szText, MAX_STRINGLEN);
  536. fnWriteLogFile(FALSE, L"%s\r\n", szText);
  537. if (g_bNTLogAvailable) {
  538. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"%s\r\n", szText);
  539. }
  540. }
  541. else {
  542. fnWriteLogFile(FALSE, L"\r\n");
  543. if (g_bNTLogAvailable) {
  544. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"\r\n");
  545. }
  546. LoadString(g_hInstance, IDS_STATUS_TEST_PASSED, szText, MAX_STRINGLEN);
  547. fnWriteLogFile(FALSE, L"%s\r\n", szText);
  548. if (g_bNTLogAvailable) {
  549. g_NTLogApi.ptlLog(g_hLogFile, TLS_INFO | TL_TEST, L"%s\r\n", szText);
  550. }
  551. }
  552. }
  553. // Close the log file
  554. fnCloseLogFile();
  555. CloseHandle(hMutex);
  556. return 0;
  557. }
  558. LRESULT CALLBACK fnDialogProcSetup (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  559. {
  560. // hWndStatusList is the handle to the Status List
  561. static HWND hWndStatusList;
  562. // rcClient is the WindowRect of the Status List
  563. RECT rcClient;
  564. // lvc specifies the attributes of a particular column of the Status List
  565. LV_COLUMN lvc;
  566. // lvi specifies the attributes of a particular item of the Status List
  567. LV_ITEM lvi;
  568. // szText is a text string
  569. WCHAR szText[MAX_STRINGLEN + 1];
  570. // szFormatString is the format of the text string
  571. WCHAR szFormatString[MAX_STRINGLEN + 1];
  572. // szRasError is the Ras error string
  573. WCHAR szRasError[MAX_STRINGLEN + 1];
  574. // dwResourceId is the resource id
  575. DWORD dwResourceId;
  576. // szDeviceName is the device name
  577. LPWSTR szDeviceName;
  578. // szIniFile is the ini file name
  579. static WCHAR szIniFile[_MAX_PATH + 1];
  580. // szMissingInfo is the missing info
  581. WCHAR szMissingInfo[MAX_STRINGLEN + 1];
  582. // szMissingInfoError is the missing info error message
  583. WCHAR szMissingInfoError[(MAX_STRINGLEN * 5) + 1];
  584. DWORD dwStyle;
  585. DWORD dwLevel;
  586. switch (iMsg) {
  587. case WM_CREATE:
  588. // Get the Rect of the Setup Dialog
  589. GetWindowRect(hWnd, &rcClient);
  590. if (!g_bBVT) {
  591. // Increase the bottom of the Setup Dialog Rect by the height of the menu
  592. rcClient.bottom += GetSystemMetrics(SM_CYMENU);
  593. }
  594. // Resize the Setup Dialog
  595. SetWindowPos(hWnd, NULL, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOMOVE | SWP_NOZORDER);
  596. break;
  597. case UM_FAXVRFY_INITIALIZE:
  598. CheckMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | g_bSend ? MF_CHECKED : MF_UNCHECKED);
  599. CheckMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | g_bSend ? MF_UNCHECKED : MF_CHECKED);
  600. // Limit the text length of edit controls
  601. SendMessage(GetDlgItem(hWnd, IDC_SEND_NUMBER), EM_SETLIMITTEXT, PHONE_NUM_LEN, 0);
  602. SendMessage(GetDlgItem(hWnd, IDC_RECEIVE_NUMBER), EM_SETLIMITTEXT, PHONE_NUM_LEN, 0);
  603. SendMessage(GetDlgItem(hWnd, IDC_RAS_USER_NAME), EM_SETLIMITTEXT, UNLEN, 0);
  604. SendMessage(GetDlgItem(hWnd, IDC_RAS_PASSWORD), EM_SETLIMITTEXT, PWLEN, 0);
  605. SendMessage(GetDlgItem(hWnd, IDC_RAS_DOMAIN), EM_SETLIMITTEXT, DNLEN, 0);
  606. // Get the handle to the Status List
  607. hWndStatusList = GetDlgItem(hWnd, IDC_STATUS_LIST);
  608. // Get the Rect of the Status List
  609. GetWindowRect(hWndStatusList, &rcClient);
  610. // Set common attributes for each column
  611. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  612. lvc.fmt = LVCFMT_LEFT;
  613. // Event Column
  614. // Load the Event Column text
  615. LoadString(g_hInstance, IDS_EVENT_LABEL, szText, MAX_STRINGLEN);
  616. // Set the column text
  617. lvc.pszText = szText;
  618. // Set the width of the column to be about 2 / 5 of the width of the Status List, allowing for the width of the borders and scroll bar
  619. lvc.cx = ((rcClient.right - rcClient.left - 4 * GetSystemMetrics(SM_CXBORDER) - GetSystemMetrics(SM_CXVSCROLL)) * 2) / 5;
  620. // Indicate this is the first column
  621. lvc.iSubItem = 0;
  622. // Insert column into Status List
  623. ListView_InsertColumn(hWndStatusList, 0, &lvc);
  624. // Port Column
  625. // Load the Port Column text
  626. LoadString(g_hInstance, IDS_PORT_LABEL, szText, MAX_STRINGLEN);
  627. // Set the column text
  628. lvc.pszText = szText;
  629. // Set the width of the column to be about 3 / 5 of the width of the Status List, allowing for the width of the borders and scroll bar
  630. lvc.cx = (lvc.cx * 3) / 2;
  631. // Indicate this is the second column
  632. lvc.iSubItem = 1;
  633. // Insert column into Status List
  634. ListView_InsertColumn(hWndStatusList, 1, &lvc);
  635. // Disable the Stop Button
  636. EnableWindow(GetDlgItem(hWnd, IDC_STOP_BUTTON), FALSE);
  637. // Get the current directory
  638. GetCurrentDirectory(sizeof(szIniFile) / sizeof(WCHAR), szIniFile);
  639. // Set the ini file name
  640. lstrcat(szIniFile, L"\\");
  641. lstrcat(szIniFile, FAXVRFY_INI);
  642. // Get the strings from the ini file
  643. GetPrivateProfileString(L"Fax", L"SendNumber", L"", g_szSndNumber, sizeof(g_szSndNumber), szIniFile);
  644. if (fnIsStringASCII(g_szSndNumber)) {
  645. SetDlgItemText(hWnd, IDC_SEND_NUMBER, g_szSndNumber);
  646. }
  647. else {
  648. ZeroMemory(g_szSndNumber, sizeof(g_szSndNumber));
  649. }
  650. GetPrivateProfileString(L"Fax", L"ReceiveNumber", L"", g_szRcvNumber, sizeof(g_szRcvNumber), szIniFile);
  651. if (fnIsStringASCII(g_szRcvNumber)) {
  652. SetDlgItemText(hWnd, IDC_RECEIVE_NUMBER, g_szRcvNumber);
  653. }
  654. else {
  655. ZeroMemory(g_szRcvNumber, sizeof(g_szRcvNumber));
  656. }
  657. if (g_bRasAvailable) {
  658. if (GetPrivateProfileInt(L"RAS", L"Enabled", 0, szIniFile)) {
  659. // Click the Fax Send check button
  660. SendMessage(GetDlgItem(hWnd, IDC_RAS_ENABLED_BUTTON), BM_CLICK, 0, 0);
  661. }
  662. }
  663. GetPrivateProfileString(L"RAS", L"UserName", L"", g_szRasUserName, sizeof(g_szRasUserName), szIniFile);
  664. SetDlgItemText(hWnd, IDC_RAS_USER_NAME, g_szRasUserName);
  665. ZeroMemory(g_szRasPassword, sizeof(g_szRasPassword));
  666. GetPrivateProfileString(L"RAS", L"Domain", L"", g_szRasDomain, sizeof(g_szRasDomain), szIniFile);
  667. SetDlgItemText(hWnd, IDC_RAS_DOMAIN, g_szRasDomain);
  668. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  669. return 0;
  670. case UM_FAXVRFY_RESET:
  671. // Enable or disable the Fax specific controls
  672. EnableWindow(GetDlgItem(hWnd, IDC_SEND_NUMBER_STATIC), (!wParam && g_bSend) ? TRUE : FALSE);
  673. EnableWindow(GetDlgItem(hWnd, IDC_SEND_NUMBER), (!wParam && g_bSend) ? TRUE : FALSE);
  674. EnableWindow(GetDlgItem(hWnd, IDC_RECEIVE_NUMBER_STATIC), (!wParam && g_bSend) ? TRUE : FALSE);
  675. EnableWindow(GetDlgItem(hWnd, IDC_RECEIVE_NUMBER), (!wParam && g_bSend) ? TRUE : FALSE);
  676. // Enable the RAS specific controls
  677. EnableWindow(GetDlgItem(hWnd, IDC_RAS_ENABLED_BUTTON), (!wParam && g_bSend && g_bRasAvailable) ? TRUE : FALSE);
  678. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME_STATIC), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  679. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  680. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD_STATIC), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  681. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  682. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN_STATIC), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  683. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN), (!wParam && g_bSend && g_bRasEnabled && g_bRasAvailable) ? TRUE : FALSE);
  684. if (wParam) {
  685. // Disable the Start Button
  686. EnableWindow(GetDlgItem(hWnd, IDC_START_BUTTON), FALSE);
  687. // Disable the Stop Button
  688. EnableWindow(GetDlgItem(hWnd, IDC_STOP_BUTTON), FALSE);
  689. // Enable the Exit Button
  690. EnableWindow(GetDlgItem(hWnd, IDC_EXIT_BUTTON), TRUE);
  691. // Disable the Option Menu
  692. EnableMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | MF_GRAYED);
  693. EnableMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | MF_GRAYED);
  694. // Set the focus to the Exit button
  695. SendMessage(hWnd, WM_NEXTDLGCTL, (WPARAM) GetDlgItem(hWnd, IDC_EXIT_BUTTON), MAKELONG(TRUE, 0));
  696. }
  697. else {
  698. // Enable the Start Button
  699. EnableWindow(GetDlgItem(hWnd, IDC_START_BUTTON), TRUE);
  700. // Disable the Stop Button
  701. EnableWindow(GetDlgItem(hWnd, IDC_STOP_BUTTON), FALSE);
  702. // Enable the Exit Button
  703. EnableWindow(GetDlgItem(hWnd, IDC_EXIT_BUTTON), TRUE);
  704. // Enable the Option Menu
  705. EnableMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | MF_ENABLED);
  706. EnableMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | MF_ENABLED);
  707. // Set the focus to the Start button
  708. SendMessage(hWnd, WM_NEXTDLGCTL, (WPARAM) GetDlgItem(hWnd, IDC_START_BUTTON), MAKELONG(TRUE, 0));
  709. }
  710. return 0;
  711. case UM_TIMEOUT_ENDED:
  712. case UM_FAXSVC_ENDED:
  713. g_bTestFailed = TRUE;
  714. if (iMsg == UM_TIMEOUT_ENDED) {
  715. // Update the status
  716. SendMessage(hWnd, UM_UPDATE_STATUS, IDS_STATUS_TIMEOUT_ENDED, 0);
  717. }
  718. else if (iMsg == UM_FAXSVC_ENDED) {
  719. // Post a completion packet to a completion port to exit the Fax Event Queue thread
  720. fnPostExitToCompletionPort(g_hCompletionPort);
  721. // Update the status
  722. SendMessage(hWnd, UM_UPDATE_STATUS, IDS_STATUS_FAXSVC_ENDED, 0);
  723. }
  724. if ((!IsWindowEnabled(GetDlgItem(hWnd, IDC_START_BUTTON))) && (g_bSend)) {
  725. // Update the status
  726. SendMessage(hWnd, UM_ITERATION_FAILED, 0, 0);
  727. }
  728. SendMessage(hWnd, UM_FAXVRFY_RESET, 1, 0);
  729. if (g_bBVT) {
  730. SendMessage(GetDlgItem(g_hWndDlg, IDC_EXIT_BUTTON), BM_CLICK, 0, 0);
  731. }
  732. return 0;
  733. case UM_ITERATION_STOPPED:
  734. // Update the status
  735. SendMessage(hWnd, UM_UPDATE_STATUS, IDS_STATUS_ITERATION_STOPPED, 0);
  736. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  737. return 0;
  738. case UM_ITERATION_PASSED:
  739. // Update the status
  740. SendMessage(hWnd, UM_UPDATE_STATUS, IDS_STATUS_ITERATION_PASSED, 0);
  741. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  742. // Update the iterations
  743. g_dwNumPassed++;
  744. g_dwNumTotal++;
  745. SetDlgItemInt(hWnd, IDC_NUM_PASSED, g_dwNumPassed, FALSE);
  746. SetDlgItemInt(hWnd, IDC_NUM_TOTAL, g_dwNumTotal, FALSE);
  747. if (g_bBVT) {
  748. SendMessage(GetDlgItem(g_hWndDlg, IDC_EXIT_BUTTON), BM_CLICK, 0, 0);
  749. }
  750. return 0;
  751. case UM_ITERATION_FAILED:
  752. // Update the status
  753. SendMessage(hWnd, UM_UPDATE_STATUS, IDS_STATUS_ITERATION_FAILED, 0);
  754. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  755. // Update the iterations
  756. g_dwNumFailed++;
  757. g_dwNumTotal++;
  758. SetDlgItemInt(hWnd, IDC_NUM_FAILED, g_dwNumFailed, FALSE);
  759. SetDlgItemInt(hWnd, IDC_NUM_TOTAL, g_dwNumTotal, FALSE);
  760. if (g_bBVT) {
  761. SendMessage(GetDlgItem(g_hWndDlg, IDC_EXIT_BUTTON), BM_CLICK, 0, 0);
  762. }
  763. return 0;
  764. case UM_UPDATE_STATUS:
  765. dwStyle = TLS_INFO;
  766. dwLevel = TLS_VARIATION;
  767. // Get the resource id
  768. dwResourceId = (DWORD) wParam;
  769. // Load the event text
  770. LoadString(g_hInstance, dwResourceId, szFormatString, MAX_STRINGLEN);
  771. // Set the event text
  772. lstrcpy(szText, szFormatString);
  773. szDeviceName = NULL;
  774. switch (wParam) {
  775. case IDS_STATUS_ITERATION_PASSED:
  776. dwStyle = TLS_PASS;
  777. break;
  778. case IDS_STATUS_ITERATION_FAILED:
  779. dwStyle = TLS_SEV2;
  780. break;
  781. case IDS_STATUS_TEST_PASSED:
  782. dwStyle = TLS_PASS;
  783. dwLevel = TL_TEST;
  784. break;
  785. case IDS_STATUS_RAS_FAILED:
  786. case IDS_STATUS_TIMEOUT_ENDED:
  787. case IDS_STATUS_FAX_SEND_FAILED:
  788. case IDS_STATUS_FAX_INVALID:
  789. case IDS_TIFF_INVALID_TIFF:
  790. case IDS_TIFF_INVALID_IMAGEWIDTH:
  791. case IDS_TIFF_INVALID_IMAGELENGTH:
  792. case IDS_TIFF_INVALID_COMPRESSION:
  793. case IDS_TIFF_INVALID_PHOTOMETRIC:
  794. case IDS_TIFF_INVALID_XRESOLUTION:
  795. case IDS_TIFF_INVALID_YRESOLUTION:
  796. case IDS_TIFF_INVALID_SOFTWARE:
  797. case IDS_TIFF_INVALID_PAGES:
  798. case IDS_STATUS_FAX_NO_DIAL_TONE_ABORT:
  799. case IDS_STATUS_FAX_BUSY_ABORT:
  800. case IDS_STATUS_FAX_NO_ANSWER_ABORT:
  801. case IDS_STATUS_FAX_FATAL_ERROR_ABORT:
  802. dwStyle = TLS_SEV2;
  803. break;
  804. case IDS_STATUS_FAXSVC_ENDED:
  805. dwStyle = TLS_SEV2;
  806. dwLevel = TL_TEST;
  807. break;
  808. case IDS_STATUS_RAS_SPEED_SUSPECT:
  809. case IDS_STATUS_FAX_NO_DIAL_TONE_RETRY:
  810. case IDS_STATUS_FAX_BUSY_RETRY:
  811. case IDS_STATUS_FAX_NO_ANSWER_RETRY:
  812. case IDS_STATUS_FAX_FATAL_ERROR_RETRY:
  813. case IDS_STATUS_FAX_FATAL_ERROR:
  814. case IDS_STATUS_FAX_ABORTING:
  815. dwStyle = TLS_WARN;
  816. break;
  817. case IDS_STATUS_DEVICE_POWERED_OFF:
  818. case IDS_STATUS_DEVICE_POWERED_ON:
  819. case IDS_STATUS_PORTS_NOT_AVAILABLE:
  820. case IDS_STATUS_UNEXPECTED_STATE:
  821. dwStyle = TLS_WARN;
  822. dwLevel = TL_TEST;
  823. break;
  824. }
  825. switch (wParam) {
  826. case IDS_TIFF_INVALID_PAGES:
  827. // Set the event text
  828. wsprintf(szText, szFormatString, (DWORD) lParam, g_bBVT ? FAXBVT_PAGES : FAXWHQL_PAGES);
  829. break;
  830. case IDS_STATUS_RAS_STARTING:
  831. case IDS_STATUS_FAX_STARTING:
  832. // Set the event text
  833. wsprintf(szText, szFormatString, (LPWSTR) lParam);
  834. break;
  835. case IDS_STATUS_RAS_LINESPEED:
  836. // Set the event text
  837. wsprintf(szText, szFormatString, ((PRAS_INFO) lParam)->dwBps);
  838. // Find the device name
  839. szDeviceName = ((PRAS_INFO) lParam)->szDeviceName;
  840. break;
  841. case IDS_STATUS_RAS_SPEED_SUSPECT:
  842. // Set the exent text
  843. wsprintf(szText, szFormatString, (DWORD) lParam);
  844. break;
  845. case IDS_STATUS_RAS_FAILED:
  846. // Initialize szRasError
  847. ZeroMemory(szRasError, sizeof(szRasError));
  848. if (lParam) {
  849. g_RasApi.RasGetErrorString((DWORD) lParam, szRasError, sizeof(szRasError) / sizeof(WCHAR));
  850. }
  851. // Set the event text
  852. wsprintf(szText, szFormatString, szRasError);
  853. break;
  854. case IDS_STATUS_FAX_DIALING:
  855. // Set the event text
  856. wsprintf(szText, szFormatString, ((PFAX_DIALING_INFO) lParam)->dwAttempt);
  857. // Find the device name
  858. fnFindDeviceName(g_pFaxPortsConfig, g_dwNumPorts, ((PFAX_DIALING_INFO) lParam)->dwDeviceId, &szDeviceName);
  859. break;
  860. case IDS_STATUS_FAX_RECEIVED:
  861. // Set the event text
  862. wsprintf(szText, szFormatString, ((PFAX_RECEIVE_INFO) lParam)->szCopyTiffName);
  863. // Find the device name
  864. fnFindDeviceName(g_pFaxPortsConfig, g_dwNumPorts, ((PFAX_RECEIVE_INFO) lParam)->dwDeviceId, &szDeviceName);
  865. break;
  866. case IDS_STATUS_FAX_ID:
  867. // Set the event text
  868. wsprintf(szText, szFormatString, (LPWSTR) lParam);
  869. break;
  870. case IDS_STATUS_FAX_VERIFYING:
  871. // Set the event text
  872. wsprintf(szText, szFormatString, (LPWSTR) lParam);
  873. break;
  874. default:
  875. // Find the device name
  876. fnFindDeviceName(g_pFaxPortsConfig, g_dwNumPorts, (DWORD) lParam, &szDeviceName);
  877. break;
  878. }
  879. // Indicate only pszText is valid
  880. lvi.mask = LVIF_TEXT;
  881. // Set the Event text
  882. lvi.pszText = szText;
  883. // Set the item number
  884. lvi.iItem = ListView_GetItemCount(hWndStatusList);
  885. // Indicate this is the first column
  886. lvi.iSubItem = 0;
  887. // Insert item into Status List
  888. ListView_InsertItem(hWndStatusList, &lvi);
  889. // Set the Port text
  890. lvi.pszText = szDeviceName;
  891. // Indicate this is the second column
  892. lvi.iSubItem = 1;
  893. // Set item in Status List
  894. ListView_SetItem(hWndStatusList, &lvi);
  895. if (szDeviceName) {
  896. DebugMacro(L"%s: %s\n", szDeviceName, szText);
  897. }
  898. else {
  899. DebugMacro(L"%s\n", szText);
  900. }
  901. if (szDeviceName) {
  902. fnWriteLogFile(TRUE, L"%s: %s\r\n", szDeviceName, szText);
  903. }
  904. else {
  905. fnWriteLogFile(TRUE, L"%s\r\n", szText);
  906. }
  907. if (g_bNTLogAvailable) {
  908. if (szDeviceName) {
  909. switch (dwLevel) {
  910. case TLS_TEST:
  911. g_NTLogApi.ptlLog(g_hLogFile, dwStyle | TL_TEST, L"%s: %s\r\n", szDeviceName, szText);
  912. break;
  913. case TLS_VARIATION:
  914. g_NTLogApi.ptlLog(g_hLogFile, dwStyle | TL_VARIATION, L"%s: %s\r\n", szDeviceName, szText);
  915. break;
  916. }
  917. }
  918. else {
  919. switch (dwLevel) {
  920. case TLS_TEST:
  921. g_NTLogApi.ptlLog(g_hLogFile, dwStyle | TL_TEST, L"%s\r\n", szText);
  922. break;
  923. case TLS_VARIATION:
  924. g_NTLogApi.ptlLog(g_hLogFile, dwStyle | TL_VARIATION, L"%s\r\n", szText);
  925. break;
  926. }
  927. }
  928. }
  929. // Scroll the Status List
  930. ListView_EnsureVisible(hWndStatusList, lvi.iItem, FALSE);
  931. return 0;
  932. case WM_SETFOCUS:
  933. // Verify correct control has the focus
  934. if ((!IsWindowEnabled(GetDlgItem(hWnd, IDC_STOP_BUTTON))) && (SendMessage(GetDlgItem(hWnd, IDC_STOP_BUTTON), WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)) {
  935. // Set the focus to the start button
  936. SendMessage(hWnd, WM_NEXTDLGCTL, (WPARAM) GetDlgItem(hWnd, IDC_START_BUTTON), MAKELONG(TRUE, 0));
  937. }
  938. break;
  939. case WM_CLOSE:
  940. if (IsWindowEnabled(GetDlgItem(hWnd, IDC_EXIT_BUTTON))) {
  941. // Signal the Exit event
  942. SetEvent(g_hExitEvent);
  943. // Post a completion packet to a completion port to exit the Fax Event Queue thread
  944. fnPostExitToCompletionPort(g_hCompletionPort);
  945. // Close the application
  946. DestroyWindow(hWnd);
  947. PostQuitMessage(0);
  948. }
  949. return 0;
  950. case WM_COMMAND:
  951. switch (LOWORD(wParam)) {
  952. case IDM_SEND:
  953. if (!g_bSend) {
  954. g_bSend = TRUE;
  955. CheckMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | MF_CHECKED);
  956. CheckMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | MF_UNCHECKED);
  957. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  958. }
  959. return 0;
  960. case IDM_RECEIVE:
  961. if (g_bSend) {
  962. g_bSend = FALSE;
  963. CheckMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | MF_UNCHECKED);
  964. CheckMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | MF_CHECKED);
  965. SendMessage(hWnd, UM_FAXVRFY_RESET, 0, 0);
  966. }
  967. return 0;
  968. case IDM_HELP:
  969. fnUsageInfo(hWnd);
  970. return 0;
  971. case IDC_SEND_NUMBER:
  972. if (HIWORD(wParam) == EN_CHANGE) {
  973. if (!fnIsEditControlASCII(hWnd, IDC_SEND_NUMBER, PHONE_NUM_LEN + 1)) {
  974. // Load the error text
  975. LoadString(g_hInstance, IDS_ASCII_SEND_NUMBER, szText, MAX_STRINGLEN);
  976. // Display the pop-up
  977. MessageBox(hWnd, szText, FAXVRFY_NAME, MB_OK | MB_ICONERROR);
  978. SetDlgItemText(hWnd, IDC_SEND_NUMBER, g_szSndNumber);
  979. }
  980. GetDlgItemText(hWnd, IDC_SEND_NUMBER, g_szSndNumber, PHONE_NUM_LEN + 1);
  981. }
  982. return 0;
  983. case IDC_RECEIVE_NUMBER:
  984. if (HIWORD(wParam) == EN_CHANGE) {
  985. if (!fnIsEditControlASCII(hWnd, IDC_RECEIVE_NUMBER, PHONE_NUM_LEN + 1)) {
  986. // Load the error text
  987. LoadString(g_hInstance, IDS_ASCII_RECEIVE_NUMBER, szText, MAX_STRINGLEN);
  988. // Display the pop-up
  989. MessageBox(hWnd, szText, FAXVRFY_NAME, MB_OK | MB_ICONERROR);
  990. SetDlgItemText(hWnd, IDC_RECEIVE_NUMBER, g_szRcvNumber);
  991. }
  992. GetDlgItemText(hWnd, IDC_RECEIVE_NUMBER, g_szRcvNumber, PHONE_NUM_LEN + 1);
  993. }
  994. return 0;
  995. case IDC_RAS_ENABLED_BUTTON:
  996. // RAS Enabled Check Box was clicked
  997. g_bRasEnabled = IsDlgButtonChecked(hWnd, IDC_RAS_ENABLED_BUTTON);
  998. // Enable or disable the RAS specific controls
  999. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME_STATIC), g_bRasEnabled ? TRUE : FALSE);
  1000. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME), g_bRasEnabled ? TRUE : FALSE);
  1001. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD_STATIC), g_bRasEnabled ? TRUE : FALSE);
  1002. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD), g_bRasEnabled ? TRUE : FALSE);
  1003. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN_STATIC), g_bRasEnabled ? TRUE : FALSE);
  1004. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN), g_bRasEnabled ? TRUE : FALSE);
  1005. return 0;
  1006. case IDC_START_BUTTON:
  1007. if (g_bSend) {
  1008. // Initialize szMissingInfoError
  1009. ZeroMemory(szMissingInfoError, sizeof(szMissingInfoError));
  1010. // Get send phone number
  1011. GetDlgItemText(hWnd, IDC_SEND_NUMBER, g_szSndNumber, PHONE_NUM_LEN + 1);
  1012. // Get receive phone number
  1013. GetDlgItemText(hWnd, IDC_RECEIVE_NUMBER, g_szRcvNumber, PHONE_NUM_LEN + 1);
  1014. // See if RAS is enabled
  1015. g_bRasEnabled = IsDlgButtonChecked(hWnd, IDC_RAS_ENABLED_BUTTON);
  1016. // Get RAS user name
  1017. GetDlgItemText(hWnd, IDC_RAS_USER_NAME, g_szRasUserName, UNLEN + 1);
  1018. // Get RAS password
  1019. GetDlgItemText(hWnd, IDC_RAS_PASSWORD, g_szRasPassword, PWLEN + 1);
  1020. // Get RAS domain
  1021. GetDlgItemText(hWnd, IDC_RAS_DOMAIN, g_szRasDomain, DNLEN + 1);
  1022. if (!lstrlen(g_szSndNumber)) {
  1023. // There is no send phone number
  1024. LoadString(g_hInstance, IDS_MISSING_INFO, szMissingInfoError, MAX_STRINGLEN);
  1025. LoadString(g_hInstance, IDS_NO_SEND_NUMBER, szMissingInfo, MAX_STRINGLEN);
  1026. lstrcat(szMissingInfoError, szMissingInfo);
  1027. }
  1028. if (!lstrlen(g_szRcvNumber)) {
  1029. // There is no receive phone number
  1030. if (lstrlen(szMissingInfoError)) {
  1031. lstrcat(szMissingInfoError, L"\n");
  1032. }
  1033. else {
  1034. LoadString(g_hInstance, IDS_MISSING_INFO, szMissingInfoError, MAX_STRINGLEN);
  1035. }
  1036. LoadString(g_hInstance, IDS_NO_RECEIVE_NUMBER, szMissingInfo, MAX_STRINGLEN);
  1037. lstrcat(szMissingInfoError, szMissingInfo);
  1038. }
  1039. if (g_bRasEnabled) {
  1040. if (!lstrlen(g_szRasUserName)) {
  1041. // There is no RAS user name
  1042. if (lstrlen(szMissingInfoError)) {
  1043. lstrcat(szMissingInfoError, L"\n");
  1044. }
  1045. else {
  1046. LoadString(g_hInstance, IDS_MISSING_INFO, szMissingInfoError, MAX_STRINGLEN);
  1047. }
  1048. LoadString(g_hInstance, IDS_NO_RAS_USER_NAME, szMissingInfo, MAX_STRINGLEN);
  1049. lstrcat(szMissingInfoError, szMissingInfo);
  1050. }
  1051. if (!lstrlen(g_szRasDomain)) {
  1052. // There is no RAS domain
  1053. if (lstrlen(szMissingInfoError)) {
  1054. lstrcat(szMissingInfoError, L"\n");
  1055. }
  1056. else {
  1057. LoadString(g_hInstance, IDS_MISSING_INFO, szMissingInfoError, MAX_STRINGLEN);
  1058. }
  1059. LoadString(g_hInstance, IDS_NO_RAS_DOMAIN, szMissingInfo, MAX_STRINGLEN);
  1060. lstrcat(szMissingInfoError, szMissingInfo);
  1061. }
  1062. }
  1063. if (lstrlen(szMissingInfoError)) {
  1064. // Display the missing info error pop-up
  1065. MessageBox(hWnd, szMissingInfoError, FAXVRFY_NAME, MB_OK | MB_ICONERROR);
  1066. return 0;
  1067. }
  1068. // Disable the Fax specific controls
  1069. EnableWindow(GetDlgItem(hWnd, IDC_SEND_NUMBER_STATIC), FALSE);
  1070. EnableWindow(GetDlgItem(hWnd, IDC_SEND_NUMBER), FALSE);
  1071. EnableWindow(GetDlgItem(hWnd, IDC_RECEIVE_NUMBER), FALSE);
  1072. EnableWindow(GetDlgItem(hWnd, IDC_RECEIVE_NUMBER_STATIC), FALSE);
  1073. // Disable the RAS specific controls
  1074. EnableWindow(GetDlgItem(hWnd, IDC_RAS_ENABLED_BUTTON), FALSE);
  1075. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME_STATIC), FALSE);
  1076. EnableWindow(GetDlgItem(hWnd, IDC_RAS_USER_NAME), FALSE);
  1077. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD_STATIC), FALSE);
  1078. EnableWindow(GetDlgItem(hWnd, IDC_RAS_PASSWORD), FALSE);
  1079. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN_STATIC), FALSE);
  1080. EnableWindow(GetDlgItem(hWnd, IDC_RAS_DOMAIN), FALSE);
  1081. // Set the strings to the ini file
  1082. WritePrivateProfileString(L"Fax", L"SendNumber", g_szSndNumber, szIniFile);
  1083. WritePrivateProfileString(L"Fax", L"ReceiveNumber", g_szRcvNumber, szIniFile);
  1084. WritePrivateProfileString(L"RAS", L"Enabled", g_bRasEnabled ? L"1" : L"0", szIniFile);
  1085. WritePrivateProfileString(L"RAS", L"UserName", g_szRasUserName, szIniFile);
  1086. WritePrivateProfileString(L"RAS", L"Domain", g_szRasDomain, szIniFile);
  1087. }
  1088. // Disable the Option Menu
  1089. EnableMenuItem(GetMenu(hWnd), IDM_SEND, MF_BYCOMMAND | MF_GRAYED);
  1090. EnableMenuItem(GetMenu(hWnd), IDM_RECEIVE, MF_BYCOMMAND | MF_GRAYED);
  1091. // Disable the Start Button
  1092. EnableWindow(GetDlgItem(hWnd, IDC_START_BUTTON), FALSE);
  1093. // Enable the Stop Button
  1094. EnableWindow(GetDlgItem(hWnd, IDC_STOP_BUTTON), TRUE);
  1095. // Disable the Exit Button
  1096. EnableWindow(GetDlgItem(hWnd, IDC_EXIT_BUTTON), FALSE);
  1097. // Set the focus to the Stop button
  1098. SendMessage(hWnd, WM_NEXTDLGCTL, (WPARAM) GetDlgItem(hWnd, IDC_STOP_BUTTON), MAKELONG(TRUE, 0));
  1099. // Update the status
  1100. SendMessage(g_hWndDlg, UM_UPDATE_STATUS, IDS_STATUS_ITERATION_STARTED, 0);
  1101. // Signal the Start event
  1102. SetEvent(g_hStartEvent);
  1103. return 0;
  1104. case IDC_STOP_BUTTON:
  1105. // Signal the Stop event
  1106. SetEvent(g_hStopEvent);
  1107. return 0;
  1108. case IDC_EXIT_BUTTON:
  1109. SendMessage(hWnd, WM_CLOSE, 0, 0);
  1110. return 0;
  1111. }
  1112. }
  1113. return DefDlgProc(hWnd, iMsg, wParam, lParam);
  1114. }