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.

1607 lines
44 KiB

  1. /*-----------------------------------------------------------------------------
  2. dialerr.cpp
  3. This file implements the Could Not Connect dialog
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved
  6. Authors:
  7. ChrisK Chris Kauffman
  8. Histroy:
  9. 7/22/96 ChrisK Cleaned and formatted
  10. 8/19/96 ValdonB Added ability to edit phone number
  11. Fixed some memory leaks
  12. -----------------------------------------------------------------------------*/
  13. #include "pch.hpp"
  14. #include "globals.h"
  15. #if defined(WIN16)
  16. #include <string.h>
  17. #include <ietapi.h>
  18. #endif
  19. TCHAR szBuf256[256];
  20. TCHAR szValidPhoneCharacters[] = {TEXT("0123456789AaBbCcDdPpTtWw!@$ -.()+*#,&\0")};
  21. #ifdef WIN16
  22. #define g_iMyMaxPhone 36
  23. #else
  24. int g_iMyMaxPhone = 0;
  25. #define MAXPHONE_NT 80
  26. #define MAXPHONE_95 36
  27. #endif
  28. PDIALERR g_pcDialErr = NULL;
  29. //////////////////////////////////////////////////////////////////////////
  30. // Keyboard hook
  31. static HHOOK hKeyHook = NULL; // our key hook
  32. static HOOKPROC hpKey = NULL; // hook proc
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Function: ProcessDBCS
  36. //
  37. // Synopsis: Converts control to use DBCS compatible font
  38. // Use this at the beginning of the dialog procedure
  39. //
  40. // Note that this is required due to a bug in Win95-J that prevents
  41. // it from properly mapping MS Shell Dlg. This hack is not needed
  42. // under winNT.
  43. //
  44. // Arguments: hwnd - Window handle of the dialog
  45. // cltID - ID of the control you want changed.
  46. //
  47. // Returns: ERROR_SUCCESS
  48. //
  49. // History: 4/31/97 a-frankh Created
  50. // 5/13/97 jmazner Stole from CM to use here
  51. //----------------------------------------------------------------------------
  52. void ProcessDBCS(HWND hDlg, int ctlID)
  53. {
  54. #if defined(WIN16)
  55. return;
  56. #else
  57. HFONT hFont = NULL;
  58. if( IsNT() )
  59. {
  60. return;
  61. }
  62. hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  63. if (hFont == NULL)
  64. hFont = (HFONT) GetStockObject(SYSTEM_FONT);
  65. if (hFont != NULL)
  66. SendMessage(GetDlgItem(hDlg,ctlID), WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
  67. #endif
  68. }
  69. HRESULT ShowDialErrDialog(PGATHEREDINFO pGI, HRESULT hrErr,
  70. LPTSTR pszConnectoid, HINSTANCE hInst,
  71. HWND hwnd)
  72. {
  73. int iRC;
  74. // CDialErrDlg *pcDED = NULL;
  75. g_pcDialErr = (PDIALERR)GlobalAlloc(GPTR,sizeof(DIALERR));
  76. if (!g_pcDialErr)
  77. {
  78. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  79. iRC = ERROR_NOT_ENOUGH_MEMORY;
  80. goto ShowDialErrDialogExit;
  81. }
  82. g_pcDialErr->m_pszConnectoid = (LPTSTR)GlobalAlloc(GPTR,RAS_MaxEntryName+1);
  83. if (!g_pcDialErr->m_pszConnectoid)
  84. {
  85. iRC = ERROR_NOT_ENOUGH_MEMORY;
  86. goto ShowDialErrDialogExit;
  87. }
  88. lstrcpy(g_pcDialErr->m_pszConnectoid,pszConnectoid);
  89. g_pcDialErr->m_pGI = pGI;
  90. g_pcDialErr->m_hrError = hrErr;
  91. g_pcDialErr->m_hInst = hInst;
  92. #if defined(WIN16)
  93. #define DLGPROC16 DLGPROC // Identify as only cast for Win16
  94. DLGPROC dlgprc;
  95. dlgprc = (DLGPROC16) MakeProcInstance((FARPROC)DialErrDlgProc,
  96. g_pcDialErr->m_hInst);
  97. iRC = DialogBoxParam(g_pcDialErr->m_hInst,
  98. MAKEINTRESOURCE(IDD_DIALERR),
  99. hwnd, dlgprc, (LPARAM)g_pcDialErr);
  100. FreeProcInstance((FARPROC) dlgprc);
  101. #else
  102. iRC = (HRESULT)DialogBoxParam(g_pcDialErr->m_hInst,MAKEINTRESOURCE(IDD_DIALERR),
  103. hwnd, DialErrDlgProc,
  104. (LPARAM)g_pcDialErr);
  105. #endif
  106. ShowDialErrDialogExit:
  107. if (g_pcDialErr->m_pszConnectoid) GlobalFree(g_pcDialErr->m_pszConnectoid);
  108. if (g_pcDialErr->m_pszDisplayable) GlobalFree(g_pcDialErr->m_pszDisplayable);
  109. if (g_pcDialErr->m_lprasdevinfo) GlobalFree(g_pcDialErr->m_lprasdevinfo);
  110. g_pcDialErr->m_lprasdevinfo = NULL;
  111. if (g_pcDialErr) GlobalFree(g_pcDialErr);
  112. g_pcDialErr = NULL;
  113. return iRC;
  114. }
  115. //+----------------------------------------------------------------------------
  116. //
  117. // Function LclSetEntryScriptPatch
  118. //
  119. // Synopsis Softlink to RasSetEntryPropertiesScriptPatch
  120. //
  121. // Arguments see RasSetEntryPropertiesScriptPatch
  122. //
  123. // Returns see RasSetEntryPropertiesScriptPatch
  124. //
  125. // Histroy 10/3/96 ChrisK Created
  126. //
  127. //-----------------------------------------------------------------------------
  128. BOOL LclSetEntryScriptPatch(LPTSTR lpszScript,LPTSTR lpszEntry)
  129. {
  130. HINSTANCE hinst = NULL;
  131. LCLSETENTRYSCRIPTPATCH fp = NULL;
  132. BOOL bRC = FALSE;
  133. hinst = LoadLibrary(TEXT("ICWDIAL.DLL"));
  134. if (hinst)
  135. {
  136. fp = (LCLSETENTRYSCRIPTPATCH)GetProcAddress(hinst,"RasSetEntryPropertiesScriptPatch");
  137. if (fp)
  138. bRC = (fp)(lpszScript,lpszEntry);
  139. FreeLibrary(hinst);
  140. hinst = NULL;
  141. fp = NULL;
  142. }
  143. return bRC;
  144. }
  145. // ############################################################################
  146. // HelpKybdHookProc
  147. //
  148. // Keyboard hook proc - check for F1, and if detected, fake a Help button
  149. // hit to the main dialog.
  150. //
  151. // Paramters:
  152. // iCode Windows message code
  153. // wParam Windows wParam (contains virtual key code)
  154. // lParam Windows lParam
  155. //
  156. // History:
  157. // 8/26/96 ValdonB Adapted from IEDIAL.C
  158. //
  159. // ############################################################################
  160. #if defined(WIN16)
  161. LRESULT CALLBACK _export HelpKybdHookProc
  162. #else
  163. LRESULT WINAPI HelpKybdHookProc
  164. #endif
  165. (
  166. int iCode,
  167. WPARAM wParam,
  168. LPARAM lParam
  169. )
  170. {
  171. LRESULT lRet = 0;
  172. Assert(g_pcDialErr->m_hwnd);
  173. if ((iCode != HC_NOREMOVE && iCode >= 0) &&
  174. (GetActiveWindow() == g_pcDialErr->m_hwnd))
  175. {
  176. // HC_NOREMOVE indicates that message is being
  177. // retrieved using PM_NOREMOVE from peek message,
  178. // if iCode < 0, then we should not process... dont
  179. // know why, but sdk says so.
  180. if (wParam == VK_F1 && !(lParam & 0x80000000L))
  181. {
  182. // bit 32 == 1 if key is being release, else 0 if
  183. // key is being pressed
  184. PostMessage(g_pcDialErr->m_hwnd, WM_COMMAND, (WPARAM)IDC_CMDHELP, 0);
  185. }
  186. }
  187. if (hKeyHook)
  188. {
  189. lRet = CallNextHookEx(hKeyHook, iCode, wParam, lParam);
  190. }
  191. return(lRet);
  192. }
  193. // ############################################################################
  194. // HelpInit
  195. //
  196. // Install a windows hook proc to launch help on F1
  197. //
  198. // History:
  199. // 8/26/96 ValdonB Adapted from IEDIAL.C
  200. //
  201. // ############################################################################
  202. static void HelpInit()
  203. {
  204. // now install the hook for the keyboard filter
  205. hpKey = (HOOKPROC)MakeProcInstance((FARPROC)HelpKybdHookProc,
  206. g_pcDialErr->m_hInst);
  207. if (hpKey)
  208. {
  209. hKeyHook = SetWindowsHookEx(WH_KEYBOARD, hpKey, g_pcDialErr->m_hInst,
  210. #if defined(WIN16)
  211. GetCurrentTask());
  212. #else
  213. GetCurrentThreadId());
  214. #endif
  215. }
  216. }
  217. // ############################################################################
  218. // HelpShutdown
  219. //
  220. // Shutdown the keyboard hook
  221. //
  222. // History:
  223. // 8/26/96 ValdonB Adapted from IEDIAL.C
  224. //
  225. // ############################################################################
  226. static void HelpShutdown()
  227. {
  228. // remove the hook
  229. if (hKeyHook)
  230. {
  231. UnhookWindowsHookEx(hKeyHook);
  232. }
  233. // dump the thunk
  234. if (hpKey)
  235. {
  236. FreeProcInstance((FARPROC)hpKey);
  237. }
  238. }
  239. extern "C" INT_PTR CALLBACK FAR PASCAL DialErrDlgProc(HWND hwnd,
  240. UINT uMsg,
  241. WPARAM wparam,
  242. LPARAM lparam)
  243. {
  244. BOOL bRes = TRUE;
  245. HRESULT hr;
  246. //LPLINEEXTENSIONID lpExtensionID;
  247. #if !defined(WIN16)
  248. DWORD dwNumDev;
  249. #endif
  250. //RNAAPI *pcRNA = NULL;
  251. WORD wIDS;
  252. LRESULT idx;
  253. LPRASENTRY lpRasEntry = NULL;
  254. LPRASDEVINFO lpRasDevInfo = NULL;
  255. DWORD dwRasEntrySize;
  256. DWORD dwRasDevInfoSize;
  257. HINSTANCE hRasDll = NULL;
  258. FARPROC fp = NULL;
  259. LPTSTR lpszDialNumber = NULL;
  260. static BOOL bCheckDisplayable = FALSE;
  261. static BOOL bInitComplete = FALSE; // if we initialize the dialog - MKarki
  262. static BOOL bDlgPropEnabled = TRUE; //this flags holds state of Dialing Properties PushButton MKarki - (5/3/97/) Fix for Bug#3393
  263. #if defined(WIN16)
  264. RECT MyRect;
  265. RECT DTRect;
  266. #endif
  267. RNAAPI *pRnaapi = NULL;
  268. static BOOL fUserEditedNumber = FALSE;
  269. switch(uMsg)
  270. {
  271. case WM_INITDIALOG:
  272. g_pcDialErr->m_hwnd = hwnd;
  273. #if defined(WIN16)
  274. //
  275. // Move the window to the center of the screen
  276. //
  277. GetWindowRect(hwnd, &MyRect);
  278. GetWindowRect(GetDesktopWindow(), &DTRect);
  279. MoveWindow(hwnd, (DTRect.right - MyRect.right) / 2, (DTRect.bottom - MyRect.bottom) /2,
  280. MyRect.right, MyRect.bottom, FALSE);
  281. SetNonBoldDlg(hwnd);
  282. #endif
  283. // Set limit on phone number length
  284. // Note: this should really be RAS_MaxPhoneNumber (128), but RAS is choking on
  285. // anything longer than 100 bytes, so we'll have to limit it to that.
  286. //
  287. // 6/3/97 jmazner Olympus #4851
  288. // RAS has different limits on w95 and NT
  289. //
  290. #ifndef WIN16
  291. if( IsNT() )
  292. {
  293. g_iMyMaxPhone = MAXPHONE_NT;
  294. }
  295. else
  296. {
  297. g_iMyMaxPhone = MAXPHONE_95;
  298. }
  299. #endif
  300. AssertSz( (sizeof(g_pcDialErr->m_szPhoneNumber) >= g_iMyMaxPhone), "Maximum phone number is greater than m_szPhoneNumber" );
  301. SendDlgItemMessage(hwnd,IDC_TEXTNUMBER,EM_SETLIMITTEXT,g_iMyMaxPhone,0);
  302. // Show the phone number
  303. //
  304. hr = DialErrGetDisplayableNumber();
  305. if (hr != ERROR_SUCCESS)
  306. {
  307. bCheckDisplayable = FALSE;
  308. SetDlgItemText(hwnd,IDC_TEXTNUMBER,g_pcDialErr->m_szPhoneNumber);
  309. } else {
  310. bCheckDisplayable = TRUE;
  311. SetDlgItemText(hwnd,IDC_TEXTNUMBER,g_pcDialErr->m_pszDisplayable);
  312. }
  313. MakeBold(GetDlgItem(hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  314. // Fill in error message
  315. //
  316. wIDS = (WORD)RasErrorToIDS(g_pcDialErr->m_hrError);
  317. AssertSz(wIDS != -1,"RasErrorToIDS got an error message it did not understand");
  318. if (wIDS != -1 && wIDS !=0)
  319. SetDlgItemText(hwnd,IDC_LBLERRMSG,GetSz(wIDS));
  320. ProcessDBCS(hwnd,IDC_CMBMODEMS);
  321. ProcessDBCS(hwnd,IDC_TEXTNUMBER);
  322. FillModems();
  323. // Set the focus to the Modems selection list
  324. //
  325. SetFocus(GetDlgItem(hwnd,IDC_CMBMODEMS));
  326. // hook the keyboard for F1 help
  327. HelpInit();
  328. bRes = FALSE;
  329. //
  330. // we should disable the Dialing Properites PushButton
  331. // if we have changed the phone number once
  332. // MKarki (5/3/97) - Fix for Bug#3393
  333. //
  334. if (FALSE == bDlgPropEnabled)
  335. {
  336. EnableWindow (
  337. GetDlgItem (hwnd, IDC_CMDDIALPROP),
  338. FALSE
  339. );
  340. }
  341. //
  342. // This shows the INIT for the error dialog is complete
  343. // and we can start processing changes to Ph No. TEXTBOX
  344. // MKarki (4/24/97) - Fix for Bug#3511
  345. //
  346. bInitComplete = TRUE;
  347. break;
  348. #if defined(WIN16)
  349. case WM_SYSCOLORCHANGE:
  350. Ctl3dColorChange();
  351. break;
  352. #endif
  353. case WM_DESTROY:
  354. ReleaseBold(GetDlgItem(hwnd,IDC_LBLTITLE));
  355. #ifdef WIN16
  356. DeleteDlgFont(hwnd);
  357. #endif
  358. // Shutdown the keyboard hook
  359. HelpShutdown();
  360. bRes = FALSE;
  361. break;
  362. case WM_CLOSE:
  363. //if (MessageBox(hwnd,GetSz(IDS_WANTTOEXIT),GetSz(IDS_TITLE),
  364. // MB_APPLMODAL | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
  365. // EndDialog(hwnd,ERROR_USERCANCEL);
  366. EndDialog(hwnd,ERROR_USERCANCEL);
  367. break;
  368. #if !defined(WIN16)
  369. case WM_HELP:
  370. //
  371. // Chrisk Olympus 5130 5/27/97
  372. // Added support for F1 Help Key
  373. //
  374. WinHelp(hwnd,TEXT("connect.hlp>proc4"),HELP_CONTEXT,(DWORD)ICW_TRB);
  375. #endif
  376. case WM_COMMAND:
  377. switch(LOWORD(wparam))
  378. {
  379. //
  380. // We now processes changes to ph no. EDIT BOX
  381. // If there is anychange in the phone number we
  382. // disable to Dialing Properties Push Button
  383. // MKarki (3/22/97) - Fix for Bug #3511
  384. //
  385. case IDC_TEXTNUMBER:
  386. TCHAR lpszTempNumber[RAS_MaxPhoneNumber +1];
  387. if ((HIWORD (wparam) == EN_CHANGE) && (bInitComplete == TRUE))
  388. {
  389. if ((GetDlgItemText (
  390. hwnd,
  391. IDC_TEXTNUMBER,
  392. lpszTempNumber,
  393. RAS_MaxPhoneNumber
  394. )) &&
  395. (0 != lstrcmp(
  396. lpszTempNumber,
  397. bCheckDisplayable ? g_pcDialErr->m_pszDisplayable :g_pcDialErr->m_szPhoneNumber)))
  398. {
  399. //
  400. // number has been modified by the user
  401. // hide the Dialing Properties Push Button
  402. //
  403. EnableWindow (
  404. GetDlgItem (hwnd, IDC_CMDDIALPROP),
  405. FALSE
  406. );
  407. //
  408. // save the state of the Dialing Properties PushButton
  409. // MKarki (5/3/97) - Fix for Bug#3393
  410. //
  411. bDlgPropEnabled = FALSE;
  412. //
  413. // 7/17/97 jmazner Olympus #8234
  414. //
  415. fUserEditedNumber = TRUE;
  416. }
  417. }
  418. break;
  419. case IDC_CMBMODEMS:
  420. if (HIWORD(wparam) == CBN_SELCHANGE)
  421. {
  422. idx = SendDlgItemMessage(hwnd,IDC_CMBMODEMS,CB_GETCURSEL,0,0);
  423. //
  424. // ChrisK Olympus 245 5/25/97
  425. // Get index of modem
  426. //
  427. idx = SendDlgItemMessage(hwnd,IDC_CMBMODEMS,CB_GETITEMDATA,idx,0);
  428. if (idx == CB_ERR) break;
  429. // Get the connectoid
  430. //
  431. /***** this code is made obsolete by the call to MyRasGetEntryProperties below
  432. #if defined(WIN16)
  433. //
  434. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  435. //
  436. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY)+256);
  437. #else
  438. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY));
  439. #endif
  440. if (!lpRasEntry)
  441. {
  442. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  443. break;
  444. }
  445. lpRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  446. if (!lpRasDevInfo)
  447. {
  448. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  449. break;
  450. }
  451. dwRasEntrySize = sizeof(RASENTRY);
  452. dwRasDevInfoSize = sizeof(RASDEVINFO);
  453. lpRasEntry->dwSize = dwRasEntrySize;
  454. lpRasDevInfo->dwSize = dwRasDevInfoSize;
  455. *******/
  456. /* hRasDll = LoadLibrary(RASAPI_LIBRARY);
  457. if (!hRasDll)
  458. {
  459. hr = GetLastError();
  460. break;
  461. }
  462. fp =GetProcAddress(hRasDll,"RasGetEntryPropertiesA");
  463. if (!fp)
  464. {
  465. FreeLibrary(hRasDll);
  466. hRasDll = LoadLibrary(TEXT("RNAPH.DLL"));
  467. if (!hRasDll)
  468. {
  469. hr = GetLastError();
  470. break;
  471. }
  472. fp = GetProcAddress(hRasDll,"RasGetEntryPropertiesA");
  473. if (!fp)
  474. {
  475. hr = GetLastError();
  476. break;
  477. }
  478. }
  479. */
  480. /****** this call has been replaced with MyRasGetEntryProperties
  481. hr = RasGetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,
  482. #if defined(WIN16)
  483. (LPBYTE)
  484. #endif
  485. lpRasEntry,
  486. &dwRasEntrySize,
  487. (LPBYTE)lpRasDevInfo,
  488. &dwRasDevInfoSize);
  489. ****/
  490. // these two pointers should not have memory allocated to them
  491. // See MyRasGetEntryProperties function comment for details.
  492. if( lpRasEntry )
  493. {
  494. GlobalFree( lpRasEntry );
  495. lpRasEntry = NULL;
  496. }
  497. if( lpRasDevInfo )
  498. {
  499. GlobalFree( lpRasDevInfo );
  500. lpRasDevInfo = NULL;
  501. }
  502. hr = MyRasGetEntryProperties( NULL,
  503. g_pcDialErr->m_pszConnectoid,
  504. &lpRasEntry,
  505. &dwRasEntrySize,
  506. &lpRasDevInfo,
  507. &dwRasDevInfoSize);
  508. if (hr != ERROR_SUCCESS)
  509. {
  510. break;
  511. }
  512. //
  513. // Replace the device with a new one
  514. //
  515. lstrcpyn(lpRasEntry->szDeviceType,g_pcDialErr->m_lprasdevinfo[idx].szDeviceType,RAS_MaxDeviceType+1);
  516. lstrcpyn(lpRasEntry->szDeviceName,g_pcDialErr->m_lprasdevinfo[idx].szDeviceName,RAS_MaxDeviceName+1);
  517. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  518. lpRasDevInfo = NULL;
  519. // DANGER!! Don't call GlobalFree on lpRasDevInfo after we set it below!!!!!!! --jmazner
  520. lpRasDevInfo = &g_pcDialErr->m_lprasdevinfo[idx];
  521. dwRasDevInfoSize = sizeof(RASDEVINFO);
  522. //hr = pcRNA->RasSetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,(LPBYTE)lpRasEntry,dwRasEntrySize,(LPBYTE)lpRasDevInfo,dwRasDevInfoSize);
  523. /*fp = GetProcAddress(hRasDll,"RasSetEntryPropertiesA");
  524. if (!fp)
  525. {
  526. hr = GetLastError();
  527. break;
  528. }*/
  529. // softlink to RasSetEntryProperties for simultaneous Win95/NT compatability
  530. if( !pRnaapi )
  531. {
  532. pRnaapi = new RNAAPI;
  533. if( !pRnaapi )
  534. {
  535. hr = ERROR_NOT_ENOUGH_MEMORY;
  536. break;
  537. }
  538. }
  539. hr = pRnaapi->RasSetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,
  540. (LPBYTE)lpRasEntry,
  541. dwRasEntrySize,
  542. (LPBYTE)lpRasDevInfo,
  543. dwRasDevInfoSize);
  544. #if !defined(WIN16)
  545. LclSetEntryScriptPatch(lpRasEntry->szScript,g_pcDialErr->m_pszConnectoid);
  546. #endif // !win16
  547. // Now that we're done with lpRasDevInfo, set it to NULL, but DON'T free it,
  548. // because it points to memory owned by g_pcDialErr->m_lprasdevinfo
  549. lpRasDevInfo = NULL;
  550. if (hr != ERROR_SUCCESS)
  551. {
  552. MessageBox(hwnd,GetSz(IDS_CANTSAVEKEY),GetSz(IDS_TITLE),MB_MYERROR);
  553. break;
  554. }
  555. /*FreeLibrary(hRasDll);
  556. hRasDll = NULL;
  557. fp = NULL;*/
  558. }
  559. break;
  560. case IDC_CMDHELP:
  561. #if defined(WIN16)
  562. WinHelp(hwnd,"connect.hlp",HELP_CONTEXT,(DWORD)1001);
  563. #else
  564. WinHelp(hwnd,TEXT("connect.hlp>proc4"),HELP_CONTEXT,(DWORD)1001);
  565. #endif
  566. break;
  567. case IDC_CMDNEXT:
  568. // NOTE: This button is actually labeled "Redial"
  569. //
  570. lpszDialNumber = (LPTSTR)GlobalAlloc(GPTR, (RAS_MaxPhoneNumber + 1) * sizeof(TCHAR));
  571. if (NULL == lpszDialNumber)
  572. {
  573. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_MYERROR);
  574. break;
  575. }
  576. // If the user has altered the phone number, make sure it can be used
  577. //
  578. if (fUserEditedNumber &&
  579. (GetDlgItemText(hwnd, IDC_TEXTNUMBER, lpszDialNumber, RAS_MaxPhoneNumber)) &&
  580. (0 != lstrcmp(lpszDialNumber, bCheckDisplayable ? g_pcDialErr->m_pszDisplayable : g_pcDialErr->m_szPhoneNumber)))
  581. {
  582. // Check that the phone number only contains valid characters
  583. //
  584. LPTSTR lpNum, lpValid;
  585. for (lpNum = lpszDialNumber;*lpNum;lpNum++)
  586. {
  587. for(lpValid = szValidPhoneCharacters;*lpValid;lpValid++)
  588. {
  589. if (*lpNum == *lpValid)
  590. break; // p2 for loop
  591. }
  592. if (!*lpValid) break; // p for loop
  593. }
  594. if (*lpNum)
  595. {
  596. MessageBox(hwnd,GetSz(IDS_INVALIDPHONE),GetSz(IDS_TITLE),MB_MYERROR);
  597. //
  598. // Set the focus back to the phone number field
  599. //
  600. SetFocus(GetDlgItem(hwnd,IDC_TEXTNUMBER));
  601. break; // switch statement
  602. }
  603. /**** replaced by call to MyRasGetEntryProperties below
  604. #if defined(WIN16)
  605. //
  606. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  607. //
  608. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY)+256);
  609. #else
  610. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY));
  611. #endif
  612. if (!lpRasEntry)
  613. {
  614. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_MYERROR);
  615. break;
  616. }
  617. lpRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  618. if (!lpRasDevInfo)
  619. {
  620. MessageBox(hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_MYERROR);
  621. break;
  622. }
  623. dwRasEntrySize = sizeof(RASENTRY);
  624. dwRasDevInfoSize = sizeof(RASDEVINFO);
  625. lpRasEntry->dwSize = dwRasEntrySize;
  626. lpRasDevInfo->dwSize = dwRasDevInfoSize;
  627. hr = RasGetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,
  628. #if defined(WIN16)
  629. (LPBYTE)
  630. #endif
  631. lpRasEntry,
  632. &dwRasEntrySize,
  633. (LPBYTE)lpRasDevInfo,
  634. &dwRasDevInfoSize);
  635. ****/
  636. // these two pointers should not have memory allocated to them
  637. // See MyRasGetEntryProperties function comment for details.
  638. if( lpRasEntry )
  639. {
  640. GlobalFree( lpRasEntry );
  641. lpRasEntry = NULL;
  642. }
  643. if( lpRasDevInfo )
  644. {
  645. GlobalFree( lpRasDevInfo );
  646. lpRasDevInfo = NULL;
  647. }
  648. dwRasEntrySize = dwRasDevInfoSize = 0;
  649. hr = MyRasGetEntryProperties( NULL,
  650. g_pcDialErr->m_pszConnectoid,
  651. &lpRasEntry,
  652. &dwRasEntrySize,
  653. &lpRasDevInfo,
  654. &dwRasDevInfoSize);
  655. if (hr != ERROR_SUCCESS)
  656. {
  657. break;
  658. }
  659. // Replace the phone number with the new one
  660. //
  661. lstrcpy(lpRasEntry->szLocalPhoneNumber, lpszDialNumber);
  662. lpRasEntry->dwCountryID = 0;
  663. lpRasEntry->dwCountryCode = 0;
  664. lpRasEntry->szAreaCode[0] = '\0';
  665. // Set to dial as is
  666. //
  667. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  668. // softlink to RasSetEntryProperties for simultaneous Win95/NT compatability
  669. if( !pRnaapi )
  670. {
  671. pRnaapi = new RNAAPI;
  672. if( !pRnaapi )
  673. {
  674. hr = ERROR_NOT_ENOUGH_MEMORY;
  675. break;
  676. }
  677. }
  678. hr = pRnaapi->RasSetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,
  679. (LPBYTE)lpRasEntry,
  680. dwRasEntrySize,
  681. (LPBYTE)lpRasDevInfo,
  682. dwRasDevInfoSize);
  683. #if !defined(WIN16)
  684. LclSetEntryScriptPatch(lpRasEntry->szScript,g_pcDialErr->m_pszConnectoid);
  685. #endif // !win16
  686. if (hr != ERROR_SUCCESS)
  687. {
  688. MessageBox(hwnd,GetSz(IDS_CANTSAVEKEY),GetSz(IDS_TITLE),MB_MYERROR);
  689. break;
  690. }
  691. }
  692. EndDialog(hwnd,ERROR_USERNEXT);
  693. break;
  694. case IDC_CMDCANCEL:
  695. //if (MessageBox(hwnd,GetSz(IDS_WANTTOEXIT),GetSz(IDS_TITLE),
  696. // MB_APPLMODAL | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
  697. // EndDialog(hwnd,ERROR_USERCANCEL);
  698. EndDialog(hwnd,ERROR_USERCANCEL);
  699. break;
  700. case IDC_CMDDIALPROP:
  701. // 12/4/96 jmazner Normandy #10294
  702. //ShowWindow(hwnd,SW_HIDE);
  703. EnableWindow(hwnd, FALSE);
  704. #if defined(WIN16)
  705. hr = IETapiTranslateDialog(hwnd,
  706. g_pcDialErr->m_szPhoneNumber,
  707. NULL);
  708. #else
  709. // 10/24/96 jmazner Normandy #10185/7019
  710. if (g_pdevice->dwTapiDev == 0xFFFFFFFF) g_pdevice->dwTapiDev = 0;
  711. hr = lineInitialize(&g_pcDialErr->m_hLineApp,g_pcDialErr->m_hInst,
  712. LineCallback,NULL,&dwNumDev);
  713. if (hr == ERROR_SUCCESS)
  714. {
  715. hr = lineTranslateDialog(g_pcDialErr->m_hLineApp,
  716. g_pdevice->dwTapiDev,
  717. g_pcDialErr->m_dwAPIVersion,
  718. hwnd,g_pcDialErr->m_szPhoneNumber);
  719. #endif
  720. hr = DialErrGetDisplayableNumber();
  721. if (hr != ERROR_SUCCESS)
  722. {
  723. bCheckDisplayable = FALSE;
  724. SetDlgItemText(hwnd,IDC_TEXTNUMBER,g_pcDialErr->m_szPhoneNumber);
  725. } else {
  726. bCheckDisplayable = TRUE;
  727. SetDlgItemText(hwnd,IDC_TEXTNUMBER,g_pcDialErr->m_pszDisplayable);
  728. }
  729. #if !defined(WIN16)
  730. lineShutdown(g_pcDialErr->m_hLineApp);
  731. g_pcDialErr->m_hLineApp = NULL;
  732. }
  733. #endif
  734. // 12/4/96 jmazner Normandy #10294
  735. //ShowWindow(hwnd,SW_SHOW);
  736. EnableWindow(hwnd, TRUE);
  737. //
  738. // 6/6/97 jmazner Olympus #4759
  739. //
  740. SetFocus(GetDlgItem(hwnd,IDC_CMDNEXT));
  741. break;
  742. }
  743. break;
  744. default:
  745. bRes = FALSE;
  746. break;
  747. }
  748. if (lpRasEntry) GlobalFree(lpRasEntry);
  749. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  750. if (lpszDialNumber) GlobalFree(lpszDialNumber);
  751. if (pRnaapi) delete pRnaapi;
  752. return bRes;
  753. }
  754. HRESULT FillModems()
  755. {
  756. //RNAAPI *pcRNA = NULL;
  757. HRESULT hr = ERROR_SUCCESS;
  758. //LPRASDEVINFO lprasdevinfo;
  759. DWORD dwSize;
  760. DWORD dwNumDev;
  761. DWORD idx;
  762. DWORD dwTempNumEntries;
  763. //HINSTANCE hRasDll=NULL;
  764. //FARPROC fp=NULL;
  765. LPRASENTRY lpRasEntry=NULL;
  766. LPRASDEVINFO lpRasDevInfo=NULL;
  767. DWORD dwRasEntrySize = 0;
  768. DWORD dwRasDevInfoSize = 0;
  769. LRESULT lLast = 0;
  770. RNAAPI *pRnaapi = NULL;
  771. // Get the connectoid
  772. //
  773. /******* This code has been obsoleted by the call to MyRasGetEntryProperties below
  774. #if defined(WIN16)
  775. //
  776. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  777. //
  778. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY)+256);
  779. #else
  780. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY));
  781. #endif
  782. if (!lpRasEntry)
  783. {
  784. MessageBox(g_pcDialErr->m_hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  785. goto FillModemExit;
  786. }
  787. lpRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  788. if (!lpRasDevInfo)
  789. {
  790. MessageBox(g_pcDialErr->m_hwnd,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  791. goto FillModemExit;
  792. }
  793. dwRasEntrySize = sizeof(RASENTRY);
  794. dwRasDevInfoSize = sizeof(RASDEVINFO);
  795. lpRasEntry->dwSize = dwRasEntrySize;
  796. lpRasDevInfo->dwSize = dwRasDevInfoSize;
  797. *********/
  798. /* fp = NULL;
  799. hRasDll = LoadLibrary(RASAPI_LIBRARY);
  800. if (hRasDll)
  801. {
  802. fp = GetProcAddress(hRasDll,RASAPI_RASGETENTRY);
  803. if (!fp)
  804. {
  805. FreeLibrary(hRasDll);
  806. hRasDll = LoadLibrary(RNAPH_LIBRARY);
  807. if (hRasDll)
  808. {
  809. fp = GetProcAddress(hRasDll,RASAPI_RASGETENTRY);
  810. }
  811. }
  812. }
  813. if (!fp)
  814. {
  815. hr = GetLastError();
  816. goto FillModemExit;
  817. }
  818. */
  819. /****** This call has been replaced by MyRasGetEntryProperties below
  820. hr = RasGetEntryProperties(NULL,g_pcDialErr->m_pszConnectoid,
  821. #if defined(WIN16)
  822. (LPBYTE)
  823. #endif
  824. lpRasEntry,
  825. &dwRasEntrySize,(LPBYTE)lpRasDevInfo,
  826. &dwRasDevInfoSize);
  827. ********/
  828. // these two pointers should not have memory allocated to them
  829. // See MyRasGetEntryProperties function comment for details.
  830. if( lpRasEntry )
  831. {
  832. GlobalFree( lpRasEntry );
  833. lpRasEntry = NULL;
  834. }
  835. if( lpRasDevInfo )
  836. {
  837. GlobalFree( lpRasDevInfo );
  838. lpRasDevInfo = NULL;
  839. }
  840. hr = MyRasGetEntryProperties( NULL,
  841. g_pcDialErr->m_pszConnectoid,
  842. &lpRasEntry,
  843. &dwRasEntrySize,
  844. &lpRasDevInfo,
  845. &dwRasDevInfoSize);
  846. if( ERROR_SUCCESS != hr )
  847. {
  848. goto FillModemExit;
  849. }
  850. /*FreeLibrary(hRasDll);
  851. hRasDll = NULL;
  852. fp = NULL; */
  853. // Get devices from RAS/RNA
  854. //
  855. if (!g_pcDialErr->m_lprasdevinfo)
  856. g_pcDialErr->m_lprasdevinfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  857. if (!g_pcDialErr->m_lprasdevinfo)
  858. {
  859. hr = ERROR_NOT_ENOUGH_MEMORY;
  860. goto FillModemExit;
  861. }
  862. g_pcDialErr->m_lprasdevinfo->dwSize = sizeof(RASDEVINFO);
  863. dwSize = sizeof(RASDEVINFO);
  864. dwNumDev = 0;
  865. /*hRasDll = LoadLibrary(RASAPI_LIBRARY);
  866. if (!hRasDll)
  867. {
  868. hr = GetLastError();
  869. goto FillModemExit;
  870. }
  871. fp =GetProcAddress(hRasDll,"RasEnumDevicesA");
  872. if (!fp)
  873. {
  874. FreeLibrary(hRasDll);
  875. hRasDll = LoadLibrary(TEXT("RNAPH.DLL"));
  876. if (!hRasDll)
  877. {
  878. hr = GetLastError();
  879. goto FillModemExit;
  880. }
  881. fp = GetProcAddress(hRasDll,"RasEnumDevicesA");
  882. if (!fp)
  883. {
  884. hr = GetLastError();
  885. goto FillModemExit;
  886. }
  887. }*/
  888. // soft link to RasEnumDevices to allow for simultaneous Win95/NT compatability
  889. pRnaapi = new RNAAPI;
  890. if( !pRnaapi )
  891. {
  892. hr = ERROR_NOT_ENOUGH_MEMORY;
  893. goto FillModemExit;
  894. }
  895. hr = pRnaapi->RasEnumDevices(g_pcDialErr->m_lprasdevinfo,&dwSize,&dwNumDev);
  896. if (hr == ERROR_BUFFER_TOO_SMALL)
  897. {
  898. GlobalFree(g_pcDialErr->m_lprasdevinfo);
  899. g_pcDialErr->m_lprasdevinfo = (LPRASDEVINFO)GlobalAlloc(GPTR, (size_t)dwSize);
  900. if (!g_pcDialErr->m_lprasdevinfo)
  901. {
  902. hr = ERROR_NOT_ENOUGH_MEMORY;
  903. goto FillModemExit;
  904. }
  905. g_pcDialErr->m_lprasdevinfo->dwSize = sizeof(RASDEVINFO);
  906. hr = pRnaapi->RasEnumDevices(g_pcDialErr->m_lprasdevinfo,&dwSize,&dwNumDev);
  907. }
  908. /*FreeLibrary(hRasDll);
  909. hRasDll = NULL;
  910. fp = NULL;*/
  911. if (hr != ERROR_SUCCESS)
  912. goto FillModemExit;
  913. // Fill in combo box
  914. //
  915. dwTempNumEntries = dwNumDev;
  916. if (dwNumDev != 0)
  917. {
  918. for (idx=0;idx<dwTempNumEntries;idx++)
  919. {
  920. //
  921. // ChrisK Olympus 4560 do not add VPN's to list of modems
  922. // Vyung only add isdn and modem type devices
  923. //
  924. if ((0 == lstrcmpi(TEXT("MODEM"),g_pcDialErr->m_lprasdevinfo[idx].szDeviceType)) &&
  925. (0 == lstrcmpi(TEXT("ISDN"),g_pcDialErr->m_lprasdevinfo[idx].szDeviceType)))
  926. {
  927. lLast = SendDlgItemMessage(g_pcDialErr->m_hwnd,IDC_CMBMODEMS,CB_ADDSTRING,0,(LPARAM)&g_pcDialErr->m_lprasdevinfo[idx].szDeviceName[0]);
  928. //
  929. // ChrisK Olympus 245 5/25/97
  930. // Save index of modem
  931. //
  932. SendDlgItemMessage(g_pcDialErr->m_hwnd,IDC_CMBMODEMS,CB_SETITEMDATA,(WPARAM)lLast,(LPARAM)idx);
  933. if (lstrcmp(g_pcDialErr->m_lprasdevinfo[idx].szDeviceName,lpRasEntry->szDeviceName) == 0)
  934. SendDlgItemMessage(g_pcDialErr->m_hwnd,IDC_CMBMODEMS,CB_SETCURSEL,(WPARAM)lLast,0);
  935. }
  936. else
  937. {
  938. dwNumDev--;
  939. }
  940. }
  941. }
  942. if (dwNumDev == 1)
  943. SendDlgItemMessage(g_pcDialErr->m_hwnd,IDC_CMBMODEMS,CB_SETCURSEL,0,0);
  944. // UNDONE: select default device
  945. FillModemExit:
  946. //if (g_pcDialErr->m_lprasdevinfo) GlobalFree(g_pcDialErr->m_lprasdevinfo);
  947. //if (pcRNA) delete pcRNA;
  948. if (lpRasEntry) GlobalFree(lpRasEntry);
  949. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  950. if( pRnaapi ) delete pRnaapi;
  951. return hr;
  952. }
  953. HRESULT DialErrGetDisplayableNumber()
  954. {
  955. #if !defined(WIN16)
  956. DWORD dwNumDev;
  957. LPLINETRANSLATEOUTPUT lpOutput2;
  958. LPLINEEXTENSIONID lpExtensionID = NULL;
  959. #endif
  960. HRESULT hr;
  961. LPRASENTRY lpRasEntry = NULL;
  962. LPRASDEVINFO lpRasDevInfo = NULL;
  963. DWORD dwRasEntrySize = 0;
  964. DWORD dwRasDevInfoSize = 0;
  965. LPLINETRANSLATEOUTPUT lpOutput1 = NULL;
  966. HINSTANCE hRasDll = NULL;
  967. FARPROC fp = NULL;
  968. #if !defined(WIN16)
  969. // Normandy 13024 - ChrisK 12/31/96
  970. // In all cases we have to get the TAPI version number, because the dialing properies
  971. // button will not work on NT if the version is 0.
  972. //
  973. // Initialize TAPIness
  974. //
  975. dwNumDev = 0;
  976. hr = lineInitialize(&g_pcDialErr->m_hLineApp,g_pcDialErr->m_hInst,LineCallback,NULL,&dwNumDev);
  977. if (hr != ERROR_SUCCESS)
  978. goto GetDisplayableNumberExit;
  979. if (g_pdevice->dwTapiDev == 0xFFFFFFFF)
  980. g_pdevice->dwTapiDev = 0;
  981. // Get TAPI version number
  982. lpExtensionID = (LPLINEEXTENSIONID )GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  983. if (!lpExtensionID)
  984. {
  985. hr = ERROR_NOT_ENOUGH_MEMORY;
  986. goto GetDisplayableNumberExit;
  987. }
  988. do {
  989. hr = lineNegotiateAPIVersion(g_pcDialErr->m_hLineApp, g_pdevice->dwTapiDev, 0x00010004, 0x00010004,
  990. &g_pcDialErr->m_dwAPIVersion, lpExtensionID);
  991. } while (hr && g_pdevice->dwTapiDev++ < dwNumDev-1);
  992. // delete ExtenstionID since we don't use it
  993. if (lpExtensionID) GlobalFree(lpExtensionID);
  994. if (hr != ERROR_SUCCESS)
  995. goto GetDisplayableNumberExit;
  996. #endif // !WIN16
  997. //RNAAPI * pcRNA;
  998. // Get phone number from connectoid
  999. //
  1000. /* ---replaced by call to MyRasGetEntryProperties below
  1001. #if defined(WIN16)
  1002. //
  1003. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  1004. //
  1005. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY)+256);
  1006. #else
  1007. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,sizeof(RASENTRY));
  1008. #endif
  1009. if (!lpRasEntry)
  1010. {
  1011. hr = ERROR_NOT_ENOUGH_MEMORY;
  1012. goto GetDisplayableNumberExit;
  1013. }
  1014. lpRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  1015. if (!lpRasDevInfo)
  1016. {
  1017. hr = ERROR_NOT_ENOUGH_MEMORY;
  1018. goto GetDisplayableNumberExit;
  1019. }
  1020. dwRasEntrySize = sizeof(RASENTRY);
  1021. dwRasDevInfoSize = sizeof(RASDEVINFO);
  1022. */
  1023. /* hRasDll = LoadLibrary(RASAPI_LIBRARY);
  1024. if (!hRasDll)
  1025. {
  1026. hr = GetLastError();
  1027. goto GetDisplayableNumberExit;
  1028. }
  1029. fp =GetProcAddress(hRasDll,"RasGetEntryPropertiesA");
  1030. if (!fp)
  1031. {
  1032. FreeLibrary(hRasDll);
  1033. hRasDll = LoadLibrary(TEXT("RNAPH.DLL"));
  1034. if (!hRasDll)
  1035. {
  1036. hr = GetLastError();
  1037. goto GetDisplayableNumberExit;
  1038. }
  1039. fp = GetProcAddress(hRasDll,"RasGetEntryPropertiesA");
  1040. if (!fp)
  1041. {
  1042. hr = GetLastError();
  1043. goto GetDisplayableNumberExit;
  1044. }
  1045. }
  1046. */
  1047. // lpRasEntry and lpRasDevInfo should not have memory allocated to them, and should be NULL
  1048. // See MyRasGetEntryProperties function comment for details.
  1049. hr = MyRasGetEntryProperties( NULL,
  1050. g_pcDialErr->m_pszConnectoid,
  1051. &lpRasEntry,
  1052. &dwRasEntrySize,
  1053. &lpRasDevInfo,
  1054. &dwRasDevInfoSize);
  1055. if (hr != ERROR_SUCCESS)
  1056. {
  1057. goto GetDisplayableNumberExit;
  1058. }
  1059. //FreeLibrary(hRasDll);
  1060. //
  1061. // If this is a dial as is number, just get it from the structure
  1062. //
  1063. if (!(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes))
  1064. {
  1065. if (g_pcDialErr->m_pszDisplayable) GlobalFree(g_pcDialErr->m_pszDisplayable);
  1066. g_pcDialErr->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, lstrlen(lpRasEntry->szLocalPhoneNumber)+1);
  1067. if (!g_pcDialErr->m_pszDisplayable)
  1068. {
  1069. hr = ERROR_NOT_ENOUGH_MEMORY;
  1070. goto GetDisplayableNumberExit;
  1071. }
  1072. lstrcpy(g_pcDialErr->m_szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  1073. lstrcpy(g_pcDialErr->m_pszDisplayable, lpRasEntry->szLocalPhoneNumber);
  1074. }
  1075. else
  1076. {
  1077. //
  1078. // If there is no area code, don't use parentheses
  1079. //
  1080. if (lpRasEntry->szAreaCode[0])
  1081. wsprintf(g_pcDialErr->m_szPhoneNumber,TEXT("+%lu (%s) %s\0"),lpRasEntry->dwCountryCode,
  1082. lpRasEntry->szAreaCode,lpRasEntry->szLocalPhoneNumber);
  1083. else
  1084. wsprintf(g_pcDialErr->m_szPhoneNumber,TEXT("+%lu %s\0"),lpRasEntry->dwCountryCode,
  1085. lpRasEntry->szLocalPhoneNumber);
  1086. #if defined(WIN16)
  1087. char szBuffer[1024];
  1088. LONG lRetCode;
  1089. memset(&szBuffer[0], 0, sizeof(szBuffer));
  1090. lpOutput1 = (LPLINETRANSLATEOUTPUT) & szBuffer[0];
  1091. lpOutput1->dwTotalSize = sizeof(szBuffer);
  1092. lRetCode = IETapiTranslateAddress(NULL, g_pcDialErr->m_szPhoneNumber,
  1093. 0L, 0L, lpOutput1);
  1094. if (0 != lRetCode)
  1095. {
  1096. //
  1097. // TODO: Set the correct error code
  1098. //
  1099. hr = GetLastError();
  1100. goto GetDisplayableNumberExit;
  1101. }
  1102. if (g_pcDialErr->m_pszDisplayable) GlobalFree(g_pcDialErr->m_pszDisplayable);
  1103. g_pcDialErr->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR,
  1104. ((size_t)lpOutput1->dwDisplayableStringSize+1));
  1105. if (!g_pcDialErr->m_pszDisplayable)
  1106. {
  1107. hr = ERROR_NOT_ENOUGH_MEMORY;
  1108. goto GetDisplayableNumberExit;
  1109. }
  1110. lstrcpy(g_pcDialErr->m_pszDisplayable,
  1111. &szBuffer[lpOutput1->dwDisplayableStringOffset]);
  1112. #else //WIN16
  1113. /* Normandy 13024 this code was moved up
  1114. //
  1115. // Initialize TAPIness
  1116. //
  1117. dwNumDev = 0;
  1118. hr = lineInitialize(&g_pcDialErr->m_hLineApp,g_pcDialErr->m_hInst,LineCallback,NULL,&dwNumDev);
  1119. if (hr != ERROR_SUCCESS)
  1120. goto GetDisplayableNumberExit;
  1121. //Normandy #7019 jmazner
  1122. //all devices should share the same dialing properties
  1123. //(at least, this is what icwdial\dialerr.cpp appears to assume, and it works right ;)
  1124. // if (g_pdevice->dwTapiDev == 0xFFFFFFFF)
  1125. // {
  1126. // if (dwNumDev == 1)
  1127. // g_pdevice->dwTapiDev = 0;
  1128. // //else
  1129. // // UNDONE: Tell the user to select a modem
  1130. // // DO NOT EXIT UNTIL THEY PICK ONE
  1131. // }
  1132. if (g_pdevice->dwTapiDev == 0xFFFFFFFF) g_pdevice->dwTapiDev = 0;
  1133. lpExtensionID = (LPLINEEXTENSIONID )GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  1134. if (!lpExtensionID)
  1135. {
  1136. hr = ERROR_NOT_ENOUGH_MEMORY;
  1137. goto GetDisplayableNumberExit;
  1138. }
  1139. hr = lineNegotiateAPIVersion(g_pcDialErr->m_hLineApp, g_pdevice->dwTapiDev, 0x00010004, 0x00010004,
  1140. &g_pcDialErr->m_dwAPIVersion, lpExtensionID);
  1141. // ditch it since we don't use it
  1142. //
  1143. if (lpExtensionID) GlobalFree(lpExtensionID);
  1144. if (hr != ERROR_SUCCESS)
  1145. goto GetDisplayableNumberExit;
  1146. Normandy 13024 (see comments above) */
  1147. // Format the phone number
  1148. //
  1149. lpOutput1 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR,sizeof(LINETRANSLATEOUTPUT));
  1150. if (!lpOutput1)
  1151. {
  1152. hr = ERROR_NOT_ENOUGH_MEMORY;
  1153. goto GetDisplayableNumberExit;
  1154. }
  1155. lpOutput1->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  1156. // Turn the canonical form into the "displayable" form
  1157. //
  1158. hr = lineTranslateAddress(g_pcDialErr->m_hLineApp,g_pdevice->dwTapiDev,
  1159. g_pcDialErr->m_dwAPIVersion,
  1160. g_pcDialErr->m_szPhoneNumber,0,
  1161. LINETRANSLATEOPTION_CANCELCALLWAITING,
  1162. lpOutput1);
  1163. if (hr != ERROR_SUCCESS || (lpOutput1->dwNeededSize != lpOutput1->dwTotalSize))
  1164. {
  1165. lpOutput2 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR, (size_t) lpOutput1->dwNeededSize);
  1166. if (!lpOutput2)
  1167. {
  1168. hr = ERROR_NOT_ENOUGH_MEMORY;
  1169. goto GetDisplayableNumberExit;
  1170. }
  1171. lpOutput2->dwTotalSize = lpOutput1->dwNeededSize;
  1172. GlobalFree(lpOutput1);
  1173. lpOutput1 = lpOutput2;
  1174. lpOutput2 = NULL;
  1175. hr = lineTranslateAddress(g_pcDialErr->m_hLineApp,g_pdevice->dwTapiDev,
  1176. g_pcDialErr->m_dwAPIVersion,
  1177. g_pcDialErr->m_szPhoneNumber,0,
  1178. LINETRANSLATEOPTION_CANCELCALLWAITING,
  1179. lpOutput1);
  1180. }
  1181. if (hr != ERROR_SUCCESS)
  1182. {
  1183. goto GetDisplayableNumberExit;
  1184. }
  1185. if (g_pcDialErr->m_pszDisplayable) GlobalFree(g_pcDialErr->m_pszDisplayable);
  1186. g_pcDialErr->m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, (size_t) lpOutput1->dwDisplayableStringSize+1);
  1187. if (!g_pcDialErr->m_pszDisplayable)
  1188. {
  1189. hr = ERROR_NOT_ENOUGH_MEMORY;
  1190. goto GetDisplayableNumberExit;
  1191. }
  1192. lstrcpyn(g_pcDialErr->m_pszDisplayable,
  1193. (LPTSTR)&((LPBYTE)lpOutput1)[lpOutput1->dwDisplayableStringOffset],
  1194. (size_t)lpOutput1->dwDisplayableStringSize);
  1195. #endif // WIN16
  1196. }
  1197. GetDisplayableNumberExit:
  1198. if (lpRasEntry) GlobalFree(lpRasEntry);
  1199. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  1200. #if !defined(WIN16)
  1201. if (lpOutput1) GlobalFree(lpOutput1);
  1202. if (g_pcDialErr->m_hLineApp) lineShutdown(g_pcDialErr->m_hLineApp);
  1203. #endif
  1204. return hr;
  1205. }
  1206. //+---------------------------------------------------------------------------
  1207. //
  1208. // Function: MyRasGetEntryProperties()
  1209. //
  1210. // Synopsis: Performs some buffer size checks and then calls RasGetEntryProperties()
  1211. // See the RasGetEntryProperties() docs to understand why this is needed.
  1212. //
  1213. // Arguments: Same as RasGetEntryProperties with the following exceptions:
  1214. // lplpRasEntryBuff -- pointer to a pointer to a RASENTRY struct. On successfull
  1215. // return, *lplpRasEntryBuff will point to the RASENTRY struct
  1216. // and buffer returned by RasGetEntryProperties.
  1217. // NOTE: should not have memory allocated to it at call time!
  1218. // To emphasize this point, *lplpRasEntryBuff must be NULL
  1219. // lplpRasDevInfoBuff -- pointer to a pointer to a RASDEVINFO struct. On successfull
  1220. // return, *lplpRasDevInfoBuff will point to the RASDEVINFO struct
  1221. // and buffer returned by RasGetEntryProperties.
  1222. // NOTE: should not have memory allocated to it at call time!
  1223. // To emphasize this point, *lplpRasDevInfoBuff must be NULL
  1224. // NOTE: Even on a successfull call to RasGetEntryProperties,
  1225. // *lplpRasDevInfoBuff may return with a value of NULL
  1226. // (occurs when there is no extra device info)
  1227. //
  1228. // Returns: ERROR_NOT_ENOUGH_MEMORY if unable to allocate either RASENTRY or RASDEVINFO buffer
  1229. // Otherwise, it retuns the error code from the call to RasGetEntryProperties.
  1230. // NOTE: if return is anything other than ERROR_SUCCESS, *lplpRasDevInfoBuff and
  1231. // *lplpRasEntryBuff will be NULL,
  1232. // and *lpdwRasEntryBuffSize and *lpdwRasDevInfoBuffSize will be 0
  1233. //
  1234. // Example:
  1235. //
  1236. // LPRASENTRY lpRasEntry = NULL;
  1237. // LPRASDEVINFO lpRasDevInfo = NULL;
  1238. // DWORD dwRasEntrySize, dwRasDevInfoSize;
  1239. //
  1240. // hr = MyRasGetEntryProperties( NULL,
  1241. // g_pcDialErr->m_pszConnectoid,
  1242. // &lpRasEntry,
  1243. // &dwRasEntrySize,
  1244. // &lpRasDevInfo,
  1245. // &dwRasDevInfoSize);
  1246. //
  1247. //
  1248. // if (hr != ERROR_SUCCESS)
  1249. // {
  1250. // //handle errors here
  1251. // } else
  1252. // {
  1253. // //continue processing
  1254. // }
  1255. //
  1256. //
  1257. // History: 9/10/96 JMazner Created
  1258. //
  1259. //----------------------------------------------------------------------------
  1260. HRESULT MyRasGetEntryProperties(LPTSTR lpszPhonebookFile,
  1261. LPTSTR lpszPhonebookEntry,
  1262. LPRASENTRY *lplpRasEntryBuff,
  1263. LPDWORD lpdwRasEntryBuffSize,
  1264. LPRASDEVINFO *lplpRasDevInfoBuff,
  1265. LPDWORD lpdwRasDevInfoBuffSize)
  1266. {
  1267. HRESULT hr;
  1268. RNAAPI *pRnaapi = NULL;
  1269. DWORD dwOldDevInfoBuffSize;
  1270. Assert( NULL != lplpRasEntryBuff );
  1271. Assert( NULL != lpdwRasEntryBuffSize );
  1272. Assert( NULL != lplpRasDevInfoBuff );
  1273. Assert( NULL != lpdwRasDevInfoBuffSize );
  1274. *lpdwRasEntryBuffSize = 0;
  1275. *lpdwRasDevInfoBuffSize = 0;
  1276. // Use reference variables internaly to make notation easier
  1277. LPRASENTRY &reflpRasEntryBuff = *lplpRasEntryBuff;
  1278. LPRASDEVINFO &reflpRasDevInfoBuff = *lplpRasDevInfoBuff;
  1279. Assert( NULL == reflpRasEntryBuff );
  1280. Assert( NULL == reflpRasDevInfoBuff );
  1281. // need to softlink for simultaneous compatability with win95 and winnt
  1282. pRnaapi = new RNAAPI;
  1283. if( !pRnaapi )
  1284. {
  1285. hr = ERROR_NOT_ENOUGH_MEMORY;
  1286. goto MyRasGetEntryPropertiesErrExit;
  1287. }
  1288. // use RasGetEntryProperties with a NULL lpRasEntry pointer to find out size buffer we need
  1289. // As per the docs' recommendation, do the same with a NULL lpRasDevInfo pointer.
  1290. hr = pRnaapi->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  1291. (LPBYTE)NULL,
  1292. lpdwRasEntryBuffSize,
  1293. (LPBYTE)NULL,lpdwRasDevInfoBuffSize);
  1294. // we expect the above call to fail because the buffer size is 0
  1295. // If it doesn't fail, that means our RasEntry is messed, so we're in trouble
  1296. if( ERROR_BUFFER_TOO_SMALL != hr )
  1297. {
  1298. goto MyRasGetEntryPropertiesErrExit;
  1299. }
  1300. // dwRasEntryBuffSize and dwRasDevInfoBuffSize now contain the size needed for their
  1301. // respective buffers, so allocate the memory for them
  1302. // dwRasEntryBuffSize should never be less than the size of the RASENTRY struct.
  1303. // If it is, we'll run into problems sticking values into the struct's fields
  1304. Assert( *lpdwRasEntryBuffSize >= sizeof(RASENTRY) );
  1305. #if defined(WIN16)
  1306. //
  1307. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  1308. //
  1309. reflpRasEntryBuff = (LPRASENTRY)GlobalAlloc(GPTR,*lpdwRasEntryBuffSize + 256);
  1310. #else
  1311. reflpRasEntryBuff = (LPRASENTRY)GlobalAlloc(GPTR,*lpdwRasEntryBuffSize);
  1312. #endif
  1313. if (!reflpRasEntryBuff)
  1314. {
  1315. hr = ERROR_NOT_ENOUGH_MEMORY;
  1316. goto MyRasGetEntryPropertiesErrExit;
  1317. }
  1318. //
  1319. // Allocate the DeviceInfo size that RasGetEntryProperties told us we needed.
  1320. // If size is 0, don't alloc anything
  1321. //
  1322. if( *lpdwRasDevInfoBuffSize > 0 )
  1323. {
  1324. Assert( *lpdwRasDevInfoBuffSize >= sizeof(RASDEVINFO) );
  1325. reflpRasDevInfoBuff = (LPRASDEVINFO)GlobalAlloc(GPTR,*lpdwRasDevInfoBuffSize);
  1326. if (!reflpRasDevInfoBuff)
  1327. {
  1328. hr = ERROR_NOT_ENOUGH_MEMORY;
  1329. goto MyRasGetEntryPropertiesErrExit;
  1330. }
  1331. } else
  1332. {
  1333. reflpRasDevInfoBuff = NULL;
  1334. }
  1335. // This is a bit convoluted: lpRasEntrySize->dwSize needs to contain the size of _only_ the
  1336. // RASENTRY structure, and _not_ the actual size of the buffer that lpRasEntrySize points to.
  1337. // This is because the dwSize field is used by RAS for compatability purposes to determine which
  1338. // version of the RASENTRY struct we're using.
  1339. // Same holds for lpRasDevInfo->dwSize
  1340. reflpRasEntryBuff->dwSize = sizeof(RASENTRY);
  1341. if( reflpRasDevInfoBuff )
  1342. {
  1343. reflpRasDevInfoBuff->dwSize = sizeof(RASDEVINFO);
  1344. }
  1345. // now we're ready to make the actual call...
  1346. // jmazner see below for why this is needed
  1347. dwOldDevInfoBuffSize = *lpdwRasDevInfoBuffSize;
  1348. hr = pRnaapi->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  1349. (LPBYTE)reflpRasEntryBuff,
  1350. lpdwRasEntryBuffSize,
  1351. (LPBYTE)reflpRasDevInfoBuff,lpdwRasDevInfoBuffSize);
  1352. // jmazner 10/7/96 Normandy #8763
  1353. // For unknown reasons, in some cases on win95, devInfoBuffSize increases after the above call,
  1354. // but the return code indicates success, not BUFFER_TOO_SMALL. If this happens, set the
  1355. // size back to what it was before the call, so the DevInfoBuffSize and the actuall space allocated
  1356. // for the DevInfoBuff match on exit.
  1357. if( (ERROR_SUCCESS == hr) && (dwOldDevInfoBuffSize != *lpdwRasDevInfoBuffSize) )
  1358. {
  1359. *lpdwRasDevInfoBuffSize = dwOldDevInfoBuffSize;
  1360. }
  1361. delete pRnaapi;
  1362. pRnaapi = NULL;
  1363. return( hr );
  1364. MyRasGetEntryPropertiesErrExit:
  1365. if(reflpRasEntryBuff)
  1366. {
  1367. GlobalFree(reflpRasEntryBuff);
  1368. reflpRasDevInfoBuff = NULL;
  1369. }
  1370. if(reflpRasDevInfoBuff)
  1371. {
  1372. GlobalFree(reflpRasDevInfoBuff);
  1373. reflpRasDevInfoBuff = NULL;
  1374. }
  1375. if (pRnaapi)
  1376. {
  1377. delete pRnaapi;
  1378. pRnaapi = NULL;
  1379. }
  1380. *lpdwRasEntryBuffSize = 0;
  1381. *lpdwRasDevInfoBuffSize = 0;
  1382. return( hr );
  1383. }