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.

923 lines
22 KiB

  1. //+---------------------------------------------------------------------------
  2. // File name: dialdlg.cpp
  3. //
  4. // This file impelements the dialing and download progress dialog
  5. //
  6. // Copyright (C) 1996 Microsoft Corporation
  7. // All rights reserved
  8. //
  9. // Authors:
  10. // ChrisK Chris Kauffman
  11. // VetriV Vellore Vetrivelkumaran
  12. //
  13. // History:
  14. // 7/22/96 ChrisK Cleaned and formatted
  15. // 8/5/96 VetriV Added WIN16 code
  16. // 8/19/96 ValdonB Added "dial as is" support
  17. // Fixed some memory leaks
  18. //
  19. // -----------------------------------------------------------------------------*/
  20. #include "pch.hpp"
  21. #include "globals.h"
  22. #if defined(WIN16)
  23. #include "ietapi.h"
  24. #include <comctlie.h>
  25. #include <string.h>
  26. static FARPROC lpfnCallback = (FARPROC) NULL;
  27. #endif
  28. #define MAX_EXIT_RETRIES 10
  29. #define WM_DIAL WM_USER+3
  30. #define MAX_RETIES 3
  31. PMYDEVICE g_pdevice = NULL;
  32. PDIALDLG g_pcPDLG = NULL;
  33. // ############################################################################
  34. void CALLBACK LineCallback(DWORD hDevice,
  35. DWORD dwMessage,
  36. DWORD dwInstance,
  37. DWORD dwParam1,
  38. DWORD dwParam2,
  39. DWORD dwParam3)
  40. {
  41. }
  42. #if defined(WIN16)
  43. static BOOL g_bFirstTime = TRUE;
  44. #endif
  45. HWND g_hDialDlgWnd = NULL;
  46. // ############################################################################
  47. HRESULT ShowDialingDialog(LPTSTR pszConnectoid, PGATHEREDINFO pGI, LPTSTR szUrl, HINSTANCE hInst, HWND hwnd, LPTSTR szINSFile)
  48. {
  49. int iRC;
  50. HINSTANCE hDialDLL = NULL;
  51. #if !defined(WIN16)
  52. PFNDDDlg pfnDDDlg = NULL;
  53. DIALDLGDATA ddData;
  54. #endif
  55. if (!g_pdevice) g_pdevice = (PMYDEVICE)GlobalAlloc(GPTR,sizeof(MYDEVICE));
  56. if (!g_pdevice)
  57. {
  58. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  59. iRC = ERROR_NOT_ENOUGH_MEMORY;
  60. goto ShowDialingDialogExit;
  61. }
  62. g_pdevice->dwTapiDev = 0xffffffff;
  63. #if defined(WIN16)
  64. if (!g_pcPDLG) g_pcPDLG = (PDIALDLG)GlobalAlloc(GPTR,sizeof(DIALDLG));
  65. if (!g_pcPDLG)
  66. {
  67. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  68. iRC = ERROR_NOT_ENOUGH_MEMORY;
  69. goto ShowDialingDialogExit;
  70. }
  71. g_pcPDLG->m_pszConnectoid = (LPTSTR)GlobalAlloc(GPTR,lstrlen(pszConnectoid)+1);
  72. if (!g_pcPDLG->m_pszConnectoid)
  73. {
  74. iRC = ERROR_NOT_ENOUGH_MEMORY;
  75. goto ShowDialingDialogExit;
  76. }
  77. lstrcpy(g_pcPDLG->m_pszConnectoid,pszConnectoid);
  78. g_pcPDLG->m_pGI = pGI;
  79. g_pcPDLG->m_szUrl = szUrl;
  80. g_pcPDLG->g_hInst = hInst;
  81. g_bProgressBarVisible = FALSE;
  82. #define DLGPROC16 DLGPROC // Identify as only cast for Win16
  83. DLGPROC dlgprc;
  84. dlgprc = (DLGPROC16) MakeProcInstance((FARPROC)DialDlgProc, g_pcPDLG->g_hInst);
  85. iRC = DialogBoxParam(g_pcPDLG->g_hInst,
  86. MAKEINTRESOURCE(IDD_DIALING),
  87. hwnd, dlgprc, (LPARAM)g_pcPDLG);
  88. FreeProcInstance((FARPROC) dlgprc);
  89. ShowDialingDialogExit:
  90. if (g_pcPDLG->m_pszConnectoid) GlobalFree(g_pcPDLG->m_pszConnectoid);
  91. if (g_pcPDLG->m_pszDisplayable) GlobalFree(g_pcPDLG->m_pszDisplayable);
  92. if (g_pcPDLG) GlobalFree(g_pcPDLG);
  93. g_pcPDLG = NULL;
  94. return iRC;
  95. #else
  96. //
  97. // Fill in data structure
  98. //
  99. ZeroMemory(&ddData,sizeof(ddData));
  100. ddData.dwSize = sizeof(ddData);
  101. StrDup(&ddData.pszMessage,GetSz(IDS_DOWNLOAD_SW));
  102. StrDup(&ddData.pszRasEntryName,pszConnectoid);
  103. StrDup(&ddData.pszMultipartMIMEUrl,pszSetupClientURL);
  104. ddData.pfnStatusCallback = StatusMessageCallback;
  105. ddData.hInst = hInst;
  106. ddData.bSkipDial = (0 == uiSetupClientNewPhoneCall);
  107. //
  108. // ChrisK 8/20/97
  109. // Pass .ins file to dialer so that the dialer can find the password
  110. //
  111. StrDup(&ddData.pszDunFile,szINSFile);
  112. //
  113. // Load API
  114. //
  115. hDialDLL = LoadLibrary(AUTODIAL_LIBRARY);
  116. if (!hDialDLL)
  117. {
  118. AssertSz(0,"Can't load icwdial.\r\n");
  119. iRC = GetLastError();
  120. goto ShowDialingDialogExit;
  121. }
  122. pfnDDDlg = (PFNDDDlg)GetProcAddress(hDialDLL,"DialingDownloadDialog");
  123. if (!pfnDDDlg)
  124. {
  125. AssertSz(0,"Can find DialingDownloadDialog.\r\n");
  126. iRC = GetLastError();
  127. goto ShowDialingDialogExit;
  128. }
  129. //
  130. // Display Dialog
  131. //
  132. iRC = pfnDDDlg(&ddData);
  133. //
  134. // Free memory and clean up
  135. //
  136. if (hDialDLL) FreeLibrary(hDialDLL);
  137. if (ddData.pszMessage) GlobalFree(ddData.pszMessage);
  138. if (ddData.pszRasEntryName) GlobalFree(ddData.pszRasEntryName);
  139. if (ddData.pszMultipartMIMEUrl) GlobalFree(ddData.pszMultipartMIMEUrl);
  140. ShowDialingDialogExit:
  141. return iRC;
  142. #endif
  143. }
  144. // ############################################################################
  145. extern "C" INT_PTR CALLBACK FAR PASCAL DialDlgProc(HWND hwnd,
  146. UINT uMsg,
  147. WPARAM wparam,
  148. LPARAM lparam)
  149. {
  150. static UINT unRasEvent = 0;
  151. #if defined(WIN16)
  152. static BOOL bUserCancelled = FALSE;
  153. #endif
  154. HRESULT hr;
  155. //BOOL bPW;
  156. WORD wIDS;
  157. //LPRASDIALPARAMS lpRasDialParams;
  158. HINSTANCE hDLDLL;
  159. FARPROC fp;
  160. #if !defined(WIN16)
  161. DWORD dwThreadResults;
  162. #endif
  163. INT iRetries;
  164. #if defined(WIN16)
  165. RECT MyRect;
  166. RECT DTRect;
  167. #endif
  168. BOOL bRes = TRUE;
  169. switch(uMsg)
  170. {
  171. case WM_DESTROY:
  172. ReleaseBold(GetDlgItem(hwnd,IDC_LBLTITLE));
  173. #ifdef WIN16
  174. DeleteDlgFont(hwnd);
  175. #endif
  176. bRes = FALSE;
  177. break;
  178. #if defined(WIN16)
  179. case WM_SYSCOLORCHANGE:
  180. Ctl3dColorChange();
  181. break;
  182. #endif
  183. case WM_INITDIALOG:
  184. g_hDialDlgWnd = hwnd;
  185. #if defined(WIN16)
  186. g_bFirstTime = TRUE;
  187. bUserCancelled = FALSE;
  188. //
  189. // Move the window to the center of the screen
  190. //
  191. GetWindowRect(hwnd, &MyRect);
  192. GetWindowRect(GetDesktopWindow(), &DTRect);
  193. MoveWindow(hwnd, (DTRect.right - MyRect.right) / 2, (DTRect.bottom - MyRect.bottom) /2,
  194. MyRect.right, MyRect.bottom, FALSE);
  195. SetNonBoldDlg(hwnd);
  196. #endif
  197. ShowWindow(GetDlgItem(hwnd,IDC_PROGRESS),SW_HIDE);
  198. g_pcPDLG->m_hwnd = hwnd;
  199. SPParams.hwnd = hwnd;
  200. #if !defined(WIN16)
  201. unRasEvent = RegisterWindowMessageA( RASDIALEVENT );
  202. #endif
  203. if (unRasEvent == 0) unRasEvent = WM_RASDIALEVENT;
  204. MakeBold(GetDlgItem(hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  205. // Do not make a call. We are already connected
  206. //
  207. if (uiSetupClientNewPhoneCall == FALSE)
  208. {
  209. PostMessage(hwnd,unRasEvent,(WPARAM)RASCS_Connected,0);
  210. break;
  211. }
  212. // Show number to be dialed
  213. //
  214. hr = GetDisplayableNumberDialDlg();
  215. if (hr != ERROR_SUCCESS)
  216. {
  217. SetDlgItemText(hwnd,IDC_LBLNUMBER,g_pcPDLG->m_szPhoneNumber);
  218. } else {
  219. SetDlgItemText(hwnd,IDC_LBLNUMBER,g_pcPDLG->m_pszDisplayable);
  220. }
  221. PostMessage(hwnd,WM_DIAL,0,0);
  222. break;
  223. case WM_DIAL:
  224. hr = DialDlg();
  225. #if defined(DEBUG)
  226. if (0 != hr)
  227. {
  228. TCHAR szTempBuf[255];
  229. RasGetErrorString((UINT)hr, szTempBuf, 254);
  230. Dprintf("CONNECT: Ras error string is <%s>\n", szTempBuf);
  231. }
  232. #endif
  233. if (hr != ERROR_SUCCESS)
  234. EndDialog(hwnd,(int)hr);
  235. break;
  236. case WM_CLOSE:
  237. if (dwDownLoad)
  238. {
  239. hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  240. if (hDLDLL)
  241. {
  242. fp = GetProcAddress(hDLDLL,DOWNLOADCANCEL);
  243. if(fp && dwDownLoad)
  244. ((PFNDOWNLOADCANCEL)fp)(dwDownLoad);
  245. FreeLibrary(hDLDLL);
  246. }
  247. }
  248. if (uiSetupClientNewPhoneCall)
  249. {
  250. if (g_pcPDLG->m_hrasconn)
  251. {
  252. RasHangUp(g_pcPDLG->m_hrasconn);
  253. WaitForConnectionTermination(g_pcPDLG->m_hrasconn);
  254. }
  255. g_pcPDLG->m_hrasconn = NULL;
  256. }
  257. EndDialog(hwnd,ERROR_USERCANCEL);
  258. break;
  259. case WM_COMMAND:
  260. switch(LOWORD(wparam))
  261. {
  262. case IDC_CMDCANCEL:
  263. if (dwDownLoad)
  264. {
  265. hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  266. if (hDLDLL)
  267. {
  268. fp = GetProcAddress(hDLDLL,DOWNLOADCANCEL);
  269. if(fp && dwDownLoad)
  270. ((PFNDOWNLOADCANCEL)fp)(dwDownLoad);
  271. FreeLibrary(hDLDLL);
  272. }
  273. #if !defined(WIN16)
  274. } else {
  275. PostMessage(hwnd,unRasEvent,RASCS_Disconnected,ERROR_USER_DISCONNECTION);
  276. #endif //!WIN16
  277. }
  278. if (uiSetupClientNewPhoneCall)
  279. {
  280. if (g_pcPDLG->m_hrasconn)
  281. {
  282. RasHangUp(g_pcPDLG->m_hrasconn);
  283. WaitForConnectionTermination(g_pcPDLG->m_hrasconn);
  284. }
  285. g_pcPDLG->m_hrasconn = NULL;
  286. }
  287. break;
  288. }
  289. #if defined(WIN16)
  290. bUserCancelled = TRUE;
  291. #endif
  292. EndDialog(hwnd,ERROR_USERCANCEL);
  293. break;
  294. case WM_DOWNLOAD_DONE:
  295. #if !defined(WIN16)
  296. dwThreadResults = STILL_ACTIVE;
  297. #endif
  298. iRetries = 0;
  299. if (uiSetupClientNewPhoneCall)
  300. {
  301. if (g_pcPDLG->m_hrasconn)
  302. {
  303. RasHangUp(g_pcPDLG->m_hrasconn);
  304. WaitForConnectionTermination(g_pcPDLG->m_hrasconn);
  305. }
  306. }
  307. #if !defined(WIN16)
  308. do {
  309. if (!GetExitCodeThread(g_pcPDLG->m_hThread,&dwThreadResults))
  310. {
  311. AssertSz(0,"CONNECT:GetExitCodeThread failed.\n");
  312. }
  313. iRetries++;
  314. if (dwThreadResults == STILL_ACTIVE) Sleep(500);
  315. } while (dwThreadResults == STILL_ACTIVE && iRetries < MAX_EXIT_RETRIES);
  316. if (dwThreadResults == ERROR_SUCCESS)
  317. EndDialog(hwnd,ERROR_USERNEXT);
  318. else
  319. EndDialog(hwnd, dwThreadResults);
  320. #else
  321. EndDialog(hwnd, ERROR_USERNEXT);
  322. #endif //!WIN16
  323. break;
  324. default:
  325. bRes = FALSE;
  326. if (uMsg == unRasEvent)
  327. {
  328. Dprintf(TEXT("CONNECT2: Ras event %u error code (%ld)\n"),wparam,lparam);
  329. #if defined(DEBUG)
  330. if (0 != lparam)
  331. {
  332. TCHAR szTempBuf[255];
  333. RasGetErrorString((UINT)lparam, szTempBuf, 254);
  334. Dprintf("CONNECT2: Ras error string is <%s>\n", szTempBuf);
  335. }
  336. #endif
  337. #if !defined(WIN16)
  338. TCHAR dzRasError[10];
  339. wsprintf(dzRasError,TEXT("%d %d"),wparam,lparam);
  340. RegSetValue(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\iSignUp"),REG_SZ,dzRasError,lstrlen(dzRasError));
  341. #endif
  342. #if defined(WIN16)
  343. //
  344. // Work around for WIN16 RAS bug - if status code to > 0x4000
  345. // adjust it to the correct value
  346. //
  347. if (wparam >= 0x4000)
  348. wparam -= 0x4000;
  349. #endif
  350. wIDS = 0;
  351. switch(wparam)
  352. {
  353. case RASCS_OpenPort:
  354. wIDS = IDS_RAS_OPENPORT;
  355. break;
  356. case RASCS_PortOpened:
  357. wIDS = IDS_RAS_PORTOPENED;
  358. break;
  359. case RASCS_ConnectDevice:
  360. wIDS = IDS_RAS_DIALING;
  361. break;
  362. #if defined(WIN16)
  363. case RASCS_AllDevicesConnected:
  364. wIDS = IDS_RAS_CONNECTED;
  365. break;
  366. #else
  367. case RASCS_DeviceConnected:
  368. wIDS = IDS_RAS_CONNECTED;
  369. break;
  370. #endif
  371. case RASCS_StartAuthentication:
  372. case RASCS_LogonNetwork:
  373. wIDS = IDS_RAS_LOCATING;
  374. break;
  375. // case RASCS_CallbackComplete:
  376. // wIDS = IDS_RAS_CONNECTED;
  377. // break;
  378. /* ETC...
  379. RASCS_AllDevicesConnected,
  380. RASCS_Authenticate,
  381. RASCS_AuthNotify,
  382. RASCS_AuthRetry,
  383. RASCS_AuthCallback,
  384. RASCS_AuthChangePassword,
  385. RASCS_AuthProject,
  386. RASCS_AuthLinkSpeed,
  387. RASCS_AuthAck,
  388. RASCS_ReAuthenticate,
  389. RASCS_Authenticated,
  390. RASCS_PrepareForCallback,
  391. RASCS_WaitForModemReset,
  392. RASCS_WaitForCallback,
  393. RASCS_Projected,
  394. RASCS_Interactive = RASCS_PAUSED,
  395. RASCS_RetryAuthentication,
  396. RASCS_CallbackSetByCaller,
  397. RASCS_PasswordExpired,
  398. */
  399. case RASCS_Connected:
  400. #if !defined(WIN16)
  401. MinimizeRNAWindow(g_pcPDLG->m_pszConnectoid, g_pcPDLG->g_hInst);
  402. #endif // !WIN16
  403. //
  404. // The connection is open and ready. Start the download.
  405. //
  406. g_pcPDLG->m_dwThreadID = 0;
  407. #if defined(WIN16)
  408. if (ThreadInit() != ERROR_SUCCESS)
  409. g_pcPDLG->m_hThread = NULL;
  410. else
  411. g_pcPDLG->m_hThread = 1;
  412. #else
  413. g_pcPDLG->m_hThread = CreateThread(NULL,0,
  414. (LPTHREAD_START_ROUTINE)ThreadInit,
  415. NULL,0,
  416. &g_pcPDLG->m_dwThreadID);
  417. #endif
  418. if (!g_pcPDLG->m_hThread)
  419. {
  420. if (uiSetupClientNewPhoneCall)
  421. {
  422. if (g_pcPDLG->m_hrasconn)
  423. {
  424. RasHangUp(g_pcPDLG->m_hrasconn);
  425. WaitForConnectionTermination(g_pcPDLG->m_hrasconn);
  426. }
  427. g_pcPDLG->m_hrasconn = NULL;
  428. }
  429. hr = GetLastError();
  430. #if defined(WIN16)
  431. if (bUserCancelled)
  432. hr = ERROR_USERCANCEL;
  433. #endif
  434. EndDialog(hwnd,(int)hr);
  435. break;
  436. }
  437. break;
  438. case RASCS_Disconnected:
  439. //if (FShouldRetry(lparam))
  440. // PostMessage(hwnd,WM_DIAL,0,0);
  441. //else
  442. if (uiSetupClientNewPhoneCall)
  443. {
  444. if (g_pcPDLG->m_hrasconn)
  445. {
  446. RasHangUp(g_pcPDLG->m_hrasconn);
  447. WaitForConnectionTermination(g_pcPDLG->m_hrasconn);
  448. }
  449. g_pcPDLG->m_hrasconn = NULL;
  450. }
  451. EndDialog(hwnd, (int)lparam);
  452. break;
  453. //EndDialog(hwnd,lparam);
  454. //break;
  455. }
  456. if (wIDS)
  457. SetDlgItemText(hwnd,IDC_LBLSTATUS,GetSz(wIDS));
  458. }
  459. }
  460. return bRes;
  461. }
  462. // ############################################################################
  463. HRESULT GetDisplayableNumberDialDlg()
  464. {
  465. HRESULT hr;
  466. LPRASENTRY lpRasEntry = NULL;
  467. LPRASDEVINFO lpRasDevInfo = NULL;
  468. DWORD dwRasEntrySize;
  469. DWORD dwRasDevInfoSize;
  470. LPLINETRANSLATEOUTPUT lpOutput1 = NULL;
  471. HINSTANCE hRasDll = NULL;
  472. FARPROC fp = NULL;
  473. #if !defined(WIN16)
  474. DWORD dwNumDev;
  475. LPLINETRANSLATEOUTPUT lpOutput2;
  476. LPLINEEXTENSIONID lpExtensionID = NULL;
  477. #endif
  478. //
  479. // Get phone number from connectoid
  480. //
  481. /*#if defined(WIN16)
  482. //
  483. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  484. //
  485. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY)+256);
  486. #else
  487. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY));
  488. #endif
  489. if (!lpRasEntry)
  490. {
  491. hr = ERROR_NOT_ENOUGH_MEMORY;
  492. goto GetDisplayableNumberExit;
  493. }
  494. lpRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  495. if (!lpRasDevInfo)
  496. {
  497. hr = ERROR_NOT_ENOUGH_MEMORY;
  498. goto GetDisplayableNumberExit;
  499. }
  500. dwRasEntrySize = sizeof(RASENTRY);
  501. dwRasDevInfoSize = sizeof(RASDEVINFO);
  502. lpRasEntry->dwSize = dwRasEntrySize;
  503. lpRasDevInfo->dwSize = dwRasDevInfoSize;
  504. */
  505. /*hRasDll = LoadLibrary(RASAPI_LIBRARY);
  506. if (!hRasDll)
  507. {
  508. hr = GetLastError();
  509. goto GetDisplayableNumberExit;
  510. }
  511. fp =GetProcAddress(hRasDll,"RasGetEntryProperties");
  512. if (!fp)
  513. {
  514. FreeLibrary(hRasDll);
  515. hRasDll = LoadLibrary("RNAPH.DLL");
  516. if (!hRasDll)
  517. {
  518. hr = GetLastError();
  519. goto GetDisplayableNumberExit;
  520. }
  521. fp = GetProcAddress(hRasDll,"RasGetEntryProperties");
  522. if (!fp)
  523. {
  524. hr = GetLastError();
  525. goto GetDisplayableNumberExit;
  526. }
  527. }*/
  528. /*
  529. hr = RasGetEntryProperties(NULL,g_pcPDLG->m_pszConnectoid,
  530. #if defined(WIN16)
  531. (LPBYTE)
  532. #endif
  533. lpRasEntry,
  534. &dwRasEntrySize,
  535. (LPBYTE)lpRasDevInfo,&dwRasDevInfoSize);
  536. */
  537. hr = MyRasGetEntryProperties( NULL,
  538. g_pcPDLG->m_pszConnectoid,
  539. &lpRasEntry,
  540. &dwRasEntrySize,
  541. &lpRasDevInfo,
  542. &dwRasDevInfoSize);
  543. if (hr != ERROR_SUCCESS)
  544. {
  545. goto GetDisplayableNumberExit;
  546. }
  547. //FreeLibrary(hRasDll);
  548. //
  549. // If this is a dial as is number, just get it from the structure
  550. //
  551. g_pcPDLG->m_bDialAsIs = !(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes);
  552. if (g_pcPDLG->m_bDialAsIs)
  553. {
  554. if (g_pcPDLG->m_pszDisplayable) GlobalFree(g_pcPDLG->m_pszDisplayable);
  555. g_pcPDLG->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, lstrlen(lpRasEntry->szLocalPhoneNumber)+1);
  556. if (!g_pcPDLG->m_pszDisplayable)
  557. {
  558. hr = ERROR_NOT_ENOUGH_MEMORY;
  559. goto GetDisplayableNumberExit;
  560. }
  561. lstrcpy(g_pcPDLG->m_szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  562. lstrcpy(g_pcPDLG->m_pszDisplayable, lpRasEntry->szLocalPhoneNumber);
  563. }
  564. else
  565. {
  566. //
  567. // If there is no area code, don't use parentheses
  568. //
  569. if (lpRasEntry->szAreaCode[0])
  570. wsprintf(g_pcPDLG->m_szPhoneNumber,TEXT("+%lu (%s) %s\0"),lpRasEntry->dwCountryCode,
  571. lpRasEntry->szAreaCode,lpRasEntry->szLocalPhoneNumber);
  572. else
  573. wsprintf(g_pcPDLG->m_szPhoneNumber,TEXT("+%lu %s\0"),lpRasEntry->dwCountryCode,
  574. lpRasEntry->szLocalPhoneNumber);
  575. #if defined(WIN16)
  576. TCHAR szBuffer[1024];
  577. LONG lRetCode;
  578. memset(&szBuffer[0], 0, sizeof(szBuffer));
  579. lpOutput1 = (LPLINETRANSLATEOUTPUT) & szBuffer[0];
  580. lpOutput1->dwTotalSize = sizeof(szBuffer);
  581. lRetCode = IETapiTranslateAddress(NULL, g_pcPDLG->m_szPhoneNumber,
  582. 0L, 0L, lpOutput1);
  583. if (0 != lRetCode)
  584. {
  585. //
  586. // TODO: Set the correct error code
  587. //
  588. hr = GetLastError();
  589. goto GetDisplayableNumberExit;
  590. }
  591. g_pcPDLG->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR,
  592. ((size_t)lpOutput1->dwDisplayableStringSize+1));
  593. if (!g_pcPDLG->m_pszDisplayable)
  594. {
  595. hr = ERROR_NOT_ENOUGH_MEMORY;
  596. goto GetDisplayableNumberExit;
  597. }
  598. lstrcpy(g_pcPDLG->m_pszDisplayable,
  599. &szBuffer[lpOutput1->dwDisplayableStringOffset]);
  600. #else //WIN16
  601. //
  602. // Initialize TAPIness
  603. //
  604. dwNumDev = 0;
  605. hr = lineInitialize(&g_pcPDLG->m_hLineApp,g_pcPDLG->g_hInst,LineCallback,NULL,&dwNumDev);
  606. if (hr != ERROR_SUCCESS)
  607. goto GetDisplayableNumberExit;
  608. if (g_pdevice->dwTapiDev == 0xFFFFFFFF)
  609. {
  610. g_pdevice->dwTapiDev = 0;
  611. }
  612. lpExtensionID = (LPLINEEXTENSIONID )GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  613. if (!lpExtensionID)
  614. {
  615. hr = ERROR_NOT_ENOUGH_MEMORY;
  616. goto GetDisplayableNumberExit;
  617. }
  618. do {
  619. hr = lineNegotiateAPIVersion(g_pcPDLG->m_hLineApp, g_pdevice->dwTapiDev, 0x00010004, 0x00010004,
  620. &g_pcPDLG->m_dwAPIVersion, lpExtensionID);
  621. } while (hr && g_pdevice->dwTapiDev++ < dwNumDev-1);
  622. // ditch it since we don't use it
  623. //
  624. if (lpExtensionID) GlobalFree(lpExtensionID);
  625. if (hr != ERROR_SUCCESS)
  626. goto GetDisplayableNumberExit;
  627. // Format the phone number
  628. //
  629. lpOutput1 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR,sizeof(LINETRANSLATEOUTPUT));
  630. if (!lpOutput1)
  631. {
  632. hr = ERROR_NOT_ENOUGH_MEMORY;
  633. goto GetDisplayableNumberExit;
  634. }
  635. lpOutput1->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  636. //
  637. // Turn the canonical form into the "displayable" form
  638. //
  639. hr = lineTranslateAddress(g_pcPDLG->m_hLineApp,g_pdevice->dwTapiDev,
  640. g_pcPDLG->m_dwAPIVersion,
  641. g_pcPDLG->m_szPhoneNumber,0,
  642. LINETRANSLATEOPTION_CANCELCALLWAITING,
  643. lpOutput1);
  644. if (hr != ERROR_SUCCESS || (lpOutput1->dwNeededSize != lpOutput1->dwTotalSize))
  645. {
  646. lpOutput2 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR, (size_t)lpOutput1->dwNeededSize);
  647. if (!lpOutput2)
  648. {
  649. hr = ERROR_NOT_ENOUGH_MEMORY;
  650. goto GetDisplayableNumberExit;
  651. }
  652. lpOutput2->dwTotalSize = lpOutput1->dwNeededSize;
  653. GlobalFree(lpOutput1);
  654. lpOutput1 = lpOutput2;
  655. lpOutput2 = NULL;
  656. hr = lineTranslateAddress(g_pcPDLG->m_hLineApp,g_pdevice->dwTapiDev,
  657. g_pcPDLG->m_dwAPIVersion,
  658. g_pcPDLG->m_szPhoneNumber,0,
  659. LINETRANSLATEOPTION_CANCELCALLWAITING,
  660. lpOutput1);
  661. }
  662. if (hr != ERROR_SUCCESS)
  663. {
  664. goto GetDisplayableNumberExit;
  665. }
  666. g_pcPDLG->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, (size_t)lpOutput1->dwDisplayableStringSize+1);
  667. if (!g_pcPDLG->m_pszDisplayable)
  668. {
  669. hr = ERROR_NOT_ENOUGH_MEMORY;
  670. goto GetDisplayableNumberExit;
  671. }
  672. lstrcpyn(g_pcPDLG->m_pszDisplayable,
  673. (LPTSTR)&((LPBYTE)lpOutput1)[lpOutput1->dwDisplayableStringOffset],
  674. lpOutput1->dwDisplayableStringSize / sizeof(TCHAR) );
  675. #endif // WIN16
  676. }
  677. GetDisplayableNumberExit:
  678. if (lpRasEntry) GlobalFree(lpRasEntry);
  679. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  680. #if !defined(WIN16)
  681. if (lpOutput1) GlobalFree(lpOutput1);
  682. if (g_pcPDLG->m_hLineApp) lineShutdown(g_pcPDLG->m_hLineApp);
  683. #endif
  684. return hr;
  685. }
  686. #if defined(WIN16)
  687. //////////////////////////////////////////////////////////////////////////
  688. // The callback proc is called during the connection process. Display
  689. // the connection progress status in the dialer window. When connection
  690. // is complete, change the Cancel button to Disconnect, and change the
  691. // state to connected.
  692. extern "C" void CALLBACK __export DialCallback(UINT uiMsg,
  693. RASCONNSTATE rasState,
  694. DWORD dwErr)
  695. {
  696. if (TRUE == g_bFirstTime)
  697. {
  698. g_bFirstTime = FALSE;
  699. if (RASCS_Disconnected == rasState)
  700. return;
  701. }
  702. //
  703. // WIN 3.1 does not send disconnect event on error!!!
  704. //
  705. if (0 != dwErr)
  706. rasState = RASCS_Disconnected;
  707. PostMessage(g_hDialDlgWnd, WM_RASDIALEVENT, (WPARAM) rasState,
  708. (LPARAM)dwErr);
  709. }
  710. #endif
  711. HRESULT DialDlg()
  712. {
  713. LPRASDIALPARAMS lpRasDialParams = NULL;
  714. LPRASDIALEXTENSIONS lpRasDialExtentions = NULL;
  715. HRESULT hr = ERROR_SUCCESS;
  716. BOOL bPW;
  717. // Get connectoid information
  718. //
  719. lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR,sizeof(RASDIALPARAMS));
  720. if (!lpRasDialParams)
  721. {
  722. hr = ERROR_NOT_ENOUGH_MEMORY;
  723. goto DialExit;
  724. }
  725. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  726. lstrcpyn(lpRasDialParams->szEntryName,g_pcPDLG->m_pszConnectoid,
  727. ARRAYSIZE(lpRasDialParams->szEntryName));
  728. bPW = FALSE;
  729. hr = RasGetEntryDialParams(NULL,lpRasDialParams,&bPW);
  730. if (hr != ERROR_SUCCESS)
  731. {
  732. goto DialExit;
  733. }
  734. //
  735. // This is only used on WINNT
  736. //
  737. lpRasDialExtentions = (LPRASDIALEXTENSIONS)GlobalAlloc(GPTR,sizeof(RASDIALEXTENSIONS));
  738. if (lpRasDialExtentions)
  739. {
  740. lpRasDialExtentions->dwSize = sizeof(RASDIALEXTENSIONS);
  741. lpRasDialExtentions->dwfOptions = RDEOPT_UsePrefixSuffix;
  742. }
  743. // Add the user's password
  744. //
  745. GetPrivateProfileString(
  746. INFFILE_USER_SECTION,INFFILE_PASSWORD,
  747. NULLSZ,lpRasDialParams->szPassword,PWLEN + 1,pszINSFileName);
  748. #if defined(WIN16)
  749. if (g_pcPDLG->m_bDialAsIs)
  750. {
  751. Dprintf("CONNECT: Dialing as is <%s>\n", g_pcPDLG->m_szPhoneNumber);
  752. lstrcpy(lpRasDialParams->szPhoneNumber, g_pcPDLG->m_szPhoneNumber);
  753. }
  754. else
  755. {
  756. //
  757. // Translate the number in canonical format to a dialable string
  758. //
  759. TCHAR szBuffer[1024];
  760. LONG lRetCode;
  761. LPLINETRANSLATEOUTPUT lpLine;
  762. memset(&szBuffer[0], 0, sizeof(szBuffer));
  763. lpLine = (LPLINETRANSLATEOUTPUT) & szBuffer[0];
  764. lpLine->dwTotalSize = sizeof(szBuffer);
  765. lRetCode = IETapiTranslateAddress(NULL, g_pcPDLG->m_szPhoneNumber,
  766. 0L, 0L, lpLine);
  767. Dprintf("CONNECT2: Dialable string retured by IETAPI is <%s>\n",
  768. (LPTSTR) &szBuffer[lpLine->dwDialableStringOffset]);
  769. lstrcpy(lpRasDialParams->szPhoneNumber,
  770. &szBuffer[lpLine->dwDialableStringOffset]);
  771. }
  772. #endif
  773. // Dial connectoid
  774. //
  775. g_pcPDLG->m_hrasconn = NULL;
  776. #if defined(WIN16)
  777. lpfnCallback = MakeProcInstance((FARPROC)DialCallback, g_pcPDLG->g_hInst);
  778. hr = RasDial(lpRasDialExtentions, NULL,lpRasDialParams,0,
  779. (LPVOID)lpfnCallback,
  780. &g_pcPDLG->m_hrasconn);
  781. #else
  782. hr = RasDial(lpRasDialExtentions,NULL,lpRasDialParams,0xFFFFFFFF,
  783. (LPVOID)g_pcPDLG->m_hwnd,
  784. &g_pcPDLG->m_hrasconn);
  785. #endif
  786. if (hr != ERROR_SUCCESS)
  787. {
  788. if (g_pcPDLG->m_hrasconn)
  789. {
  790. RasHangUp(g_pcPDLG->m_hrasconn);
  791. }
  792. goto DialExit;
  793. }
  794. DialExit:
  795. if (lpRasDialParams) GlobalFree(lpRasDialParams);
  796. if (lpRasDialExtentions) GlobalFree(lpRasDialExtentions);
  797. return hr;
  798. }