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.

3827 lines
118 KiB

  1. //**********************************************************************
  2. // File name: RefDial.cpp
  3. //
  4. // Implementation of CRefDial
  5. //
  6. // Functions:
  7. //
  8. // Copyright (c) 1992 - 1999 Microsoft Corporation. All rights reserved.
  9. //**********************************************************************
  10. #include "stdafx.h"
  11. #include "icwhelp.h"
  12. #include "RefDial.h"
  13. #include "appdefs.h"
  14. #include <regstr.h>
  15. #include <urlmon.h>
  16. #include <mshtmhst.h>
  17. const TCHAR c_szCreditsMagicNum[] = TEXT("1 425 555 1212");
  18. const TCHAR c_szRegStrValDigitalPID[] = TEXT("DigitalProductId");
  19. const TCHAR c_szSignedPIDFName[] = TEXT("signed.pid");
  20. const TCHAR c_szRASProfiles[] = TEXT("RemoteAccess\\Profile");
  21. const TCHAR c_szProxyEnable[] = TEXT("ProxyEnable");
  22. TCHAR g_BINTOHEXLookup[16] =
  23. {
  24. TEXT('0'),
  25. TEXT('1'),
  26. TEXT('2'),
  27. TEXT('3'),
  28. TEXT('4'),
  29. TEXT('5'),
  30. TEXT('6'),
  31. TEXT('7'),
  32. TEXT('8'),
  33. TEXT('9'),
  34. TEXT('A'),
  35. TEXT('B'),
  36. TEXT('C'),
  37. TEXT('D'),
  38. TEXT('E'),
  39. TEXT('F')
  40. };
  41. typedef DWORD (WINAPI * GETICWCONNVER) ();
  42. GETICWCONNVER lpfnGetIcwconnVer;
  43. HWND g_hwndRNAApp = NULL;
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CRefDial
  46. HRESULT CRefDial::OnDraw(ATL_DRAWINFO& di)
  47. {
  48. return S_OK;
  49. }
  50. LRESULT CRefDial::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  51. {
  52. // Register the RASDIALEVENT message
  53. m_unRasDialMsg = RegisterWindowMessageA( RASDIALEVENT );
  54. if (m_unRasDialMsg == 0)
  55. {
  56. m_unRasDialMsg = WM_RASDIALEVENT;
  57. }
  58. // Make sure the window is hidden
  59. ShowWindow(SW_HIDE);
  60. return 0;
  61. }
  62. LRESULT CRefDial::OnDownloadEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  63. {
  64. USES_CONVERSION;
  65. if (uMsg == WM_DOWNLOAD_DONE)
  66. {
  67. DWORD dwThreadResults = STILL_ACTIVE;
  68. int iRetries = 0;
  69. // We keep the RAS connection open here, it must be explicitly
  70. // close by the container (a call DoHangup)
  71. // This code will wait until the download thread exists, and
  72. // collect the download status.
  73. do {
  74. if (!GetExitCodeThread(m_hThread,&dwThreadResults))
  75. {
  76. AssertMsg(0,TEXT("CONNECT:GetExitCodeThread failed.\n"));
  77. }
  78. iRetries++;
  79. if (dwThreadResults == STILL_ACTIVE)
  80. Sleep(500);
  81. } while (dwThreadResults == STILL_ACTIVE && iRetries < MAX_EXIT_RETRIES);
  82. // See if there is an URL to pass to the container
  83. BSTR bstrURL;
  84. if (m_szRefServerURL[0] != TEXT('\0'))
  85. bstrURL = (BSTR)A2BSTR(m_szRefServerURL);
  86. else
  87. bstrURL = NULL;
  88. m_RasStatusID = IDS_DOWNLOAD_COMPLETE;
  89. Fire_DownloadComplete(bstrURL, dwThreadResults);
  90. // The download is complete now, so we reset this to TRUE, so the RAS
  91. // event handler does not get confused
  92. m_bDownloadHasBeenCanceled = TRUE;
  93. // Free any memory allocated above during the conversion
  94. SysFreeString(bstrURL);
  95. }
  96. else if (uMsg == WM_DOWNLOAD_PROGRESS)
  97. {
  98. // Fire a progress event to the container
  99. m_RasStatusID = IDS_DOWNLOADING;
  100. Fire_DownloadProgress((long)wParam);
  101. }
  102. return 0;
  103. }
  104. static const TCHAR szRnaAppWindowClass[] = _T("#32770"); // hard coded dialog class name
  105. BOOL NeedZapperEx(void)
  106. {
  107. OSVERSIONINFO oi;
  108. memset(&oi, 0, sizeof(oi));
  109. oi.dwOSVersionInfoSize = sizeof(oi);
  110. if( GetVersionEx(&oi) &&
  111. (oi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) &&
  112. (oi.dwMajorVersion==4) &&
  113. (oi.dwMinorVersion==0) &&
  114. (LOWORD(oi.dwBuildNumber) <= 1070) )
  115. return TRUE;
  116. else
  117. return FALSE;
  118. }
  119. void GetRNAWindowEx()
  120. {
  121. TCHAR szTitle[MAX_PATH] = TEXT("\0");
  122. if (!LoadString(_Module.GetModuleInstance(), IDS_CONNECTED, szTitle, ARRAYSIZE(szTitle)))
  123. lstrcpy(szTitle , _T("Connected To "));
  124. g_hwndRNAApp = FindWindow(szRnaAppWindowClass, szTitle);
  125. }
  126. BOOL MinimizeRNAWindowEx()
  127. {
  128. if(g_hwndRNAApp)
  129. {
  130. // Get the main frame window's style
  131. LONG window_style = GetWindowLong(g_hwndRNAApp, GWL_STYLE);
  132. //Remove the system menu from the window's style
  133. window_style |= WS_MINIMIZE;
  134. //set the style attribute of the main frame window
  135. SetWindowLong(g_hwndRNAApp, GWL_STYLE, window_style);
  136. ShowWindow(g_hwndRNAApp, SW_MINIMIZE);
  137. return TRUE;
  138. }
  139. return FALSE;
  140. }
  141. LRESULT CRefDial::OnRasDialEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  142. {
  143. RNAAPI* pcRNA;
  144. TraceMsg(TF_GENERAL, TEXT("ICWHELP: Ras event %u error code (%ld)\n"),wParam,lParam);
  145. TCHAR dzRasError[10];
  146. wsprintf(dzRasError,TEXT("%d %d"),wParam,lParam);
  147. RegSetValue(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\iSignUp"),REG_SZ,dzRasError,lstrlen(dzRasError)+1);
  148. // In NT4, it gives wParma with error code in lParam rather than a
  149. // actual wParam message
  150. if (lParam)
  151. {
  152. wParam = RASCS_Disconnected;
  153. }
  154. m_RasStatusID = 0;
  155. switch(wParam)
  156. {
  157. case RASCS_OpenPort:
  158. m_RasStatusID = IDS_RAS_OPENPORT;
  159. break;
  160. case RASCS_PortOpened:
  161. m_RasStatusID = IDS_RAS_PORTOPENED;
  162. break;
  163. case RASCS_ConnectDevice:
  164. m_RasStatusID = IDS_RAS_DIALING;
  165. break;
  166. case RASCS_DeviceConnected:
  167. m_RasStatusID = IDS_RAS_CONNECTED;
  168. break;
  169. case RASCS_AllDevicesConnected:
  170. m_RasStatusID = IDS_RAS_CONNECTED;
  171. break;
  172. case RASCS_Authenticate:
  173. m_RasStatusID = IDS_RAS_CONNECTING;
  174. break;
  175. case RASCS_StartAuthentication:
  176. case RASCS_LogonNetwork:
  177. m_RasStatusID = IDS_RAS_LOCATING;
  178. break;
  179. case RASCS_Connected:
  180. {
  181. m_RasStatusID = IDS_RAS_CONNECTED;
  182. //
  183. // Hide RNA window on Win95 retail
  184. //
  185. if (NeedZapperEx())
  186. GetRNAWindowEx();
  187. break;
  188. }
  189. case RASCS_Disconnected:
  190. // Normandy 13184 - ChrisK 1-9-97
  191. m_RasStatusID = IDS_RAS_HANGINGUP;
  192. IF_NTONLY
  193. // jmazner Normandy #5603 ported from ChrisK's fix in icwdial
  194. // There is a possibility that we will get multiple disconnects in NT
  195. // and we only want to handle the first one. Note: the flag is reset
  196. // in the INITIALIZE event, so we should handle 1 disconnect per instance
  197. // of the dialog.
  198. if (m_bDisconnect)
  199. break;
  200. else
  201. m_bDisconnect = TRUE;
  202. ENDIF_NTONLY
  203. //
  204. // If we are in the middle of a download, cancel the it!
  205. //
  206. //
  207. // ChrisK 5240 Olympus
  208. // Only the thread that creates the dwDownload should invalidate it
  209. // so we need another method to track if the cancel button has been
  210. // pressed.
  211. //
  212. if (!m_bDownloadHasBeenCanceled)
  213. {
  214. HINSTANCE hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  215. if (hDLDLL)
  216. {
  217. FARPROC fp = GetProcAddress(hDLDLL,DOWNLOADCANCEL);
  218. if(fp)
  219. ((PFNDOWNLOADCANCEL)fp)(m_dwDownLoad);
  220. FreeLibrary(hDLDLL);
  221. hDLDLL = NULL;
  222. m_bDownloadHasBeenCanceled = TRUE;
  223. }
  224. }
  225. // If we get a disconnected status from the RAS server, then
  226. // hangup the modem here
  227. if (m_hrasconn)
  228. {
  229. pcRNA = new RNAAPI;
  230. if (pcRNA)
  231. {
  232. pcRNA->RasHangUp(m_hrasconn);
  233. m_hrasconn = NULL;
  234. delete pcRNA;
  235. pcRNA = NULL;
  236. }
  237. }
  238. break;
  239. }
  240. // Fire the event to the container.
  241. Fire_RasDialStatus((USHORT)wParam);
  242. // If we are connected then fire an event telling the container
  243. // that we are ready
  244. if (wParam == RASCS_Connected)
  245. Fire_RasConnectComplete(TRUE);
  246. else if (wParam == RASCS_Disconnected)
  247. {
  248. m_hrDialErr = (HRESULT)lParam;
  249. Fire_RasConnectComplete(FALSE);
  250. }
  251. return 0;
  252. }
  253. STDMETHODIMP CRefDial::get_DownloadStatusString(BSTR * pVal)
  254. {
  255. USES_CONVERSION;
  256. if (pVal == NULL)
  257. return E_POINTER;
  258. if (m_DownloadStatusID)
  259. *pVal = (BSTR)A2BSTR(GetSz((USHORT)m_DownloadStatusID));
  260. else
  261. *pVal = (BSTR)A2BSTR(TEXT(""));
  262. return S_OK;
  263. }
  264. /******************************************************************************
  265. // These functions come from the existing ICW code and are use to setup a
  266. // connectiod to the referral server, dial it, and perform the download.
  267. ******************************************************************************/
  268. //+----------------------------------------------------------------------------
  269. // Function: ReadConnectionInformation
  270. //
  271. // Synopsis: Read the contents from the ISP file
  272. //
  273. // Arguments: none
  274. //
  275. // Returns: error value - ERROR_SUCCESS = succes
  276. //
  277. // History: 1/9/98 DONALDM Adapted from ICW 1.x
  278. //-----------------------------------------------------------------------------
  279. DWORD CRefDial::ReadConnectionInformation(void)
  280. {
  281. USES_CONVERSION;
  282. DWORD hr;
  283. TCHAR szUserName[UNLEN+1];
  284. TCHAR szPassword[PWLEN+1];
  285. LPTSTR pszTemp;
  286. BOOL bReboot;
  287. LPTSTR lpRunOnceCmd;
  288. bReboot = FALSE;
  289. lpRunOnceCmd = NULL;
  290. //
  291. // Get the name of DUN file from ISP file, if there is one.
  292. //
  293. TCHAR pszDunFile[MAX_PATH];
  294. #ifdef UNICODE
  295. hr = GetDataFromISPFile(m_bstrISPFile,INF_SECTION_ISPINFO, INF_DUN_FILE, pszDunFile,MAX_PATH);
  296. #else
  297. hr = GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_ISPINFO, INF_DUN_FILE, pszDunFile,MAX_PATH);
  298. #endif
  299. if (ERROR_SUCCESS == hr)
  300. {
  301. //
  302. // Get the full path to the DUN File
  303. //
  304. TCHAR szTempPath[MAX_PATH];
  305. lstrcpy(szTempPath,pszDunFile);
  306. if (!(hr = SearchPath(NULL,szTempPath,NULL,MAX_PATH,pszDunFile,&pszTemp)))
  307. {
  308. ErrorMsg1(m_hWnd, IDS_CANTREADTHISFILE, CharUpper(pszDunFile));
  309. goto ReadConnectionInformationExit;
  310. }
  311. //
  312. // save current DUN file name in global (for ourself)
  313. //
  314. lstrcpy(m_szCurrentDUNFile, pszDunFile);
  315. }
  316. //
  317. // Read the DUN/ISP file File
  318. //
  319. hr = m_ISPImport.ImportConnection(m_szCurrentDUNFile[0] != '\0' ? m_szCurrentDUNFile : OLE2A(m_bstrISPFile),
  320. m_szISPSupportNumber,
  321. m_szEntryName,
  322. szUserName,
  323. szPassword,
  324. &bReboot);
  325. if ((VER_PLATFORM_WIN32_NT == g_dwPlatform) && (ERROR_INVALID_PARAMETER == hr))
  326. {
  327. // If there are only dial-out entries configured on NT, we get
  328. // ERROR_INVALID_PARAMETER returned from RasSetEntryProperties,
  329. // which InetConfigClient returns to ImportConnection which
  330. // returns it to us. If we get this error, we want to display
  331. // a different error instructing the user to configure a modem
  332. // for dial-out.
  333. MessageBox(GetSz(IDS_NODIALOUT),
  334. GetSz(IDS_TITLE),
  335. MB_ICONERROR | MB_OK | MB_APPLMODAL);
  336. goto ReadConnectionInformationExit;
  337. }
  338. else
  339. if (ERROR_CANNOT_FIND_PHONEBOOK_ENTRY == hr)
  340. {
  341. //
  342. // The disk is full, or something is wrong with the
  343. // phone book file
  344. MessageBox(GetSz(IDS_NOPHONEENTRY),
  345. GetSz(IDS_TITLE),
  346. MB_ICONERROR | MB_OK | MB_APPLMODAL);
  347. goto ReadConnectionInformationExit;
  348. }
  349. else if (hr == ERROR_CANCELLED)
  350. {
  351. TraceMsg(TF_GENERAL, TEXT("ICWHELP: User cancelled, quitting.\n"));
  352. goto ReadConnectionInformationExit;
  353. }
  354. else if (hr == ERROR_RETRY)
  355. {
  356. TraceMsg(TF_GENERAL, TEXT("ICWHELP: User retrying.\n"));
  357. goto ReadConnectionInformationExit;
  358. }
  359. else if (hr != ERROR_SUCCESS)
  360. {
  361. ErrorMsg1(m_hWnd, IDS_CANTREADTHISFILE, CharUpper(pszDunFile));
  362. goto ReadConnectionInformationExit;
  363. }
  364. else
  365. {
  366. //
  367. // place the name of the connectoid in the registry
  368. //
  369. if (ERROR_SUCCESS != (hr = StoreInSignUpReg((LPBYTE)m_szEntryName, lstrlen(m_szEntryName)+1, REG_SZ, RASENTRYVALUENAME)))
  370. {
  371. MsgBox(IDS_CANTSAVEKEY,MB_MYERROR);
  372. goto ReadConnectionInformationExit;
  373. }
  374. }
  375. AssertMsg(!bReboot, TEXT("ICWHELP: We should never reboot here.\r\n"));
  376. ReadConnectionInformationExit:
  377. return hr;
  378. }
  379. HRESULT CRefDial::GetDisplayableNumber()
  380. {
  381. HRESULT hr = ERROR_SUCCESS;
  382. LPRASENTRY lpRasEntry = NULL;
  383. LPRASDEVINFO lpRasDevInfo = NULL;
  384. DWORD dwRasEntrySize = 0;
  385. DWORD dwRasDevInfoSize = 0;
  386. RNAAPI *pcRNA = NULL;
  387. LPLINETRANSLATEOUTPUT lpOutput1 = NULL;
  388. DWORD dwNumDev;
  389. LPLINETRANSLATEOUTPUT lpOutput2;
  390. LPLINEEXTENSIONID lpExtensionID = NULL;
  391. //
  392. // Get phone number from connectoid
  393. //
  394. hr = MyRasGetEntryProperties(NULL,
  395. m_szConnectoid,
  396. &lpRasEntry,
  397. &dwRasEntrySize,
  398. &lpRasDevInfo,
  399. &dwRasDevInfoSize);
  400. if (hr != ERROR_SUCCESS || NULL == lpRasEntry)
  401. {
  402. goto GetDisplayableNumberExit;
  403. }
  404. //
  405. // If this is a dial as is number, just get it from the structure
  406. //
  407. m_bDialAsIs = !(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes);
  408. if (m_bDialAsIs)
  409. {
  410. if (m_pszDisplayable) GlobalFree(m_pszDisplayable);
  411. m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, sizeof(TCHAR)*(lstrlen(lpRasEntry->szLocalPhoneNumber)+1));
  412. if (!m_pszDisplayable)
  413. {
  414. hr = ERROR_NOT_ENOUGH_MEMORY;
  415. goto GetDisplayableNumberExit;
  416. }
  417. lstrcpy(m_szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  418. lstrcpy(m_pszDisplayable, lpRasEntry->szLocalPhoneNumber);
  419. TCHAR szAreaCode[MAX_AREACODE+1];
  420. TCHAR szCountryCode[8];
  421. if (SUCCEEDED(tapiGetLocationInfo(szCountryCode,szAreaCode)))
  422. {
  423. if (szCountryCode[0] != '\0')
  424. m_dwCountryCode = _ttoi(szCountryCode);
  425. else
  426. m_dwCountryCode = 1;
  427. }
  428. else
  429. {
  430. m_dwCountryCode = 1;
  431. }
  432. }
  433. else
  434. {
  435. //
  436. // If there is no area code, don't use parentheses
  437. //
  438. if (lpRasEntry->szAreaCode[0])
  439. wsprintf(m_szPhoneNumber,TEXT("+%lu (%s) %s\0"),lpRasEntry->dwCountryCode,
  440. lpRasEntry->szAreaCode,lpRasEntry->szLocalPhoneNumber);
  441. else
  442. wsprintf(m_szPhoneNumber,TEXT("+%lu %s\0"),lpRasEntry->dwCountryCode,
  443. lpRasEntry->szLocalPhoneNumber);
  444. //
  445. // Initialize TAPIness
  446. //
  447. dwNumDev = 0;
  448. hr = lineInitialize(&m_hLineApp,_Module.GetModuleInstance(),LineCallback,(LPSTR)NULL,&dwNumDev);
  449. if (hr != ERROR_SUCCESS)
  450. goto GetDisplayableNumberExit;
  451. lpExtensionID = (LPLINEEXTENSIONID )GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  452. if (!lpExtensionID)
  453. {
  454. hr = ERROR_NOT_ENOUGH_MEMORY;
  455. goto GetDisplayableNumberExit;
  456. }
  457. if (m_dwTapiDev == 0xFFFFFFFF)
  458. {
  459. m_dwTapiDev = 0;
  460. }
  461. //
  462. // ChrisK Olympus 5558 6/11/97
  463. // PPTP device will choke the version negotiating
  464. //
  465. do {
  466. hr = lineNegotiateAPIVersion(m_hLineApp, m_dwTapiDev, 0x00010004, 0x00010004,
  467. &m_dwAPIVersion, lpExtensionID);
  468. } while (hr != ERROR_SUCCESS && m_dwTapiDev++ < dwNumDev - 1);
  469. if (m_dwTapiDev >= dwNumDev)
  470. {
  471. m_dwTapiDev = 0;
  472. }
  473. // ditch it since we don't use it
  474. //
  475. if (lpExtensionID) GlobalFree(lpExtensionID);
  476. lpExtensionID = NULL;
  477. if (hr != ERROR_SUCCESS)
  478. goto GetDisplayableNumberExit;
  479. // Format the phone number
  480. //
  481. lpOutput1 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR,sizeof(LINETRANSLATEOUTPUT));
  482. if (!lpOutput1)
  483. {
  484. hr = ERROR_NOT_ENOUGH_MEMORY;
  485. goto GetDisplayableNumberExit;
  486. }
  487. lpOutput1->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  488. // Turn the canonical form into the "displayable" form
  489. //
  490. hr = lineTranslateAddress(m_hLineApp,m_dwTapiDev,m_dwAPIVersion,
  491. m_szPhoneNumber,0,
  492. LINETRANSLATEOPTION_CANCELCALLWAITING,
  493. lpOutput1);
  494. if (hr != ERROR_SUCCESS || (lpOutput1->dwNeededSize != lpOutput1->dwTotalSize))
  495. {
  496. lpOutput2 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR, (size_t)lpOutput1->dwNeededSize);
  497. if (!lpOutput2)
  498. {
  499. hr = ERROR_NOT_ENOUGH_MEMORY;
  500. goto GetDisplayableNumberExit;
  501. }
  502. lpOutput2->dwTotalSize = lpOutput1->dwNeededSize;
  503. GlobalFree(lpOutput1);
  504. lpOutput1 = lpOutput2;
  505. lpOutput2 = NULL;
  506. hr = lineTranslateAddress(m_hLineApp,m_dwTapiDev,
  507. m_dwAPIVersion,m_szPhoneNumber,0,
  508. LINETRANSLATEOPTION_CANCELCALLWAITING,
  509. lpOutput1);
  510. }
  511. if (hr != ERROR_SUCCESS)
  512. {
  513. goto GetDisplayableNumberExit;
  514. }
  515. m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, ((size_t)lpOutput1->dwDisplayableStringSize+1));
  516. if (!m_pszDisplayable)
  517. {
  518. hr = ERROR_NOT_ENOUGH_MEMORY;
  519. goto GetDisplayableNumberExit;
  520. }
  521. lstrcpyn(m_pszDisplayable,
  522. (LPTSTR)&((LPBYTE)lpOutput1)[lpOutput1->dwDisplayableStringOffset],
  523. (int)lpOutput1->dwDisplayableStringSize);
  524. TCHAR szAreaCode[MAX_AREACODE+1];
  525. TCHAR szCountryCode[8];
  526. if (SUCCEEDED(tapiGetLocationInfo(szCountryCode,szAreaCode)))
  527. {
  528. if (szCountryCode[0] != '\0')
  529. m_dwCountryCode = _ttoi(szCountryCode);
  530. else
  531. m_dwCountryCode = 1;
  532. }
  533. else
  534. {
  535. m_dwCountryCode = 1;
  536. }
  537. }
  538. GetDisplayableNumberExit:
  539. if (lpOutput1) GlobalFree(lpOutput1);
  540. if (m_hLineApp) lineShutdown(m_hLineApp);
  541. return hr;
  542. }
  543. typedef DWORD (WINAPI* PFNRASDIALA)(LPRASDIALEXTENSIONS,LPSTR,LPRASDIALPARAMSA,DWORD,LPVOID,LPHRASCONN);
  544. DWORD CRefDial::MyRasDial
  545. (
  546. LPRASDIALEXTENSIONS lpRasDialExtensions,
  547. LPTSTR lpszPhonebook,
  548. LPRASDIALPARAMS lpRasDialParams,
  549. DWORD dwNotifierType,
  550. LPVOID lpvNotifier,
  551. LPHRASCONN lphRasConn
  552. )
  553. {
  554. HRESULT hr;
  555. if (!m_hRasDll)
  556. m_hRasDll = LoadLibrary(TEXT("RasApi32.dll"));
  557. if (!m_hRasDll)
  558. {
  559. hr = GetLastError();
  560. goto MyRasDialExit;
  561. }
  562. if (m_hRasDll && !m_fpRasDial)
  563. m_fpRasDial = GetProcAddress(m_hRasDll,"RasDialA");
  564. if (!m_fpRasDial)
  565. {
  566. hr = GetLastError();
  567. goto MyRasDialExit;
  568. }
  569. if (m_fpRasDial)
  570. {
  571. #ifdef UNICODE
  572. // RasDialW version always fails to connect.
  573. // I don't know why. So I want to call RasDialA even if this is UNICODE build.
  574. RASDIALPARAMSA RasDialParams;
  575. RasDialParams.dwSize = sizeof(RASDIALPARAMSA);
  576. wcstombs(RasDialParams.szEntryName, lpRasDialParams->szEntryName, RAS_MaxEntryName+1);
  577. wcstombs(RasDialParams.szPhoneNumber, lpRasDialParams->szPhoneNumber, RAS_MaxPhoneNumber+1);
  578. wcstombs(RasDialParams.szCallbackNumber, lpRasDialParams->szCallbackNumber, RAS_MaxCallbackNumber+1);
  579. wcstombs(RasDialParams.szUserName, lpRasDialParams->szUserName, UNLEN+1);
  580. wcstombs(RasDialParams.szPassword, lpRasDialParams->szPassword, PWLEN+1);
  581. wcstombs(RasDialParams.szDomain, lpRasDialParams->szDomain, DNLEN+1);
  582. hr = ((PFNRASDIALA)m_fpRasDial)(lpRasDialExtensions,NULL,
  583. &RasDialParams,
  584. dwNotifierType,
  585. (LPVOID) lpvNotifier,
  586. lphRasConn);
  587. #else
  588. hr = ((PFNRASDIAL)m_fpRasDial)(lpRasDialExtensions,lpszPhonebook,
  589. lpRasDialParams,
  590. dwNotifierType,
  591. (LPVOID) lpvNotifier,
  592. lphRasConn);
  593. #endif
  594. Assert(hr == ERROR_SUCCESS);
  595. }
  596. MyRasDialExit:
  597. return hr;
  598. }
  599. DWORD CRefDial::MyRasGetEntryDialParams
  600. (
  601. LPTSTR lpszPhonebook,
  602. LPRASDIALPARAMS lprasdialparams,
  603. LPBOOL lpfPassword
  604. )
  605. {
  606. HRESULT hr;
  607. if (!m_hRasDll)
  608. m_hRasDll = LoadLibrary(TEXT("RasApi32.dll"));
  609. if (!m_hRasDll)
  610. {
  611. hr = GetLastError();
  612. goto MyRasGetEntryDialParamsExit;
  613. }
  614. if (m_hRasDll && !m_fpRasGetEntryDialParams)
  615. #ifdef UNICODE
  616. m_fpRasGetEntryDialParams = GetProcAddress(m_hRasDll,"RasGetEntryDialParamsW");
  617. #else
  618. m_fpRasGetEntryDialParams = GetProcAddress(m_hRasDll,"RasGetEntryDialParamsA");
  619. #endif
  620. if (!m_fpRasGetEntryDialParams)
  621. {
  622. hr = GetLastError();
  623. goto MyRasGetEntryDialParamsExit;
  624. }
  625. if (m_fpRasGetEntryDialParams)
  626. hr = ((PFNRASGETENTRYDIALPARAMS)m_fpRasGetEntryDialParams)(lpszPhonebook,lprasdialparams,lpfPassword);
  627. MyRasGetEntryDialParamsExit:
  628. return hr;
  629. }
  630. BOOL CRefDial::FShouldRetry(HRESULT hrErr)
  631. {
  632. BOOL bRC;
  633. m_uiRetry++;
  634. if (hrErr == ERROR_LINE_BUSY ||
  635. hrErr == ERROR_VOICE_ANSWER ||
  636. hrErr == ERROR_NO_ANSWER ||
  637. hrErr == ERROR_NO_CARRIER ||
  638. hrErr == ERROR_AUTHENTICATION_FAILURE ||
  639. hrErr == ERROR_PPP_TIMEOUT ||
  640. hrErr == ERROR_REMOTE_DISCONNECTION ||
  641. hrErr == ERROR_AUTH_INTERNAL ||
  642. hrErr == ERROR_PROTOCOL_NOT_CONFIGURED ||
  643. hrErr == ERROR_PPP_NO_PROTOCOLS_CONFIGURED)
  644. {
  645. bRC = TRUE;
  646. } else {
  647. bRC = FALSE;
  648. }
  649. bRC = bRC && m_uiRetry < MAX_RETIES;
  650. return bRC;
  651. }
  652. // This function will perform the actual dialing
  653. STDMETHODIMP CRefDial::DoConnect(BOOL * pbRetVal)
  654. {
  655. USES_CONVERSION;
  656. TCHAR szPassword[PWLEN+2];
  657. LPRASDIALPARAMS lpRasDialParams = NULL;
  658. LPRASDIALEXTENSIONS lpRasDialExtentions = NULL;
  659. HRESULT hr = ERROR_SUCCESS;
  660. BOOL bPW;
  661. // Initialize the dial error member
  662. m_hrDialErr = ERROR_SUCCESS;
  663. // Get connectoid information
  664. //
  665. lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR,sizeof(RASDIALPARAMS));
  666. if (!lpRasDialParams)
  667. {
  668. hr = ERROR_NOT_ENOUGH_MEMORY;
  669. goto DialExit;
  670. }
  671. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  672. lstrcpyn(lpRasDialParams->szEntryName,m_szConnectoid,ARRAYSIZE(lpRasDialParams->szEntryName));
  673. bPW = FALSE;
  674. hr = MyRasGetEntryDialParams(NULL,lpRasDialParams,&bPW);
  675. if (hr != ERROR_SUCCESS)
  676. {
  677. goto DialExit;
  678. }
  679. //
  680. // This is only used on WINNT
  681. //
  682. lpRasDialExtentions = (LPRASDIALEXTENSIONS)GlobalAlloc(GPTR,sizeof(RASDIALEXTENSIONS));
  683. if (lpRasDialExtentions)
  684. {
  685. lpRasDialExtentions->dwSize = sizeof(RASDIALEXTENSIONS);
  686. lpRasDialExtentions->dwfOptions = RDEOPT_UsePrefixSuffix;
  687. }
  688. //
  689. // Add the user's password
  690. //
  691. szPassword[0] = 0;
  692. GetPrivateProfileString(INFFILE_USER_SECTION,
  693. INFFILE_PASSWORD,
  694. NULLSZ,
  695. szPassword,
  696. PWLEN + 1,
  697. m_szCurrentDUNFile[0] != '\0'? m_szCurrentDUNFile : OLE2A(m_bstrISPFile));
  698. if(szPassword[0])
  699. lstrcpy(lpRasDialParams->szPassword, szPassword);
  700. //
  701. // Dial connectoid
  702. //
  703. //Fix for redialing, on win9x we need to make sure we "hangup"
  704. //and free the rna resources in case we are redialing.
  705. //NT - is smart enough not to need it but it won't hurt.
  706. if (m_pcRNA)
  707. m_pcRNA->RasHangUp(m_hrasconn);
  708. m_hrasconn = NULL;
  709. #if defined(DEBUG)
  710. if (FCampusNetOverride())
  711. {
  712. m_bModemOverride = TRUE;
  713. }
  714. #endif
  715. if (m_bModemOverride)
  716. {
  717. // Skip dialing because the server is on the campus network
  718. //
  719. PostMessage(RegisterWindowMessageA(RASDIALEVENT),RASCS_Connected,0);
  720. hr = ERROR_SUCCESS;
  721. }
  722. else
  723. hr = MyRasDial(lpRasDialExtentions,NULL,lpRasDialParams,0xFFFFFFFF, m_hWnd,
  724. &m_hrasconn);
  725. m_bModemOverride = FALSE;
  726. if (( hr != ERROR_SUCCESS) || m_bWaitingToHangup)
  727. {
  728. // We failed to connect for some reason, so hangup
  729. if (m_hrasconn)
  730. {
  731. if (!m_pcRNA) m_pcRNA = new RNAAPI;
  732. if (!m_pcRNA)
  733. {
  734. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  735. } else {
  736. m_pcRNA->RasHangUp(m_hrasconn);
  737. m_bWaitingToHangup = FALSE;
  738. m_hrasconn = NULL;
  739. }
  740. }
  741. goto DialExit;
  742. }
  743. if (lpRasDialParams)
  744. GlobalFree(lpRasDialParams);
  745. lpRasDialParams = NULL;
  746. DialExit:
  747. if (lpRasDialExtentions)
  748. GlobalFree(lpRasDialExtentions);
  749. lpRasDialExtentions = NULL;
  750. // Set the return value for the method
  751. if (hr != ERROR_SUCCESS)
  752. *pbRetVal = FALSE;
  753. else
  754. *pbRetVal = TRUE;
  755. m_hrDialErr = hr;
  756. return S_OK;
  757. }
  758. //+---------------------------------------------------------------------------
  759. //
  760. // Function: MyRasGetEntryProperties()
  761. //
  762. // Synopsis: Performs some buffer size checks and then calls RasGetEntryProperties()
  763. // See the RasGetEntryProperties() docs to understand why this is needed.
  764. //
  765. // Arguments: Same as RasGetEntryProperties with the following exceptions:
  766. // lplpRasEntryBuff -- pointer to a pointer to a RASENTRY struct. On successfull
  767. // return, *lplpRasEntryBuff will point to the RASENTRY struct
  768. // and buffer returned by RasGetEntryProperties.
  769. // NOTE: should not have memory allocated to it at call time!
  770. // To emphasize this point, *lplpRasEntryBuff must be NULL
  771. // lplpRasDevInfoBuff -- pointer to a pointer to a RASDEVINFO struct. On successfull
  772. // return, *lplpRasDevInfoBuff will point to the RASDEVINFO struct
  773. // and buffer returned by RasGetEntryProperties.
  774. // NOTE: should not have memory allocated to it at call time!
  775. // To emphasize this point, *lplpRasDevInfoBuff must be NULL
  776. // NOTE: Even on a successfull call to RasGetEntryProperties,
  777. // *lplpRasDevInfoBuff may return with a value of NULL
  778. // (occurs when there is no extra device info)
  779. //
  780. // Returns: ERROR_NOT_ENOUGH_MEMORY if unable to allocate either RASENTRY or RASDEVINFO buffer
  781. // Otherwise, it retuns the error code from the call to RasGetEntryProperties.
  782. // NOTE: if return is anything other than ERROR_SUCCESS, *lplpRasDevInfoBuff and
  783. // *lplpRasEntryBuff will be NULL,
  784. // and *lpdwRasEntryBuffSize and *lpdwRasDevInfoBuffSize will be 0
  785. //
  786. // Example:
  787. //
  788. // LPRASENTRY lpRasEntry = NULL;
  789. // LPRASDEVINFO lpRasDevInfo = NULL;
  790. // DWORD dwRasEntrySize, dwRasDevInfoSize;
  791. //
  792. // hr = MyRasGetEntryProperties( NULL,
  793. // g_pcDialErr->m_szConnectoid,
  794. // &lpRasEntry,
  795. // &dwRasEntrySize,
  796. // &lpRasDevInfo,
  797. // &dwRasDevInfoSize);
  798. //
  799. //
  800. // if (hr != ERROR_SUCCESS)
  801. // {
  802. // //handle errors here
  803. // } else
  804. // {
  805. // //continue processing
  806. // }
  807. //
  808. //
  809. // History: 9/10/96 JMazner Created for icwconn2
  810. // 9/17/96 JMazner Adapted for icwconn1
  811. // 1/8/98 DONALDM Moved to the new ICW/GetConn project
  812. //----------------------------------------------------------------------------
  813. HRESULT CRefDial::MyRasGetEntryProperties(LPTSTR lpszPhonebookFile,
  814. LPTSTR lpszPhonebookEntry,
  815. LPRASENTRY *lplpRasEntryBuff,
  816. LPDWORD lpdwRasEntryBuffSize,
  817. LPRASDEVINFO *lplpRasDevInfoBuff,
  818. LPDWORD lpdwRasDevInfoBuffSize)
  819. {
  820. HRESULT hr;
  821. RNAAPI *pcRNA = NULL;
  822. DWORD dwOldDevInfoBuffSize;
  823. Assert( NULL != lplpRasEntryBuff );
  824. Assert( NULL != lpdwRasEntryBuffSize );
  825. Assert( NULL != lplpRasDevInfoBuff );
  826. Assert( NULL != lpdwRasDevInfoBuffSize );
  827. *lpdwRasEntryBuffSize = 0;
  828. *lpdwRasDevInfoBuffSize = 0;
  829. pcRNA = new RNAAPI;
  830. if (!pcRNA)
  831. {
  832. hr = ERROR_NOT_ENOUGH_MEMORY;
  833. goto MyRasGetEntryPropertiesErrExit;
  834. }
  835. // use RasGetEntryProperties with a NULL lpRasEntry pointer to find out size buffer we need
  836. // As per the docs' recommendation, do the same with a NULL lpRasDevInfo pointer.
  837. hr = pcRNA->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  838. (LPBYTE) NULL,
  839. lpdwRasEntryBuffSize,
  840. (LPBYTE) NULL,
  841. lpdwRasDevInfoBuffSize);
  842. // we expect the above call to fail because the buffer size is 0
  843. // If it doesn't fail, that means our RasEntry is messed, so we're in trouble
  844. if( ERROR_BUFFER_TOO_SMALL != hr )
  845. {
  846. goto MyRasGetEntryPropertiesErrExit;
  847. }
  848. // dwRasEntryBuffSize and dwRasDevInfoBuffSize now contain the size needed for their
  849. // respective buffers, so allocate the memory for them
  850. // dwRasEntryBuffSize should never be less than the size of the RASENTRY struct.
  851. // If it is, we'll run into problems sticking values into the struct's fields
  852. Assert( *lpdwRasEntryBuffSize >= sizeof(RASENTRY) );
  853. if (m_reflpRasEntryBuff)
  854. {
  855. if (*lpdwRasEntryBuffSize > m_reflpRasEntryBuff->dwSize)
  856. {
  857. LPRASENTRY pTemp = m_reflpRasEntryBuff;
  858. m_reflpRasEntryBuff = (LPRASENTRY)GlobalReAlloc(pTemp, *lpdwRasEntryBuffSize, GPTR);
  859. if (m_reflpRasEntryBuff == NULL)
  860. {
  861. GlobalFree(pTemp);
  862. }
  863. }
  864. }
  865. else
  866. {
  867. m_reflpRasEntryBuff = (LPRASENTRY)GlobalAlloc(GPTR,*lpdwRasEntryBuffSize);
  868. }
  869. if (!m_reflpRasEntryBuff)
  870. {
  871. hr = ERROR_NOT_ENOUGH_MEMORY;
  872. goto MyRasGetEntryPropertiesErrExit;
  873. }
  874. // This is a bit convoluted: lpRasEntrySize->dwSize needs to contain the size of _only_ the
  875. // RASENTRY structure, and _not_ the actual size of the buffer that lpRasEntrySize points to.
  876. // This is because the dwSize field is used by RAS for compatability purposes to determine which
  877. // version of the RASENTRY struct we're using.
  878. // Same holds for lpRasDevInfo->dwSize
  879. m_reflpRasEntryBuff->dwSize = sizeof(RASENTRY);
  880. //
  881. // Allocate the DeviceInfo size that RasGetEntryProperties told us we needed.
  882. // If size is 0, don't alloc anything
  883. //
  884. if( *lpdwRasDevInfoBuffSize > 0 )
  885. {
  886. Assert( *lpdwRasDevInfoBuffSize >= sizeof(RASDEVINFO) );
  887. if (m_reflpRasDevInfoBuff)
  888. {
  889. // check if existing size is not sufficient
  890. if ( *lpdwRasDevInfoBuffSize > m_reflpRasDevInfoBuff->dwSize )
  891. {
  892. LPRASDEVINFO pTemp = m_reflpRasDevInfoBuff;
  893. m_reflpRasDevInfoBuff = (LPRASDEVINFO)GlobalReAlloc(pTemp,*lpdwRasDevInfoBuffSize, GPTR);
  894. if (m_reflpRasDevInfoBuff == NULL)
  895. {
  896. GlobalFree(pTemp);
  897. }
  898. }
  899. }
  900. else
  901. {
  902. m_reflpRasDevInfoBuff = (LPRASDEVINFO)GlobalAlloc(GPTR,*lpdwRasDevInfoBuffSize);
  903. }
  904. if (!m_reflpRasDevInfoBuff)
  905. {
  906. hr = ERROR_NOT_ENOUGH_MEMORY;
  907. goto MyRasGetEntryPropertiesErrExit;
  908. }
  909. }
  910. else
  911. {
  912. m_reflpRasDevInfoBuff = NULL;
  913. }
  914. if( m_reflpRasDevInfoBuff )
  915. {
  916. m_reflpRasDevInfoBuff->dwSize = sizeof(RASDEVINFO);
  917. }
  918. // now we're ready to make the actual call...
  919. // jmazner see below for why this is needed
  920. dwOldDevInfoBuffSize = *lpdwRasDevInfoBuffSize;
  921. hr = pcRNA->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  922. (LPBYTE) m_reflpRasEntryBuff,
  923. lpdwRasEntryBuffSize,
  924. (LPBYTE) m_reflpRasDevInfoBuff,
  925. lpdwRasDevInfoBuffSize);
  926. // jmazner 10/7/96 Normandy #8763
  927. // For unknown reasons, in some cases on win95, devInfoBuffSize increases after the above call,
  928. // but the return code indicates success, not BUFFER_TOO_SMALL. If this happens, set the
  929. // size back to what it was before the call, so the DevInfoBuffSize and the actuall space allocated
  930. // for the DevInfoBuff match on exit.
  931. if( (ERROR_SUCCESS == hr) && (dwOldDevInfoBuffSize != *lpdwRasDevInfoBuffSize) )
  932. {
  933. *lpdwRasDevInfoBuffSize = dwOldDevInfoBuffSize;
  934. }
  935. if( pcRNA )
  936. {
  937. delete pcRNA;
  938. pcRNA = NULL;
  939. }
  940. *lplpRasEntryBuff = m_reflpRasEntryBuff;
  941. *lplpRasDevInfoBuff = m_reflpRasDevInfoBuff;
  942. return( hr );
  943. MyRasGetEntryPropertiesErrExit:
  944. if(m_reflpRasEntryBuff)
  945. {
  946. GlobalFree(m_reflpRasEntryBuff);
  947. m_reflpRasEntryBuff = NULL;
  948. *lplpRasEntryBuff = NULL;
  949. }
  950. if(m_reflpRasDevInfoBuff)
  951. {
  952. GlobalFree(m_reflpRasDevInfoBuff);
  953. m_reflpRasDevInfoBuff = NULL;
  954. *lplpRasDevInfoBuff = NULL;
  955. }
  956. if( pcRNA )
  957. {
  958. delete pcRNA;
  959. pcRNA = NULL;
  960. }
  961. *lpdwRasEntryBuffSize = 0;
  962. *lpdwRasDevInfoBuffSize = 0;
  963. return( hr );
  964. }
  965. //+---------------------------------------------------------------------------
  966. //
  967. // Function: LineCallback()
  968. //
  969. // Synopsis: Call back for TAPI line
  970. //
  971. //+---------------------------------------------------------------------------
  972. void CALLBACK LineCallback(DWORD hDevice,
  973. DWORD dwMessage,
  974. DWORD dwInstance,
  975. DWORD dwParam1,
  976. DWORD dwParam2,
  977. DWORD dwParam3)
  978. {
  979. }
  980. HRESULT MyGetFileVersion(LPCTSTR pszFileName, LPGATHERINFO lpGatherInfo)
  981. {
  982. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  983. DWORD dwSize = 0;
  984. DWORD dwTemp = 0;
  985. LPVOID pv = NULL, pvVerInfo = NULL;
  986. UINT uiSize;
  987. DWORD dwVerPiece;
  988. //int idx;
  989. // verify parameters
  990. //
  991. Assert(pszFileName && lpGatherInfo);
  992. // Get version
  993. //
  994. dwSize = GetFileVersionInfoSize((LPTSTR)pszFileName,&dwTemp);
  995. if (!dwSize)
  996. {
  997. hr = GetLastError();
  998. goto MyGetFileVersionExit;
  999. }
  1000. pv = (LPVOID)GlobalAlloc(GPTR, (size_t)dwSize);
  1001. if (!pv) goto MyGetFileVersionExit;
  1002. if (!GetFileVersionInfo((LPTSTR)pszFileName,dwTemp,dwSize,pv))
  1003. {
  1004. hr = GetLastError();
  1005. goto MyGetFileVersionExit;
  1006. }
  1007. if (!VerQueryValue(pv,TEXT("\\\0"),&pvVerInfo,&uiSize))
  1008. {
  1009. hr = GetLastError();
  1010. goto MyGetFileVersionExit;
  1011. }
  1012. pvVerInfo = (LPVOID)((DWORD_PTR)pvVerInfo + sizeof(DWORD)*4);
  1013. lpGatherInfo->m_szSUVersion[0] = '\0';
  1014. dwVerPiece = (*((LPDWORD)pvVerInfo)) >> 16;
  1015. wsprintf(lpGatherInfo->m_szSUVersion,TEXT("%d."),dwVerPiece);
  1016. dwVerPiece = (*((LPDWORD)pvVerInfo)) & 0x0000ffff;
  1017. wsprintf(lpGatherInfo->m_szSUVersion,TEXT("%s%d."),lpGatherInfo->m_szSUVersion,dwVerPiece);
  1018. dwVerPiece = (((LPDWORD)pvVerInfo)[1]) >> 16;
  1019. wsprintf(lpGatherInfo->m_szSUVersion,TEXT("%s%d."),lpGatherInfo->m_szSUVersion,dwVerPiece);
  1020. dwVerPiece = (((LPDWORD)pvVerInfo)[1]) & 0x0000ffff;
  1021. wsprintf(lpGatherInfo->m_szSUVersion,TEXT("%s%d"),lpGatherInfo->m_szSUVersion,dwVerPiece);
  1022. if (!VerQueryValue(pv,TEXT("\\VarFileInfo\\Translation"),&pvVerInfo,&uiSize))
  1023. {
  1024. hr = GetLastError();
  1025. goto MyGetFileVersionExit;
  1026. }
  1027. // separate version information from character set
  1028. lpGatherInfo->m_lcidApps = (LCID)(LOWORD(*(DWORD*)pvVerInfo));
  1029. hr = ERROR_SUCCESS;
  1030. MyGetFileVersionExit:
  1031. if (pv) GlobalFree(pv);
  1032. return hr;
  1033. }
  1034. DWORD CRefDial::FillGatherInfoStruct(LPGATHERINFO lpGatherInfo)
  1035. {
  1036. USES_CONVERSION;
  1037. HKEY hkey = NULL;
  1038. SYSTEM_INFO si;
  1039. TCHAR szTempPath[MAX_PATH];
  1040. DWORD dwRet = ERROR_SUCCESS;
  1041. lpGatherInfo->m_lcidUser = GetUserDefaultLCID();
  1042. lpGatherInfo->m_lcidSys = GetSystemDefaultLCID();
  1043. OSVERSIONINFO osvi;
  1044. ZeroMemory(&osvi,sizeof(OSVERSIONINFO));
  1045. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1046. if (!GetVersionEx(&osvi))
  1047. {
  1048. // Nevermind, we'll just assume the version is 0.0 if we can't read it
  1049. //
  1050. ZeroMemory(&osvi,sizeof(OSVERSIONINFO));
  1051. }
  1052. lpGatherInfo->m_dwOS = osvi.dwPlatformId;
  1053. lpGatherInfo->m_dwMajorVersion = osvi.dwMajorVersion;
  1054. lpGatherInfo->m_dwMinorVersion = osvi.dwMinorVersion;
  1055. ZeroMemory(&si,sizeof(SYSTEM_INFO));
  1056. GetSystemInfo(&si);
  1057. lpGatherInfo->m_wArchitecture = si.wProcessorArchitecture;
  1058. // Sign-up version
  1059. //
  1060. lpGatherInfo->m_szSUVersion[0] = '\0';
  1061. if( GetModuleFileName(_Module.GetModuleInstance(), szTempPath, MAX_PATH))
  1062. {
  1063. if ((MyGetFileVersion(szTempPath, lpGatherInfo)) != ERROR_SUCCESS)
  1064. {
  1065. return (GetLastError());
  1066. }
  1067. }
  1068. else
  1069. return( GetLastError() );
  1070. // OEM code
  1071. //
  1072. TCHAR szOeminfoPath[MAX_PATH + 1];
  1073. TCHAR *lpszTerminator = NULL;
  1074. TCHAR *lpszLastChar = NULL;
  1075. TCHAR szTemp[MAX_PATH];
  1076. if( 0 != GetSystemDirectory( szOeminfoPath, MAX_PATH + 1 ) )
  1077. {
  1078. lpszTerminator = &(szOeminfoPath[ lstrlen(szOeminfoPath) ]);
  1079. lpszLastChar = CharPrev( szOeminfoPath, lpszTerminator );
  1080. if( '\\' != *lpszLastChar )
  1081. {
  1082. lpszLastChar = CharNext( lpszLastChar );
  1083. *lpszLastChar = '\\';
  1084. lpszLastChar = CharNext( lpszLastChar );
  1085. *lpszLastChar = '\0';
  1086. }
  1087. lstrcat( szOeminfoPath, ICW_OEMINFO_FILENAME );
  1088. //Default oem code must be NULL if it doesn't exist in oeminfo.ini
  1089. if (!GetPrivateProfileString(ICW_OEMINFO_OEMSECTION,
  1090. ICW_OEMINFO_OEMKEY,
  1091. TEXT(""),
  1092. m_szOEM,
  1093. MAX_OEMNAME,
  1094. szOeminfoPath))
  1095. {
  1096. //oem = (nothing), set to NULL
  1097. m_szOEM[0] = '\0';
  1098. }
  1099. // Get the Product Code, Promo code and ALLOFFERS code if they exist
  1100. if (GetPrivateProfileString(ICW_OEMINFO_ICWSECTION,
  1101. ICW_OEMINFO_PRODUCTCODE,
  1102. DEFAULT_PRODUCTCODE,
  1103. szTemp,
  1104. ARRAYSIZE(szTemp),
  1105. szOeminfoPath))
  1106. {
  1107. m_bstrProductCode = A2BSTR(szTemp);
  1108. }
  1109. else
  1110. m_bstrProductCode = A2BSTR(DEFAULT_PRODUCTCODE);
  1111. if (GetPrivateProfileString(ICW_OEMINFO_ICWSECTION,
  1112. ICW_OEMINFO_PROMOCODE,
  1113. DEFAULT_PROMOCODE,
  1114. szTemp,
  1115. ARRAYSIZE(szTemp),
  1116. szOeminfoPath))
  1117. {
  1118. m_bstrPromoCode = A2BSTR(szTemp);
  1119. }
  1120. else
  1121. m_bstrPromoCode = A2BSTR(DEFAULT_PROMOCODE);
  1122. m_lAllOffers = GetPrivateProfileInt(ICW_OEMINFO_ICWSECTION,
  1123. ICW_OEMINFO_ALLOFFERS,
  1124. 1,
  1125. szOeminfoPath);
  1126. }
  1127. // 2/20/97 jmazner Olympus #259
  1128. if ( RegOpenKey(HKEY_LOCAL_MACHINE,ICWSETTINGSPATH,&hkey) == ERROR_SUCCESS)
  1129. {
  1130. DWORD dwSize;
  1131. DWORD dwType;
  1132. dwType = REG_SZ;
  1133. dwSize = sizeof(TCHAR)*(MAX_RELPROD + 1);
  1134. if (RegQueryValueEx(hkey,RELEASEPRODUCTKEY,NULL,&dwType,(LPBYTE)&lpGatherInfo->m_szRelProd[0],&dwSize) != ERROR_SUCCESS)
  1135. lpGatherInfo->m_szRelProd[0] = '\0';
  1136. dwSize = sizeof(TCHAR)*(MAX_RELVER + 1);
  1137. if (RegQueryValueEx(hkey,RELEASEVERSIONKEY,NULL,&dwType,(LPBYTE)&lpGatherInfo->m_szRelVer[0],&dwSize) != ERROR_SUCCESS)
  1138. lpGatherInfo->m_szRelVer[0] = '\0';
  1139. RegCloseKey(hkey);
  1140. }
  1141. // PromoCode
  1142. lpGatherInfo->m_szPromo[0] = '\0';
  1143. TCHAR szPIDPath[MAX_PATH]; // Reg path to the PID
  1144. // Form the Path, it is HKLM\\Software\\Microsoft\Windows[ NT]\\CurrentVersion
  1145. lstrcpy(szPIDPath, TEXT("Software\\Microsoft\\Windows"));
  1146. IF_NTONLY
  1147. lstrcat(szPIDPath, TEXT(" NT"));
  1148. ENDIF_NTONLY
  1149. lstrcat(szPIDPath, TEXT("\\CurrentVersion"));
  1150. BYTE byDigitalPID[MAX_DIGITAL_PID];
  1151. // Get the Product ID for this machine
  1152. if ( RegOpenKey(HKEY_LOCAL_MACHINE,szPIDPath,&hkey) == ERROR_SUCCESS)
  1153. {
  1154. DWORD dwSize;
  1155. DWORD dwType;
  1156. dwType = REG_BINARY;
  1157. dwSize = sizeof(byDigitalPID);
  1158. if (RegQueryValueEx(hkey,
  1159. c_szRegStrValDigitalPID,
  1160. NULL,
  1161. &dwType,
  1162. (LPBYTE)byDigitalPID,
  1163. &dwSize) == ERROR_SUCCESS)
  1164. {
  1165. // BINHEX the digital PID data so we can send it to the ref_server
  1166. int i = 0;
  1167. BYTE by;
  1168. for (DWORD dwX = 0; dwX < dwSize; dwX++)
  1169. {
  1170. by = byDigitalPID[dwX];
  1171. m_szPID[i++] = g_BINTOHEXLookup[((by & 0xF0) >> 4)];
  1172. m_szPID[i++] = g_BINTOHEXLookup[(by & 0x0F)];
  1173. }
  1174. m_szPID[i] = '\0';
  1175. }
  1176. else
  1177. {
  1178. m_szPID[0] = '\0';
  1179. }
  1180. RegCloseKey(hkey);
  1181. }
  1182. return( dwRet );
  1183. }
  1184. // ############################################################################
  1185. HRESULT CRefDial::CreateEntryFromDUNFile(LPTSTR pszDunFile)
  1186. {
  1187. TCHAR szFileName[MAX_PATH];
  1188. TCHAR szUserName[UNLEN+1];
  1189. TCHAR szPassword[PWLEN+1];
  1190. LPTSTR pszTemp;
  1191. HRESULT hr;
  1192. BOOL fNeedsRestart=FALSE;
  1193. hr = ERROR_SUCCESS;
  1194. // Get fully qualified path name
  1195. //
  1196. if (!SearchPath(NULL,pszDunFile,NULL,MAX_PATH,&szFileName[0],&pszTemp))
  1197. {
  1198. hr = ERROR_FILE_NOT_FOUND;
  1199. goto CreateEntryFromDUNFileExit;
  1200. }
  1201. // save current DUN file name in global
  1202. lstrcpy(m_szCurrentDUNFile, &szFileName[0]);
  1203. hr = m_ISPImport.ImportConnection (&szFileName[0], m_szISPSupportNumber, m_szEntryName, szUserName, szPassword,&fNeedsRestart);
  1204. // place the name of the connectoid in the registry
  1205. //
  1206. if (ERROR_SUCCESS != (StoreInSignUpReg((LPBYTE)m_szEntryName, lstrlen(m_szEntryName)+1, REG_SZ, RASENTRYVALUENAME)))
  1207. {
  1208. goto CreateEntryFromDUNFileExit;
  1209. }
  1210. lstrcpy(m_szLastDUNFile, pszDunFile);
  1211. CreateEntryFromDUNFileExit:
  1212. return hr;
  1213. }
  1214. HRESULT CRefDial::UserPickANumber(HWND hWnd,
  1215. LPGATHERINFO lpGatherInfo,
  1216. PSUGGESTINFO lpSuggestInfo,
  1217. HINSTANCE hPHBKDll,
  1218. DWORD_PTR dwPhoneBook,
  1219. TCHAR *pszConnectoid,
  1220. DWORD dwSize,
  1221. DWORD dwPhoneDisplayFlags)
  1222. {
  1223. USES_CONVERSION;
  1224. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1225. FARPROC fp;
  1226. RASENTRY *prasentry = NULL;
  1227. RASDEVINFO *prasdevinfo = NULL;
  1228. DWORD dwRasentrySize = 0;
  1229. DWORD dwRasdevinfoSize = 0;
  1230. TCHAR szTemp[256];
  1231. TCHAR *ppszDunFiles[1];
  1232. TCHAR *ppszTemp[1];
  1233. TCHAR szDunFile[12];
  1234. BOOL bStatus = TRUE;
  1235. //
  1236. // If the phone book can't find a number let the user pick
  1237. //
  1238. ppszDunFiles[0] = &szDunFile[0];
  1239. lstrcpy(&szDunFile[0],OLE2A(m_bstrISPFile));
  1240. fp = GetProcAddress(hPHBKDll, PHBK_DISPLAYAPI);
  1241. AssertMsg(fp != NULL,TEXT("display access number api is missing"));
  1242. ppszTemp[0] = szTemp;
  1243. //
  1244. // donsc - 3/10/98
  1245. //
  1246. // We have seen at least one code-path that could bring you into
  1247. // here with lpSuggestInfo or lpGatherInfo == NULL. That has been
  1248. // fixed, but to be defensive, we will ensure that these pointers
  1249. // are valid...even if they don't have information, we will still let
  1250. // the user pick a number.
  1251. SUGGESTINFO SugInfo;
  1252. GATHERINFO GatInfo;
  1253. ::ZeroMemory(&SugInfo,sizeof(SugInfo));
  1254. ::ZeroMemory(&GatInfo,sizeof(GatInfo));
  1255. if(lpSuggestInfo == NULL)
  1256. {
  1257. TraceMsg(TF_GENERAL, TEXT("UserPickANumber: lpSuggestInfo is NULL\n"));
  1258. lpSuggestInfo = &SugInfo;
  1259. }
  1260. if(lpGatherInfo == NULL)
  1261. {
  1262. TraceMsg(TF_GENERAL, TEXT("UserPickANumber: lpGatherInfo is NULL\n"));
  1263. lpGatherInfo = &GatInfo;
  1264. }
  1265. hr = ((PFNPHONEDISPLAY)fp)(dwPhoneBook,
  1266. ppszTemp,
  1267. ppszDunFiles,
  1268. &(lpSuggestInfo->wNumber),
  1269. &(lpSuggestInfo->dwCountryID),
  1270. &(lpGatherInfo->m_wState),
  1271. lpGatherInfo->m_fType,
  1272. lpGatherInfo->m_bMask,
  1273. hWnd,
  1274. dwPhoneDisplayFlags);
  1275. if (hr != ERROR_SUCCESS)
  1276. goto UserPickANumberExit;
  1277. ZeroMemory(pszConnectoid,dwSize);
  1278. hr = ReadSignUpReg((LPBYTE)pszConnectoid, &dwSize, REG_SZ,
  1279. RASENTRYVALUENAME);
  1280. if (hr != ERROR_SUCCESS)
  1281. goto UserPickANumberExit;
  1282. hr = MyRasGetEntryProperties(NULL,
  1283. pszConnectoid,
  1284. &prasentry,
  1285. &dwRasentrySize,
  1286. &prasdevinfo,
  1287. &dwRasdevinfoSize);
  1288. if (hr != ERROR_SUCCESS)
  1289. goto UserPickANumberExit;
  1290. //
  1291. // Check to see if the user selected a phone number with a different dun file
  1292. // than the one already used to create the connectoid
  1293. //
  1294. TCHAR szTempPath[MAX_PATH];
  1295. // If we did not use dun file last time, assumed we used the default.
  1296. if ( *m_szLastDUNFile )
  1297. lstrcpy(szTempPath, m_szLastDUNFile);
  1298. else
  1299. bStatus = (ERROR_SUCCESS == GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_ISPINFO, INF_DUN_FILE,szTempPath,MAX_PATH));
  1300. if (bStatus)
  1301. {
  1302. if (_tcsicmp(szTempPath,ppszDunFiles[0]))
  1303. {
  1304. //
  1305. // Rats, they changed dun files. We now get to build the connectoid
  1306. // from scratch
  1307. //
  1308. if (CreateEntryFromDUNFile(ppszDunFiles[0]) == ERROR_SUCCESS)
  1309. {
  1310. prasentry = NULL;
  1311. dwRasentrySize = 0;
  1312. prasdevinfo = NULL;
  1313. dwRasdevinfoSize = 0;
  1314. hr = MyRasGetEntryProperties(NULL,
  1315. pszConnectoid,
  1316. &prasentry,
  1317. &dwRasentrySize,
  1318. &prasdevinfo,
  1319. &dwRasdevinfoSize);
  1320. if (hr != ERROR_SUCCESS || NULL == prasentry)
  1321. goto UserPickANumberExit;
  1322. BreakUpPhoneNumber(prasentry, szTemp);
  1323. prasentry->dwCountryID = lpSuggestInfo->dwCountryID;
  1324. }
  1325. else
  1326. {
  1327. hr = ERROR_READING_DUN;
  1328. goto UserPickANumberExit;
  1329. }
  1330. }
  1331. else
  1332. {
  1333. BreakUpPhoneNumber(prasentry, szTemp);
  1334. prasentry->dwCountryID = lpSuggestInfo->dwCountryID;
  1335. }
  1336. }
  1337. else
  1338. {
  1339. hr = ERROR_READING_ISP;
  1340. goto UserPickANumberExit;
  1341. }
  1342. prasentry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  1343. //
  1344. // Write out new connectoid
  1345. //
  1346. if (m_pcRNA)
  1347. hr = m_pcRNA->RasSetEntryProperties(NULL, pszConnectoid,
  1348. (LPBYTE)prasentry,
  1349. dwRasentrySize,
  1350. (LPBYTE)prasdevinfo,
  1351. dwRasdevinfoSize);
  1352. if (hr != ERROR_SUCCESS)
  1353. goto UserPickANumberExit;
  1354. return hr;
  1355. UserPickANumberExit:
  1356. TCHAR szBuff256[257];
  1357. if (hr == ERROR_READING_ISP)
  1358. {
  1359. MsgBox(IDS_CANTREADMSNSUISP, MB_MYERROR);
  1360. } else if (hr == ERROR_READING_DUN) {
  1361. MsgBox(IDS_CANTREADMSDUNFILE, MB_MYERROR);
  1362. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1363. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWPHBK.DLL"));
  1364. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1365. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1366. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWDL.DLL"));
  1367. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1368. } else if (hr == ERROR_USERBACK || hr == ERROR_USERCANCEL) {
  1369. // Do nothing
  1370. } else if (hr == ERROR_NOT_ENOUGH_MEMORY) {
  1371. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  1372. } else if ((hr == ERROR_NO_MORE_ITEMS) || (hr == ERROR_INVALID_DATA)
  1373. || (hr == ERROR_FILE_NOT_FOUND)) {
  1374. MsgBox(IDS_CORRUPTPHONEBOOK, MB_MYERROR);
  1375. } else if (hr != ERROR_SUCCESS) {
  1376. wsprintf(szBuff256,TEXT("You can ignore this, just report it and include this number (%d).\n"),hr);
  1377. AssertMsg(0,szBuff256);
  1378. }
  1379. return hr;
  1380. }
  1381. HRESULT CRefDial::SetupForRASDialing
  1382. (
  1383. LPGATHERINFO lpGatherInfo,
  1384. HINSTANCE hPHBKDll,
  1385. DWORD_PTR *lpdwPhoneBook,
  1386. PSUGGESTINFO *ppSuggestInfo,
  1387. TCHAR *pszConnectoid,
  1388. BOOL FAR *bConnectiodCreated
  1389. )
  1390. {
  1391. USES_CONVERSION;
  1392. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1393. FARPROC fp;
  1394. PSUGGESTINFO pSuggestInfo = NULL;
  1395. TCHAR szEntry[MAX_RASENTRYNAME];
  1396. DWORD dwSize = sizeof(szEntry);
  1397. RASENTRY *prasentry = NULL;
  1398. RASDEVINFO *prasdevinfo = NULL;
  1399. DWORD dwRasentrySize = 0;
  1400. DWORD dwRasdevinfoSize = 0;
  1401. HINSTANCE hRasDll =NULL;
  1402. TCHAR szBuff256[257];
  1403. LPRASCONN lprasconn = NULL;
  1404. // Load the connectoid
  1405. //
  1406. if (!m_pcRNA)
  1407. m_pcRNA = new RNAAPI;
  1408. if (!m_pcRNA)
  1409. goto SetupForRASDialingExit;
  1410. prasentry = (RASENTRY*)GlobalAlloc(GPTR,sizeof(RASENTRY)+2);
  1411. Assert(prasentry);
  1412. if (!prasentry)
  1413. {
  1414. hr = GetLastError();
  1415. goto SetupForRASDialingExit;
  1416. }
  1417. prasentry->dwSize = sizeof(RASENTRY);
  1418. dwRasentrySize = sizeof(RASENTRY);
  1419. prasdevinfo = (RASDEVINFO*)GlobalAlloc(GPTR,sizeof(RASDEVINFO));
  1420. Assert(prasdevinfo);
  1421. if (!prasdevinfo)
  1422. {
  1423. hr = GetLastError();
  1424. goto SetupForRASDialingExit;
  1425. }
  1426. prasdevinfo->dwSize = sizeof(RASDEVINFO);
  1427. dwRasdevinfoSize = sizeof(RASDEVINFO);
  1428. hr = ReadSignUpReg((LPBYTE)&szEntry[0], &dwSize, REG_SZ,
  1429. RASENTRYVALUENAME);
  1430. if (hr != ERROR_SUCCESS)
  1431. goto SetupForRASDialingExit;
  1432. #ifdef UNICODE
  1433. // Comment for UNICODE.
  1434. // RasGetEntryProperties fails in case of UNICODE
  1435. // because of size. So I ask the size first before actual call.
  1436. hr = m_pcRNA->RasGetEntryProperties(NULL, szEntry,
  1437. NULL,
  1438. &dwRasentrySize,
  1439. NULL,
  1440. &dwRasdevinfoSize);
  1441. #else
  1442. hr = m_pcRNA->RasGetEntryProperties(NULL, szEntry,
  1443. (LPBYTE)prasentry,
  1444. &dwRasentrySize,
  1445. (LPBYTE)prasdevinfo,
  1446. &dwRasdevinfoSize);
  1447. #endif
  1448. if (hr == ERROR_BUFFER_TOO_SMALL)
  1449. {
  1450. // Comment for UNICODE.
  1451. // This must be happen for UNICODE.
  1452. TraceMsg(TF_GENERAL,TEXT("CONNECT:RasGetEntryProperties failed, try a new size.\n"));
  1453. GlobalFree(prasentry);
  1454. prasentry = (RASENTRY*)GlobalAlloc(GPTR,((size_t)dwRasentrySize));
  1455. prasentry->dwSize = dwRasentrySize;
  1456. GlobalFree(prasdevinfo);
  1457. if(dwRasdevinfoSize > 0)
  1458. {
  1459. prasdevinfo = (RASDEVINFO*)GlobalAlloc(GPTR,((size_t)dwRasdevinfoSize));
  1460. prasdevinfo->dwSize = dwRasdevinfoSize;
  1461. }
  1462. else
  1463. prasdevinfo = NULL;
  1464. hr = m_pcRNA->RasGetEntryProperties(NULL, szEntry,
  1465. (LPBYTE)prasentry,
  1466. &dwRasentrySize,
  1467. (LPBYTE)prasdevinfo,
  1468. &dwRasdevinfoSize);
  1469. }
  1470. if (hr != ERROR_SUCCESS)
  1471. goto SetupForRASDialingExit;
  1472. lpGatherInfo->m_wState = 0;
  1473. lpGatherInfo->m_fType = TYPE_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  1474. lpGatherInfo->m_bMask = MASK_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  1475. //
  1476. // Check to see if the phone number was filled in
  1477. //
  1478. if (lstrcmp(&prasentry->szLocalPhoneNumber[0],DUN_NOPHONENUMBER) == 0)
  1479. {
  1480. //
  1481. // allocate and intialize memory
  1482. //
  1483. pSuggestInfo = (PSUGGESTINFO)GlobalAlloc(GPTR,sizeof(SUGGESTINFO));
  1484. Assert(pSuggestInfo);
  1485. if (!pSuggestInfo)
  1486. {
  1487. hr = GetLastError();
  1488. goto SetupForRASDialingExit;
  1489. }
  1490. *ppSuggestInfo = pSuggestInfo;
  1491. // set phone number type and mask
  1492. pSuggestInfo->fType = TYPE_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  1493. pSuggestInfo->bMask = MASK_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  1494. pSuggestInfo->wAreaCode = Sz2W(lpGatherInfo->m_szAreaCode);
  1495. pSuggestInfo->dwCountryID = lpGatherInfo->m_dwCountry;
  1496. // Load Microsoft's phonebook
  1497. //
  1498. fp = GetProcAddress(hPHBKDll,PHBK_LOADAPI);
  1499. AssertMsg(fp != NULL,TEXT("PhoneBookLoad is missing from icwphbk.dll"));
  1500. hr = ((PFNPHONEBOOKLOAD)fp)(OLE2A(m_bstrISPFile),lpdwPhoneBook);
  1501. if (hr != ERROR_SUCCESS) goto SetupForRASDialingExit;
  1502. AssertMsg((*lpdwPhoneBook == TRUE),TEXT("Phonebook Load return no error and 0 for phonebook"));
  1503. //
  1504. // Load Suggest procedure
  1505. //
  1506. fp = GetProcAddress(hPHBKDll,PHBK_SUGGESTAPI);
  1507. AssertMsg(fp != NULL,TEXT("PhoneBookSuggest is missing from icwphbk.dll"));
  1508. // Set the number of suggestions
  1509. pSuggestInfo->wNumber = NUM_PHBK_SUGGESTIONS;
  1510. // get phone number
  1511. hr = ((PFPHONEBOOKSUGGEST)fp)(*lpdwPhoneBook,pSuggestInfo);
  1512. // Inore error because we can continue even without a suggested
  1513. // phone number (the user will just have to pick one).
  1514. hr = ERROR_SUCCESS;
  1515. }
  1516. else
  1517. {
  1518. ZeroMemory(pszConnectoid, dwSize);
  1519. hr = ReadSignUpReg((LPBYTE)pszConnectoid, &dwSize, REG_SZ,
  1520. RASENTRYVALUENAME);
  1521. if (hr != ERROR_SUCCESS)
  1522. goto SetupForRASDialingExit;
  1523. // Use the RASENTRY that we have to create the connectiod
  1524. hr = m_pcRNA->RasSetEntryProperties(NULL,
  1525. pszConnectoid,
  1526. (LPBYTE)prasentry,
  1527. dwRasentrySize,
  1528. (LPBYTE)prasdevinfo,
  1529. dwRasdevinfoSize);
  1530. *bConnectiodCreated = TRUE;
  1531. }
  1532. SetupForRASDialingExit:
  1533. if (prasentry)
  1534. GlobalFree(prasentry);
  1535. if (prasdevinfo)
  1536. GlobalFree(prasdevinfo);
  1537. if (hr == ERROR_READING_ISP)
  1538. {
  1539. MsgBox(IDS_CANTREADMSNSUISP, MB_MYERROR);
  1540. } else if (hr == ERROR_READING_DUN) {
  1541. MsgBox(IDS_CANTREADMSDUNFILE, MB_MYERROR);
  1542. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1543. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWPHBK.DLL"));
  1544. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1545. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1546. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWDL.DLL"));
  1547. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1548. } else if (hr == ERROR_USERBACK || hr == ERROR_USERCANCEL) {
  1549. // Do nothing
  1550. } else if (hr == ERROR_NOT_ENOUGH_MEMORY) {
  1551. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  1552. } else if ((hr == ERROR_NO_MORE_ITEMS) || (hr == ERROR_INVALID_DATA)
  1553. || (hr == ERROR_FILE_NOT_FOUND)) {
  1554. MsgBox(IDS_CORRUPTPHONEBOOK, MB_MYERROR);
  1555. } else if (hr != ERROR_SUCCESS) {
  1556. wsprintf(szBuff256,TEXT("You can ignore this, just report it and include this number (%d).\n"),hr);
  1557. AssertMsg(0,szBuff256);
  1558. }
  1559. return hr;
  1560. }
  1561. // 10/22/96 jmazner Normandy #9923
  1562. // Since in SetupConnectoidExit we're treating results other than ERROR_SUCCESS as
  1563. // indicating successfull completion, we need bSuccess to provide a simple way for the
  1564. // caller to tell whether the function completed.
  1565. HRESULT CRefDial::SetupConnectoid
  1566. (
  1567. PSUGGESTINFO pSuggestInfo,
  1568. int irc,
  1569. TCHAR *pszConnectoid,
  1570. DWORD dwSize,
  1571. BOOL *pbSuccess
  1572. )
  1573. {
  1574. USES_CONVERSION;
  1575. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1576. RASENTRY *prasentry = NULL;
  1577. RASDEVINFO *prasdevinfo = NULL;
  1578. DWORD dwRasentrySize = 0;
  1579. DWORD dwRasdevinfoSize = 0;
  1580. HINSTANCE hPHBKDll = NULL;
  1581. HINSTANCE hRasDll =NULL;
  1582. LPTSTR lpszSetupFile;
  1583. LPRASCONN lprasconn = NULL;
  1584. CMcRegistry reg;
  1585. Assert(pbSuccess);
  1586. if (!pSuggestInfo)
  1587. {
  1588. hr = ERROR_PHBK_NOT_FOUND;
  1589. goto SetupConnectoidExit;
  1590. }
  1591. lpszSetupFile = m_szCurrentDUNFile[0] != '\0' ? m_szCurrentDUNFile : OLE2A(m_bstrISPFile);
  1592. if (lstrcmp(pSuggestInfo->rgpAccessEntry[irc]->szDataCenter,lpszSetupFile))
  1593. {
  1594. hr = CreateEntryFromDUNFile(pSuggestInfo->rgpAccessEntry[irc]->szDataCenter);
  1595. if (hr == ERROR_SUCCESS)
  1596. {
  1597. ZeroMemory(pszConnectoid, dwSize);
  1598. hr = ReadSignUpReg((LPBYTE)pszConnectoid, &dwSize, REG_SZ,
  1599. RASENTRYVALUENAME);
  1600. if (hr != ERROR_SUCCESS)
  1601. goto SetupConnectoidExit;
  1602. if( prasentry )
  1603. {
  1604. GlobalFree( prasentry );
  1605. prasentry = NULL;
  1606. dwRasentrySize = NULL;
  1607. }
  1608. if( prasdevinfo )
  1609. {
  1610. GlobalFree( prasdevinfo );
  1611. prasdevinfo = NULL;
  1612. dwRasdevinfoSize = NULL;
  1613. }
  1614. hr = MyRasGetEntryProperties(NULL,
  1615. pszConnectoid,
  1616. &prasentry,
  1617. &dwRasentrySize,
  1618. &prasdevinfo,
  1619. &dwRasdevinfoSize);
  1620. if (hr != ERROR_SUCCESS || NULL == prasentry)
  1621. goto SetupConnectoidExit;
  1622. }
  1623. else
  1624. {
  1625. // 10/22/96 jmazner Normandy #9923
  1626. goto SetupConnectoidExit;
  1627. }
  1628. }
  1629. else
  1630. {
  1631. goto SetupConnectoidExit;
  1632. }
  1633. prasentry->dwCountryID = pSuggestInfo->rgpAccessEntry[irc]->dwCountryID;
  1634. lstrcpyn(prasentry->szAreaCode,
  1635. pSuggestInfo->rgpAccessEntry[irc]->szAreaCode,
  1636. ARRAYSIZE(prasentry->szAreaCode));
  1637. lstrcpyn(prasentry->szLocalPhoneNumber,
  1638. pSuggestInfo->rgpAccessEntry[irc]->szAccessNumber,
  1639. ARRAYSIZE(prasentry->szLocalPhoneNumber));
  1640. prasentry->dwCountryCode = 0;
  1641. prasentry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  1642. // 10/19/96 jmazner Multiple modems problems
  1643. // If no device name and type has been specified, grab the one we've stored
  1644. // in ConfigRasEntryDevice
  1645. if( 0 == lstrlen(prasentry->szDeviceName) )
  1646. {
  1647. // doesn't make sense to have an empty device name but a valid device type
  1648. Assert( 0 == lstrlen(prasentry->szDeviceType) );
  1649. // double check that we've already stored the user's choice.
  1650. Assert( lstrlen(m_ISPImport.m_szDeviceName) );
  1651. Assert( lstrlen(m_ISPImport.m_szDeviceType) );
  1652. lstrcpyn( prasentry->szDeviceName, m_ISPImport.m_szDeviceName, lstrlen(m_ISPImport.m_szDeviceName) );
  1653. lstrcpyn( prasentry->szDeviceType, m_ISPImport.m_szDeviceType, lstrlen(m_ISPImport.m_szDeviceType) );
  1654. }
  1655. // Write out new connectoid
  1656. if (m_pcRNA)
  1657. hr = m_pcRNA->RasSetEntryProperties(NULL, pszConnectoid,
  1658. (LPBYTE)prasentry,
  1659. dwRasentrySize,
  1660. (LPBYTE)prasdevinfo,
  1661. dwRasdevinfoSize);
  1662. // Set this connetiod to have not proxy enabled
  1663. TCHAR szConnectionProfile[REGSTR_MAX_VALUE_LENGTH];
  1664. lstrcpy(szConnectionProfile, c_szRASProfiles);
  1665. lstrcat(szConnectionProfile, TEXT("\\"));
  1666. lstrcat(szConnectionProfile, pszConnectoid);
  1667. reg.CreateKey(HKEY_CURRENT_USER, szConnectionProfile);
  1668. reg.SetValue(c_szProxyEnable, (DWORD)0);
  1669. SetupConnectoidExit:
  1670. *pbSuccess = FALSE;
  1671. TCHAR szBuff256[257];
  1672. if (hr == ERROR_READING_ISP)
  1673. {
  1674. MsgBox(IDS_CANTREADMSNSUISP, MB_MYERROR);
  1675. } else if (hr == ERROR_READING_DUN) {
  1676. MsgBox(IDS_CANTREADMSDUNFILE, MB_MYERROR);
  1677. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1678. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWPHBK.DLL"));
  1679. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1680. } else if (hr == ERROR_PHBK_NOT_FOUND) {
  1681. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("ICWDL.DLL"));
  1682. MessageBox(szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  1683. } else if (hr == ERROR_USERBACK || hr == ERROR_USERCANCEL || hr == ERROR_SUCCESS) {
  1684. // Do nothing
  1685. *pbSuccess = TRUE;
  1686. } else if (hr == ERROR_NOT_ENOUGH_MEMORY) {
  1687. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  1688. } else if ((hr == ERROR_NO_MORE_ITEMS) || (hr == ERROR_INVALID_DATA)
  1689. || (hr == ERROR_FILE_NOT_FOUND)) {
  1690. MsgBox(IDS_CORRUPTPHONEBOOK, MB_MYERROR);
  1691. } else if (hr != ERROR_SUCCESS) {
  1692. wsprintf(szBuff256,TEXT("You can ignore this, just report it and include this number (%d).\n"),hr);
  1693. AssertMsg(0,szBuff256);
  1694. *pbSuccess = TRUE;
  1695. }
  1696. return hr;
  1697. }
  1698. // Form the Dialing URL. Must be called after setting up for dialing.
  1699. HRESULT CRefDial::FormURL()
  1700. {
  1701. USES_CONVERSION;
  1702. TCHAR szTemp[MAX_PATH];
  1703. TCHAR szPromo[MAX_PATH];
  1704. TCHAR szProd[MAX_PATH];
  1705. TCHAR szArea[MAX_PATH];
  1706. TCHAR szOEM[MAX_PATH];
  1707. DWORD dwCONNWIZVersion = 0; // Version of CONNWIZ.HTM
  1708. //
  1709. // ChrisK Olympus 3997 5/25/97
  1710. //
  1711. TCHAR szRelProd[MAX_PATH];
  1712. TCHAR szRelProdVer[MAX_PATH];
  1713. HRESULT hr = ERROR_SUCCESS;
  1714. OSVERSIONINFO osvi;
  1715. //
  1716. // Build URL complete with name value pairs
  1717. //
  1718. hr = GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_ISPINFO, INF_REFERAL_URL,&szTemp[0],256);
  1719. if ('\0' == szTemp[0])
  1720. {
  1721. MsgBox(IDS_MSNSU_WRONG,MB_MYERROR);
  1722. return hr;
  1723. }
  1724. Assert(szTemp[0]);
  1725. ANSI2URLValue(m_szOEM,szOEM,0);
  1726. ANSI2URLValue(m_lpGatherInfo->m_szAreaCode,szArea,0);
  1727. if (m_bstrProductCode)
  1728. ANSI2URLValue(OLE2A((BSTR)m_bstrProductCode),szProd,0);
  1729. else
  1730. ANSI2URLValue(DEFAULT_PRODUCTCODE,szProd,0);
  1731. if (m_bstrPromoCode)
  1732. ANSI2URLValue(OLE2A((BSTR)m_bstrPromoCode),szPromo,0);
  1733. else
  1734. ANSI2URLValue(DEFAULT_PROMOCODE,szProd,0);
  1735. //
  1736. // ChrisK Olympus 3997 5/25/97
  1737. //
  1738. ANSI2URLValue(m_lpGatherInfo->m_szRelProd, szRelProd, 0);
  1739. ANSI2URLValue(m_lpGatherInfo->m_szRelVer, szRelProdVer, 0);
  1740. ZeroMemory(&osvi,sizeof(OSVERSIONINFO));
  1741. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1742. if (!GetVersionEx(&osvi))
  1743. {
  1744. ZeroMemory(&osvi,sizeof(OSVERSIONINFO));
  1745. }
  1746. #if defined(DEBUG)
  1747. LoadTestingLocaleOverride(&m_lpGatherInfo->m_dwCountry,
  1748. &m_lpGatherInfo->m_lcidUser);
  1749. #endif //DEBUG
  1750. HINSTANCE hInstIcwconn = LoadLibrary(ICW_DOWNLOADABLE_COMPONENT_NAME);
  1751. if (hInstIcwconn)
  1752. {
  1753. lpfnGetIcwconnVer = (GETICWCONNVER)GetProcAddress(hInstIcwconn, ICW_DOWNLOADABLE_COMPONENT_GETVERFUNC);
  1754. // Get the version of ICWCONN.DLL
  1755. if (lpfnGetIcwconnVer)
  1756. dwCONNWIZVersion = lpfnGetIcwconnVer();
  1757. FreeLibrary(hInstIcwconn);
  1758. }
  1759. #if defined(DEBUG)
  1760. if (FRefURLOverride())
  1761. {
  1762. TweakRefURL(szTemp,
  1763. &m_lpGatherInfo->m_lcidUser,
  1764. &m_lpGatherInfo->m_dwOS,
  1765. &m_lpGatherInfo->m_dwMajorVersion,
  1766. &m_lpGatherInfo->m_dwMinorVersion,
  1767. &m_lpGatherInfo->m_wArchitecture,
  1768. szPromo,
  1769. szOEM,
  1770. szArea,
  1771. &m_lpGatherInfo->m_dwCountry,
  1772. &m_lpGatherInfo->m_szSUVersion[0],
  1773. szProd,
  1774. &osvi.dwBuildNumber, //For this we really want to LOWORD
  1775. szRelProd,
  1776. szRelProdVer,
  1777. &dwCONNWIZVersion,
  1778. m_szPID,
  1779. &m_lAllOffers);
  1780. }
  1781. #endif //DEBUG
  1782. // Autoconfig will set alloffers always.
  1783. if ( m_lAllOffers || (m_lpGatherInfo->m_dwFlag & ICW_CFGFLAG_AUTOCONFIG) )
  1784. {
  1785. m_lpGatherInfo->m_dwFlag |= ICW_CFGFLAG_ALLOFFERS;
  1786. }
  1787. wsprintf(m_szUrl,TEXT("%slcid=%lu&sysdeflcid=%lu&appslcid=%lu&icwos=%lu&osver=%lu.%2.2d%s&arch=%u&promo=%s&oem=%s&area=%s&country=%lu&icwver=%s&prod=%s&osbld=%d&icwrp=%s&icwrpv=%s&wizver=%lu&PID=%s&cfgflag=%lu"),
  1788. szTemp,
  1789. m_lpGatherInfo->m_lcidUser,
  1790. m_lpGatherInfo->m_lcidSys,
  1791. m_lpGatherInfo->m_lcidApps,
  1792. m_lpGatherInfo->m_dwOS,
  1793. m_lpGatherInfo->m_dwMajorVersion,
  1794. m_lpGatherInfo->m_dwMinorVersion,
  1795. ICW_OS_VER,
  1796. m_lpGatherInfo->m_wArchitecture,
  1797. szPromo,
  1798. szOEM,
  1799. szArea,
  1800. m_lpGatherInfo->m_dwCountry,
  1801. &m_lpGatherInfo->m_szSUVersion[0],
  1802. szProd,
  1803. LOWORD(osvi.dwBuildNumber),
  1804. szRelProd,
  1805. szRelProdVer,
  1806. dwCONNWIZVersion,
  1807. m_szPID,
  1808. m_lpGatherInfo->m_dwFlag);
  1809. // Update registry values
  1810. //
  1811. wsprintf(m_lpGatherInfo->m_szISPFile,TEXT("%s\\%s"),g_pszAppDir,OLE2A(m_bstrISPFile));
  1812. lstrcpyn(m_lpGatherInfo->m_szAppDir,g_pszAppDir,ARRAYSIZE(m_lpGatherInfo->m_szAppDir));
  1813. StoreInSignUpReg(
  1814. (LPBYTE)m_lpGatherInfo,
  1815. sizeof(GATHERINFO),
  1816. REG_BINARY,
  1817. GATHERINFOVALUENAME);
  1818. return hr;
  1819. }
  1820. static const TCHAR cszBrandingSection[] = TEXT("Branding");
  1821. static const TCHAR cszBrandingFlags[] = TEXT("Flags");
  1822. static const TCHAR cszSupportSection[] = TEXT("Support");
  1823. static const TCHAR cszSupportNumber[] = TEXT("SupportPhoneNumber");
  1824. static const TCHAR cszLoggingSection[] = TEXT("Logging");
  1825. static const TCHAR cszStartURL[] = TEXT("StartURL");
  1826. static const TCHAR cszEndURL[] = TEXT("EndURL");
  1827. void CRefDial::GetISPFileSettings(LPTSTR lpszFile)
  1828. {
  1829. TCHAR szTemp[INTERNET_MAX_URL_LENGTH];
  1830. GetINTFromISPFile(lpszFile,
  1831. (LPTSTR)cszBrandingSection,
  1832. (LPTSTR)cszBrandingFlags,
  1833. (int FAR *)&m_lBrandingFlags,
  1834. BRAND_DEFAULT);
  1835. // Read the Support Number
  1836. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1837. (LPTSTR)cszSupportSection,
  1838. (LPTSTR)cszSupportNumber,
  1839. szTemp,
  1840. ARRAYSIZE(szTemp)))
  1841. m_bstrSupportNumber = A2BSTR(szTemp);
  1842. else
  1843. m_bstrSupportNumber.Empty();
  1844. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1845. (LPTSTR)cszLoggingSection,
  1846. (LPTSTR)cszStartURL,
  1847. szTemp,
  1848. ARRAYSIZE(szTemp)))
  1849. m_bstrLoggingStartUrl = A2BSTR(szTemp);
  1850. else
  1851. m_bstrLoggingStartUrl.Empty();
  1852. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1853. (LPTSTR)cszLoggingSection,
  1854. (LPTSTR)cszEndURL,
  1855. szTemp,
  1856. ARRAYSIZE(szTemp)))
  1857. m_bstrLoggingEndUrl = A2BSTR(szTemp);
  1858. else
  1859. m_bstrLoggingEndUrl.Empty();
  1860. }
  1861. // This function will accept user selected values that are necessary to
  1862. // setup a connectiod for dialing
  1863. // Returns:
  1864. // TRUE OK to dial
  1865. // FALSE Some kind of problem
  1866. // QuitWizard - TRUE, then terminate
  1867. // UserPickNumber - TRUE, then display Pick a Number DLG
  1868. // QuitWizard and UserPickNumber both FALSE, then just
  1869. // display the page prior to Dialing UI.
  1870. STDMETHODIMP CRefDial::SetupForDialing
  1871. (
  1872. BSTR bstrISPFile,
  1873. DWORD dwCountry,
  1874. BSTR bstrAreaCode,
  1875. DWORD dwFlag,
  1876. BOOL *pbRetVal
  1877. )
  1878. {
  1879. USES_CONVERSION;
  1880. HRESULT hr = S_OK;
  1881. long lRC = 0;
  1882. LPLINECOUNTRYENTRY pLCETemp;
  1883. HINSTANCE hPHBKDll = NULL;
  1884. DWORD_PTR dwPhoneBook = 0;
  1885. DWORD idx;
  1886. BOOL bSuccess = FALSE;
  1887. BOOL bConnectiodCreated = FALSE;
  1888. // Create a Window. We need a window, which will be hidden, so that we can process RAS status
  1889. // messages
  1890. RECT rcPos;
  1891. Create(NULL, rcPos, NULL, 0, 0, 0 );
  1892. // Initialize failure codes
  1893. *pbRetVal = FALSE;
  1894. m_bQuitWizard = FALSE;
  1895. m_bUserPickNumber = FALSE;
  1896. // Stuff the Area Code, and Country Code into the GatherInfo struct
  1897. Assert(bstrAreaCode);
  1898. lstrcpy(m_lpGatherInfo->m_szAreaCode,OLE2A(bstrAreaCode));
  1899. m_lpGatherInfo->m_dwCountry = dwCountry;
  1900. m_lpGatherInfo->m_dwFlag = dwFlag;
  1901. // Make a copy of the ISP file we should use.
  1902. Assert(bstrISPFile);
  1903. m_bstrISPFile = bstrISPFile;
  1904. // Read the ISP file stuff
  1905. GetISPFileSettings(OLE2A(m_bstrISPFile));
  1906. // Read the Connection File information which will create
  1907. // a connectiod from the passed in ISP file
  1908. switch(ReadConnectionInformation())
  1909. {
  1910. case ERROR_SUCCESS:
  1911. {
  1912. // Fill in static info into the GatherInfo sturct
  1913. DWORD dwRet = FillGatherInfoStruct(m_lpGatherInfo);
  1914. switch( dwRet )
  1915. {
  1916. case ERROR_FILE_NOT_FOUND:
  1917. MsgBox(IDS_MSNSU_WRONG,MB_MYERROR);
  1918. m_bQuitWizard = TRUE;
  1919. hr = S_FALSE;
  1920. break;
  1921. case ERROR_SUCCESS:
  1922. //do nothing
  1923. break;
  1924. default:
  1925. AssertMsg(dwRet, TEXT("FillGatherInfoStruct did not successfully complete. DUNfile entry corrupt?"));
  1926. break;
  1927. }
  1928. break;
  1929. }
  1930. case ERROR_CANCELLED:
  1931. hr = S_FALSE;
  1932. m_bQuitWizard = TRUE;
  1933. goto SetupForDialingExit;
  1934. break;
  1935. case ERROR_RETRY:
  1936. m_bTryAgain = TRUE;
  1937. hr = S_FALSE;
  1938. break;
  1939. default:
  1940. MsgBox(IDS_MSNSU_WRONG,MB_MYERROR);
  1941. hr = S_FALSE;
  1942. break;
  1943. }
  1944. // If we failed for some reason above, we need to return
  1945. // the error to the caller, and Quit The Wizard.
  1946. if (S_OK != hr)
  1947. goto SetupForDialingExit;
  1948. // we need to pass a valid window handle to lineTranslateDialog
  1949. // API call -MKarki (4/17/97) Fix for Bug #428
  1950. //
  1951. if (m_lpGatherInfo != NULL)
  1952. {
  1953. m_lpGatherInfo->m_hwnd = GetActiveWindow();
  1954. }
  1955. //
  1956. // Fill in country
  1957. //
  1958. m_lpGatherInfo->m_pLineCountryList = (LPLINECOUNTRYLIST)GlobalAlloc(GPTR,sizeof(LINECOUNTRYLIST));
  1959. Assert(m_lpGatherInfo->m_pLineCountryList);
  1960. if (!(m_lpGatherInfo->m_pLineCountryList))
  1961. {
  1962. m_bQuitWizard = TRUE;
  1963. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  1964. goto SetupForDialingExit;
  1965. }
  1966. m_lpGatherInfo->m_pLineCountryList->dwTotalSize = sizeof(LINECOUNTRYLIST);
  1967. //
  1968. // figure out how much memory we will need
  1969. //
  1970. lRC = lineGetCountry(m_lpGatherInfo->m_dwCountry,0x10004,
  1971. m_lpGatherInfo->m_pLineCountryList);
  1972. if ( lRC && lRC != LINEERR_STRUCTURETOOSMALL)
  1973. AssertMsg(0,TEXT("lineGetCountry error"));
  1974. Assert(m_lpGatherInfo->m_pLineCountryList->dwNeededSize);
  1975. LPLINECOUNTRYLIST pLineCountryTemp;
  1976. pLineCountryTemp = (LPLINECOUNTRYLIST)GlobalAlloc(GPTR,
  1977. ((size_t)m_lpGatherInfo->m_pLineCountryList->dwNeededSize));
  1978. Assert (pLineCountryTemp);
  1979. if (!pLineCountryTemp)
  1980. {
  1981. m_bQuitWizard = TRUE;
  1982. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  1983. goto SetupForDialingExit;
  1984. }
  1985. //
  1986. // initialize structure
  1987. //
  1988. pLineCountryTemp->dwTotalSize = m_lpGatherInfo->m_pLineCountryList->dwNeededSize;
  1989. GlobalFree(m_lpGatherInfo->m_pLineCountryList);
  1990. m_lpGatherInfo->m_pLineCountryList = pLineCountryTemp;
  1991. pLineCountryTemp = NULL;
  1992. //
  1993. // fetch information from TAPI
  1994. //
  1995. lRC = lineGetCountry(m_lpGatherInfo->m_dwCountry,0x10004,
  1996. m_lpGatherInfo->m_pLineCountryList);
  1997. if (lRC)
  1998. {
  1999. Assert(0);
  2000. m_bQuitWizard = TRUE;
  2001. // BUGBUG Probably should have an error message here
  2002. goto SetupForDialingExit;
  2003. }
  2004. //
  2005. // On Windows 95, lineGetCountry has a bug -- if we try to retrieve the
  2006. // dialing properties of just one country (i.e, if the first parameter is
  2007. // not zero), it returns m_pLineCountryList->dwNumCountries = 0!!
  2008. // But the m_pLineCountryList still has valid data
  2009. //
  2010. if (VER_PLATFORM_WIN32_NT != g_dwPlatform)
  2011. {
  2012. if (0 == m_lpGatherInfo->m_pLineCountryList->dwNumCountries)
  2013. m_lpGatherInfo->m_pLineCountryList->dwNumCountries = 1;
  2014. }
  2015. pLCETemp = (LPLINECOUNTRYENTRY)((UINT_PTR)m_lpGatherInfo->m_pLineCountryList +
  2016. (UINT)m_lpGatherInfo->m_pLineCountryList->dwCountryListOffset);
  2017. //
  2018. // build look up array
  2019. //
  2020. m_lpGatherInfo->m_rgNameLookUp = (LPCNTRYNAMELOOKUPELEMENT)GlobalAlloc(GPTR,((size_t)(sizeof(CNTRYNAMELOOKUPELEMENT)
  2021. * m_lpGatherInfo->m_pLineCountryList->dwNumCountries)));
  2022. for (idx=0; idx < m_lpGatherInfo->m_pLineCountryList->dwNumCountries;
  2023. idx++)
  2024. {
  2025. m_lpGatherInfo->m_rgNameLookUp[idx].psCountryName = (LPTSTR)((DWORD_PTR)m_lpGatherInfo->m_pLineCountryList + (DWORD)pLCETemp[idx].dwCountryNameOffset);
  2026. m_lpGatherInfo->m_rgNameLookUp[idx].dwNameSize = pLCETemp[idx].dwCountryNameSize;
  2027. m_lpGatherInfo->m_rgNameLookUp[idx].pLCE = &pLCETemp[idx];
  2028. AssertMsg(m_lpGatherInfo->m_rgNameLookUp[idx].psCountryName[0],
  2029. TEXT("Blank country name in look up array"));
  2030. }
  2031. // Prepare to Setup for Dialing, which will use the phonebook
  2032. // to get a suggested number
  2033. hPHBKDll = LoadLibrary(PHONEBOOK_LIBRARY);
  2034. AssertMsg(hPHBKDll != NULL,TEXT("Phonebook DLL is missing"));
  2035. if (!hPHBKDll)
  2036. {
  2037. //
  2038. // TODO: BUGBUG Pop-up error message
  2039. //
  2040. m_bQuitWizard = TRUE;
  2041. goto SetupForDialingExit;
  2042. }
  2043. // Setup, and possible create a connectiod
  2044. hr = SetupForRASDialing(m_lpGatherInfo,
  2045. hPHBKDll,
  2046. &dwPhoneBook,
  2047. &m_pSuggestInfo,
  2048. &m_szConnectoid[0],
  2049. &bConnectiodCreated);
  2050. if (ERROR_SUCCESS != hr)
  2051. {
  2052. m_bQuitWizard = TRUE;
  2053. goto SetupForDialingExit;
  2054. }
  2055. // If we have a RASENTRY struct from SetupForRASDialing, then just use it
  2056. // otherwise use the suggest info
  2057. if (!bConnectiodCreated)
  2058. {
  2059. // If there is only 1 suggested number, then we setup the
  2060. // connectiod, and we are ready to dial
  2061. if (1 == m_pSuggestInfo->wNumber)
  2062. {
  2063. SetupConnectoid(m_pSuggestInfo, 0, &m_szConnectoid[0],
  2064. sizeof(m_szConnectoid), &bSuccess);
  2065. if( !bSuccess )
  2066. {
  2067. m_bQuitWizard = TRUE;
  2068. goto SetupForDialingExit;
  2069. }
  2070. }
  2071. else
  2072. {
  2073. // More than 1 entry in the Phonebook, so we need to
  2074. // ask the user which one they want to use
  2075. if (m_pSuggestInfo->wNumber > 1)
  2076. {
  2077. // we are going to have to save these values for later
  2078. if (m_rgpSuggestedAE)
  2079. {
  2080. // We allocated an extra pointer so we'd have NULL on the
  2081. // end of the list and this for loop will work
  2082. for (int i=0; m_rgpSuggestedAE[i]; i++)
  2083. GlobalFree(m_rgpSuggestedAE[i]);
  2084. GlobalFree(m_rgpSuggestedAE);
  2085. m_rgpSuggestedAE = NULL;
  2086. }
  2087. // We first need to allocate space for the pointers.
  2088. // We'll allocate an extra one so that we will have
  2089. // a NULL pointer at the end of the list for when
  2090. // we free g_rgpSuggestedAE. We don't need to set
  2091. // the pointers to NULL because GPTR includes a flag
  2092. // to tell GlobalAlloc to initialize the memory to zero.
  2093. m_rgpSuggestedAE = (PACCESSENTRY*)GlobalAlloc(GPTR,
  2094. sizeof(PACCESSENTRY)*(m_pSuggestInfo->wNumber + 1));
  2095. if (NULL == m_rgpSuggestedAE)
  2096. hr = E_ABORT;
  2097. else if (m_pSuggestInfo->rgpAccessEntry)
  2098. {
  2099. for (UINT i=0; i < m_pSuggestInfo->wNumber; i++)
  2100. {
  2101. m_rgpSuggestedAE[i] = (PACCESSENTRY)GlobalAlloc(GPTR, sizeof(ACCESSENTRY));
  2102. if (NULL == m_rgpSuggestedAE[i])
  2103. {
  2104. hr = E_ABORT;
  2105. break; // for loop
  2106. }
  2107. memmove(m_rgpSuggestedAE[i], m_pSuggestInfo->rgpAccessEntry[i],
  2108. sizeof(ACCESSENTRY));
  2109. }
  2110. m_pSuggestInfo->rgpAccessEntry = m_rgpSuggestedAE;
  2111. }
  2112. if (E_ABORT == hr)
  2113. {
  2114. MsgBox(IDS_OUTOFMEMORY,MB_MYERROR);
  2115. m_bQuitWizard = TRUE;
  2116. goto SetupForDialingExit;
  2117. }
  2118. m_bUserPickNumber = TRUE;
  2119. goto SetupForDialingExit;
  2120. }
  2121. else
  2122. {
  2123. // Call RAS to have the user pick a number to dial
  2124. hr = UserPickANumber( GetActiveWindow(), m_lpGatherInfo,
  2125. m_pSuggestInfo,
  2126. hPHBKDll,
  2127. dwPhoneBook,
  2128. &m_szConnectoid[0],
  2129. sizeof(m_szConnectoid),
  2130. 0);
  2131. if (ERROR_USERBACK == hr)
  2132. {
  2133. goto SetupForDialingExit;
  2134. }
  2135. else if (ERROR_USERCANCEL == hr)
  2136. {
  2137. m_bQuitWizard = TRUE;
  2138. goto SetupForDialingExit;
  2139. }
  2140. else if (ERROR_SUCCESS != hr)
  2141. {
  2142. // Go back to prev page.
  2143. goto SetupForDialingExit;
  2144. }
  2145. // Error SUCCESS will fall through and set pbRetVal to TRUE below
  2146. }
  2147. }
  2148. }
  2149. // Success if we get to here
  2150. *pbRetVal = TRUE;
  2151. // Generate a Displayable number
  2152. m_hrDisplayableNumber = GetDisplayableNumber();
  2153. SetupForDialingExit:
  2154. if (hPHBKDll)
  2155. {
  2156. if (dwPhoneBook)
  2157. {
  2158. FARPROC fp = GetProcAddress(hPHBKDll,PHBK_UNLOADAPI);
  2159. ASSERT(fp);
  2160. ((PFNPHONEBOOKUNLOAD)fp)(dwPhoneBook);
  2161. dwPhoneBook = 0;
  2162. }
  2163. FreeLibrary(hPHBKDll);
  2164. hPHBKDll = NULL;
  2165. }
  2166. return S_OK;
  2167. }
  2168. STDMETHODIMP CRefDial::RemoveConnectoid(BOOL * pVal)
  2169. {
  2170. if (m_hrasconn)
  2171. DoHangup();
  2172. if (m_pSuggestInfo)
  2173. {
  2174. GlobalFree(m_pSuggestInfo->rgpAccessEntry);
  2175. GlobalFree(m_pSuggestInfo);
  2176. m_pSuggestInfo = NULL;
  2177. }
  2178. if( (m_pcRNA!=NULL) && (m_szConnectoid[0]!='\0') )
  2179. {
  2180. m_pcRNA->RasDeleteEntry(NULL,m_szConnectoid);
  2181. delete m_pcRNA;
  2182. m_pcRNA = NULL;
  2183. }
  2184. return S_OK;
  2185. }
  2186. STDMETHODIMP CRefDial::get_QuitWizard(BOOL * pVal)
  2187. {
  2188. if (pVal == NULL)
  2189. return E_POINTER;
  2190. *pVal = m_bQuitWizard;
  2191. return S_OK;
  2192. }
  2193. STDMETHODIMP CRefDial::get_UserPickNumber(BOOL * pVal)
  2194. {
  2195. if (pVal == NULL)
  2196. return E_POINTER;
  2197. *pVal = m_bUserPickNumber;
  2198. return S_OK;
  2199. }
  2200. STDMETHODIMP CRefDial::get_DialPhoneNumber(BSTR * pVal)
  2201. {
  2202. USES_CONVERSION;
  2203. if (pVal == NULL)
  2204. return E_POINTER;
  2205. if (m_hrDisplayableNumber == ERROR_SUCCESS)
  2206. *pVal = A2BSTR(m_pszDisplayable);
  2207. else
  2208. *pVal = A2BSTR(m_szPhoneNumber);
  2209. return S_OK;
  2210. }
  2211. STDMETHODIMP CRefDial::put_DialPhoneNumber(BSTR newVal)
  2212. {
  2213. USES_CONVERSION;
  2214. LPRASENTRY lpRasEntry = NULL;
  2215. LPRASDEVINFO lpRasDevInfo = NULL;
  2216. DWORD dwRasEntrySize = 0;
  2217. DWORD dwRasDevInfoSize = 0;
  2218. RNAAPI *pcRNA = NULL;
  2219. HRESULT hr;
  2220. // Get the current RAS entry properties
  2221. hr = MyRasGetEntryProperties(NULL,
  2222. m_szConnectoid,
  2223. &lpRasEntry,
  2224. &dwRasEntrySize,
  2225. &lpRasDevInfo,
  2226. &dwRasDevInfoSize);
  2227. if (NULL ==lpRasDevInfo)
  2228. {
  2229. dwRasDevInfoSize = 0;
  2230. }
  2231. if (hr == ERROR_SUCCESS && NULL != lpRasEntry)
  2232. {
  2233. // Replace the phone number with the new one
  2234. //
  2235. lstrcpy(lpRasEntry->szLocalPhoneNumber, OLE2A(newVal));
  2236. // non-zero dummy values are required due to bugs in win95
  2237. lpRasEntry->dwCountryID = 1;
  2238. lpRasEntry->dwCountryCode = 1;
  2239. lpRasEntry->szAreaCode[1] = '\0';
  2240. lpRasEntry->szAreaCode[0] = '8';
  2241. // Set to dial as is
  2242. //
  2243. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  2244. pcRNA = new RNAAPI;
  2245. if (pcRNA)
  2246. {
  2247. #if defined(DEBUG)
  2248. TCHAR szMsg[256];
  2249. OutputDebugString(TEXT("CRefDial::put_DialPhoneNumber - MyRasGetEntryProperties()"));
  2250. wsprintf(szMsg, TEXT("lpRasEntry->dwfOptions: %ld"), lpRasEntry->dwfOptions);
  2251. OutputDebugString(szMsg);
  2252. wsprintf(szMsg, TEXT("lpRasEntry->dwCountryID: %ld"), lpRasEntry->dwCountryID);
  2253. OutputDebugString(szMsg);
  2254. wsprintf(szMsg, TEXT("lpRasEntry->dwCountryCode: %ld"), lpRasEntry->dwCountryCode);
  2255. OutputDebugString(szMsg);
  2256. wsprintf(szMsg, TEXT("lpRasEntry->szAreaCode: %s"), lpRasEntry->szAreaCode);
  2257. OutputDebugString(szMsg);
  2258. wsprintf(szMsg, TEXT("lpRasEntry->szLocalPhoneNumber: %s"), lpRasEntry->szLocalPhoneNumber);
  2259. OutputDebugString(szMsg);
  2260. wsprintf(szMsg, TEXT("lpRasEntry->dwAlternateOffset: %ld"), lpRasEntry->dwAlternateOffset);
  2261. OutputDebugString(szMsg);
  2262. #endif //DEBUG
  2263. pcRNA->RasSetEntryProperties(NULL,
  2264. m_szConnectoid,
  2265. (LPBYTE)lpRasEntry,
  2266. dwRasEntrySize,
  2267. (LPBYTE)lpRasDevInfo,
  2268. dwRasDevInfoSize);
  2269. delete pcRNA;
  2270. }
  2271. }
  2272. // Regenerate the displayable number
  2273. GetDisplayableNumber();
  2274. return S_OK;
  2275. }
  2276. STDMETHODIMP CRefDial::get_URL(BSTR * pVal)
  2277. {
  2278. USES_CONVERSION;
  2279. TCHAR szTemp[256];
  2280. if (pVal == NULL)
  2281. return E_POINTER;
  2282. // Get the URL from the ISP file, and then convert it
  2283. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_ISPINFO, INF_REFERAL_URL,&szTemp[0],256)))
  2284. {
  2285. *pVal = A2BSTR(szTemp);
  2286. }
  2287. else
  2288. {
  2289. *pVal = NULL;
  2290. }
  2291. return S_OK;
  2292. }
  2293. STDMETHODIMP CRefDial::get_PromoCode(BSTR * pVal)
  2294. {
  2295. if (pVal == NULL)
  2296. return E_POINTER;
  2297. *pVal = m_bstrPromoCode.Copy();
  2298. return S_OK;
  2299. }
  2300. STDMETHODIMP CRefDial::put_PromoCode(BSTR newVal)
  2301. {
  2302. if (newVal && wcslen(newVal))
  2303. m_bstrPromoCode = newVal;
  2304. return S_OK;
  2305. }
  2306. STDMETHODIMP CRefDial::get_ProductCode(BSTR * pVal)
  2307. {
  2308. if (pVal == NULL)
  2309. return E_POINTER;
  2310. *pVal = m_bstrProductCode;
  2311. return S_OK;
  2312. }
  2313. STDMETHODIMP CRefDial::put_ProductCode(BSTR newVal)
  2314. {
  2315. if (newVal && wcslen(newVal))
  2316. m_bstrProductCode = newVal;
  2317. return S_OK;
  2318. }
  2319. STDMETHODIMP CRefDial::put_OemCode(BSTR newVal)
  2320. {
  2321. USES_CONVERSION;
  2322. if (newVal && wcslen(newVal))
  2323. lstrcpy(m_szOEM, OLE2A(newVal));
  2324. return S_OK;
  2325. }
  2326. STDMETHODIMP CRefDial::put_AllOfferCode(long newVal)
  2327. {
  2328. m_lAllOffers = newVal;
  2329. return S_OK;
  2330. }
  2331. //+---------------------------------------------------------------------------
  2332. //
  2333. // Function: DoOfferDownload
  2334. //
  2335. // Synopsis: Download the ISP offer from the ISP server
  2336. //
  2337. //+---------------------------------------------------------------------------
  2338. STDMETHODIMP CRefDial::DoOfferDownload(BOOL *pbRetVal)
  2339. {
  2340. HRESULT hr;
  2341. RNAAPI *pcRNA;
  2342. //
  2343. // Hide RNA window on Win95 retail
  2344. //
  2345. // MinimizeRNAWindow(m_pszConnectoid,g_hInst);
  2346. // 4/2/97 ChrisK Olympus 296
  2347. // g_hRNAZapperThread = LaunchRNAReestablishZapper(g_hInst);
  2348. //
  2349. // The connection is open and ready. Start the download.
  2350. //
  2351. m_dwThreadID = 0;
  2352. m_hThread = CreateThread(NULL,
  2353. 0,
  2354. (LPTHREAD_START_ROUTINE)DownloadThreadInit,
  2355. (LPVOID)this,
  2356. 0,
  2357. &m_dwThreadID);
  2358. // 5-1-97 ChrisK Olympus 2934
  2359. // m_objBusyMessages.Start(m_hWnd,IDC_LBLSTATUS,m_hrasconn);
  2360. // If we dont get the donwload thread, then kill the open
  2361. // connection
  2362. if (!m_hThread)
  2363. {
  2364. hr = GetLastError();
  2365. if (m_hrasconn)
  2366. {
  2367. pcRNA = new RNAAPI;
  2368. if (pcRNA)
  2369. {
  2370. pcRNA->RasHangUp(m_hrasconn);
  2371. m_hrasconn = NULL;
  2372. delete pcRNA;
  2373. pcRNA = NULL;
  2374. }
  2375. }
  2376. *pbRetVal = FALSE;
  2377. }
  2378. else
  2379. {
  2380. // Download has started.
  2381. m_bDownloadHasBeenCanceled = FALSE;
  2382. *pbRetVal = TRUE;
  2383. }
  2384. return S_OK;
  2385. }
  2386. STDMETHODIMP CRefDial::get_DialStatusString(BSTR * pVal)
  2387. {
  2388. USES_CONVERSION;
  2389. if (pVal == NULL)
  2390. return E_POINTER;
  2391. if (m_RasStatusID)
  2392. {
  2393. if (m_bRedial)
  2394. {
  2395. switch (m_RasStatusID)
  2396. {
  2397. case IDS_RAS_DIALING:
  2398. case IDS_RAS_PORTOPENED:
  2399. case IDS_RAS_OPENPORT:
  2400. {
  2401. *pVal = A2BSTR(GetSz(IDS_RAS_REDIALING));
  2402. return S_OK;
  2403. }
  2404. default:
  2405. break;
  2406. }
  2407. }
  2408. *pVal = A2BSTR(GetSz((USHORT)m_RasStatusID));
  2409. }
  2410. else
  2411. *pVal = A2BSTR(TEXT(""));
  2412. return S_OK;
  2413. }
  2414. //+---------------------------------------------------------------------------
  2415. //
  2416. // Function: DoInit
  2417. //
  2418. // Synopsis: Initialize cancel status and the displayable number for this
  2419. // round of dialing.
  2420. //
  2421. //+---------------------------------------------------------------------------
  2422. STDMETHODIMP CRefDial::DoInit()
  2423. {
  2424. m_bWaitingToHangup = FALSE;
  2425. // Update the phone number to display if user has changed dialing properties
  2426. // This function should be called re-init the dialing properties.
  2427. // SetupforDialing should be called prior to this.
  2428. GetDisplayableNumber();
  2429. return S_OK;
  2430. }
  2431. //+---------------------------------------------------------------------------
  2432. //
  2433. // Function: DoHangup
  2434. //
  2435. // Synopsis: Hangup the modem for the currently active RAS session
  2436. //
  2437. //+---------------------------------------------------------------------------
  2438. STDMETHODIMP CRefDial::DoHangup()
  2439. {
  2440. RNAAPI *pcRNA;
  2441. // Set the disconnect flag as the system may be too busy with dialing.
  2442. // Once we get a chance to terminate dialing, we know we have to hangup
  2443. m_bWaitingToHangup = TRUE;
  2444. if (NULL != m_hrasconn)
  2445. {
  2446. pcRNA = new RNAAPI;
  2447. if (pcRNA)
  2448. {
  2449. pcRNA->RasHangUp(m_hrasconn);
  2450. m_hrasconn = NULL;
  2451. delete pcRNA;
  2452. pcRNA = NULL;
  2453. }
  2454. }
  2455. return (m_hrasconn == NULL) ? S_OK : E_POINTER;
  2456. }
  2457. STDMETHODIMP CRefDial::ProcessSignedPID(BOOL * pbRetVal)
  2458. {
  2459. USES_CONVERSION;
  2460. HANDLE hfile;
  2461. DWORD dwFileSize;
  2462. DWORD dwBytesRead;
  2463. LPBYTE lpbSignedPID;
  2464. LPTSTR lpszSignedPID;
  2465. *pbRetVal = FALSE;
  2466. // Open the PID file for Binary Reading. It will be in the CWD
  2467. if (INVALID_HANDLE_VALUE != (hfile = CreateFile(c_szSignedPIDFName,
  2468. GENERIC_READ,
  2469. 0,
  2470. NULL,
  2471. OPEN_EXISTING,
  2472. FILE_ATTRIBUTE_NORMAL,
  2473. NULL)))
  2474. {
  2475. dwFileSize = GetFileSize(hfile, NULL);
  2476. // Allocate a buffer to read the file, and one to store the BINHEX version
  2477. lpbSignedPID = new BYTE[dwFileSize];
  2478. lpszSignedPID = new TCHAR[(dwFileSize * 2) + 1];
  2479. if (lpbSignedPID && lpszSignedPID)
  2480. {
  2481. if (ReadFile(hfile, (LPVOID) lpbSignedPID, dwFileSize, &dwBytesRead, NULL) &&
  2482. (dwFileSize == dwBytesRead))
  2483. {
  2484. // BINHEX the signed PID data so we can send it to the signup server
  2485. DWORD dwX = 0;
  2486. BYTE by;
  2487. for (DWORD dwY = 0; dwY < dwFileSize; dwY++)
  2488. {
  2489. by = lpbSignedPID[dwY];
  2490. lpszSignedPID[dwX++] = g_BINTOHEXLookup[((by & 0xF0) >> 4)];
  2491. lpszSignedPID[dwX++] = g_BINTOHEXLookup[(by & 0x0F)];
  2492. }
  2493. lpszSignedPID[dwX] = '\0';
  2494. // Convert the signed pid to a BSTR
  2495. m_bstrSignedPID = A2BSTR(lpszSignedPID);
  2496. // Set the return value
  2497. *pbRetVal = TRUE;
  2498. }
  2499. }
  2500. // Free the buffers we allocated
  2501. if (lpbSignedPID)
  2502. {
  2503. delete[] lpbSignedPID;
  2504. }
  2505. if (lpszSignedPID)
  2506. {
  2507. delete[] lpszSignedPID;
  2508. }
  2509. // Close the File
  2510. CloseHandle(hfile);
  2511. #ifndef DEBUG
  2512. // Delete the File
  2513. // defer removal of this file until the container app exits.
  2514. // see BUG 373.
  2515. //DeleteFile(c_szSignedPIDFName);
  2516. #endif
  2517. }
  2518. return S_OK;
  2519. }
  2520. STDMETHODIMP CRefDial::get_SignedPID(BSTR * pVal)
  2521. {
  2522. if (pVal == NULL)
  2523. return E_POINTER;
  2524. *pVal = m_bstrSignedPID.Copy();
  2525. return S_OK;
  2526. }
  2527. STDMETHODIMP CRefDial::FormReferralServerURL(BOOL * pbRetVal)
  2528. {
  2529. // Form the URL to be used to access the referal server
  2530. if (ERROR_SUCCESS != FormURL())
  2531. *pbRetVal = FALSE;
  2532. else
  2533. *pbRetVal = TRUE;
  2534. return S_OK;
  2535. }
  2536. STDMETHODIMP CRefDial::get_SignupURL(BSTR * pVal)
  2537. {
  2538. USES_CONVERSION;
  2539. TCHAR szTemp[256];
  2540. if (pVal == NULL)
  2541. return E_POINTER;
  2542. // Get the URL from the ISP file, and then convert it
  2543. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_URL, INF_SIGNUP_URL,&szTemp[0],256)))
  2544. {
  2545. *pVal = A2BSTR(szTemp);
  2546. }
  2547. else
  2548. {
  2549. *pVal = NULL;
  2550. }
  2551. return S_OK;
  2552. }
  2553. STDMETHODIMP CRefDial::get_AutoConfigURL(BSTR * pVal)
  2554. {
  2555. USES_CONVERSION;
  2556. TCHAR szTemp[256];
  2557. if (pVal == NULL)
  2558. return E_POINTER;
  2559. // Get the URL from the ISP file, and then convert it
  2560. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_URL, INF_AUTOCONFIG_URL,&szTemp[0],256)))
  2561. {
  2562. *pVal = A2BSTR(szTemp);
  2563. }
  2564. else
  2565. {
  2566. *pVal = NULL;
  2567. }
  2568. return S_OK;
  2569. }
  2570. STDMETHODIMP CRefDial::get_ISDNURL(BSTR * pVal)
  2571. {
  2572. USES_CONVERSION;
  2573. TCHAR szTemp[256];
  2574. if (pVal == NULL)
  2575. return E_POINTER;
  2576. // Get the ISDN URL from the ISP file, and then convert it
  2577. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_URL, INF_ISDN_URL,&szTemp[0],256)))
  2578. {
  2579. *pVal = A2BSTR(szTemp);
  2580. }
  2581. else
  2582. {
  2583. *pVal = NULL;
  2584. }
  2585. if (0 == szTemp[0] || NULL == *pVal)
  2586. {
  2587. // Get the sign up URL from the ISP file, and then convert it
  2588. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_URL, INF_SIGNUP_URL,&szTemp[0],256)))
  2589. {
  2590. *pVal = A2BSTR(szTemp);
  2591. }
  2592. else
  2593. {
  2594. *pVal = NULL;
  2595. }
  2596. }
  2597. return S_OK;
  2598. }
  2599. STDMETHODIMP CRefDial::get_ISDNAutoConfigURL(BSTR * pVal)
  2600. {
  2601. USES_CONVERSION;
  2602. TCHAR szTemp[256];
  2603. if (pVal == NULL)
  2604. return E_POINTER;
  2605. // Get the URL from the ISP file, and then convert it
  2606. if (SUCCEEDED(GetDataFromISPFile(OLE2A(m_bstrISPFile),INF_SECTION_URL, INF_ISDN_AUTOCONFIG_URL,&szTemp[0],256)))
  2607. {
  2608. *pVal = A2BSTR(szTemp);
  2609. }
  2610. else
  2611. {
  2612. *pVal = NULL;
  2613. }
  2614. return S_OK;
  2615. }
  2616. STDMETHODIMP CRefDial::get_TryAgain(BOOL * pVal)
  2617. {
  2618. if (pVal == NULL)
  2619. return E_POINTER;
  2620. *pVal = m_bTryAgain;
  2621. return S_OK;
  2622. }
  2623. STDMETHODIMP CRefDial::get_DialError(HRESULT * pVal)
  2624. {
  2625. *pVal = m_hrDialErr;
  2626. return S_OK;
  2627. }
  2628. STDMETHODIMP CRefDial::put_ModemOverride(BOOL newbVal)
  2629. {
  2630. m_bModemOverride = newbVal;
  2631. return S_OK;
  2632. }
  2633. STDMETHODIMP CRefDial::put_Redial(BOOL newbVal)
  2634. {
  2635. m_bRedial = newbVal;
  2636. return S_OK;
  2637. }
  2638. STDMETHODIMP CRefDial::get_DialErrorMsg(BSTR * pVal)
  2639. {
  2640. USES_CONVERSION;
  2641. if (pVal == NULL)
  2642. return E_POINTER;
  2643. if (m_hrDialErr != ERROR_SUCCESS)
  2644. {
  2645. DWORD dwIDS = RasErrorToIDS(m_hrDialErr);
  2646. if (dwIDS != -1 && dwIDS !=0)
  2647. {
  2648. *pVal = A2BSTR(GetSz((WORD)dwIDS));
  2649. }
  2650. else
  2651. {
  2652. *pVal = A2BSTR(GetSz(IDS_PPPRANDOMFAILURE));
  2653. }
  2654. }
  2655. else
  2656. {
  2657. *pVal = A2BSTR(GetSz(IDS_PPPRANDOMFAILURE));
  2658. }
  2659. return S_OK;
  2660. }
  2661. STDMETHODIMP CRefDial::ModemEnum_Reset()
  2662. {
  2663. m_emModemEnum.ResetIndex();
  2664. return S_OK;
  2665. }
  2666. STDMETHODIMP CRefDial::ModemEnum_Next(BSTR *pDeviceName)
  2667. {
  2668. if (pDeviceName == NULL)
  2669. return E_POINTER;
  2670. *pDeviceName = A2BSTR(m_emModemEnum.Next());
  2671. return S_OK;
  2672. }
  2673. STDMETHODIMP CRefDial::get_ModemEnum_NumDevices(long * pVal)
  2674. {
  2675. if (pVal == NULL)
  2676. return E_POINTER;
  2677. m_emModemEnum.ReInit();
  2678. *pVal = m_emModemEnum.GetNumDevices();
  2679. if(m_ISPImport.m_szDeviceName[0]!='\0')
  2680. {
  2681. //
  2682. // Find out what the current device index is
  2683. //
  2684. for(int l=0; l<(*pVal); l++)
  2685. {
  2686. if(lstrcmp(m_ISPImport.m_szDeviceName,m_emModemEnum.GetDeviceName(l))==0)
  2687. {
  2688. m_lCurrentModem = l;
  2689. break;
  2690. }
  2691. }
  2692. if(l == (*pVal))
  2693. m_lCurrentModem = -1;
  2694. }
  2695. else
  2696. m_lCurrentModem = -1;
  2697. return S_OK;
  2698. }
  2699. STDMETHODIMP CRefDial::get_SupportNumber(BSTR * pVal)
  2700. {
  2701. USES_CONVERSION;
  2702. TCHAR szSupportNumber[MAX_PATH];
  2703. if (pVal == NULL)
  2704. return E_POINTER;
  2705. if (m_SupportInfo.GetSupportInfo(szSupportNumber, m_dwCountryCode))
  2706. *pVal = A2BSTR(szSupportNumber);
  2707. else
  2708. *pVal = NULL;
  2709. return S_OK;
  2710. }
  2711. STDMETHODIMP CRefDial::get_ISPSupportNumber(BSTR * pVal)
  2712. {
  2713. USES_CONVERSION;
  2714. if (pVal == NULL)
  2715. return E_POINTER;
  2716. if (*m_szISPSupportNumber)
  2717. *pVal = A2BSTR(m_szISPSupportNumber);
  2718. else
  2719. *pVal = NULL;
  2720. return S_OK;
  2721. }
  2722. STDMETHODIMP CRefDial::ShowDialingProperties(BOOL * pbRetVal)
  2723. {
  2724. HRESULT hr;
  2725. DWORD dwNumDev = 0;
  2726. *pbRetVal = FALSE;
  2727. hr = lineInitialize(&m_hLineApp,_Module.GetModuleInstance(),LineCallback,(LPSTR)NULL,&dwNumDev);
  2728. if (hr == ERROR_SUCCESS)
  2729. {
  2730. LPLINEEXTENSIONID lpExtensionID;
  2731. if (m_dwTapiDev == 0xFFFFFFFF)
  2732. {
  2733. m_dwTapiDev = 0;
  2734. }
  2735. lpExtensionID = (LPLINEEXTENSIONID)GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  2736. if (lpExtensionID)
  2737. {
  2738. //
  2739. // Negotiate version - without this call
  2740. // lineTranslateDialog would fail
  2741. //
  2742. do {
  2743. hr = lineNegotiateAPIVersion(m_hLineApp,
  2744. m_dwTapiDev,
  2745. 0x00010004, 0x00010004,
  2746. &m_dwAPIVersion,
  2747. lpExtensionID);
  2748. } while ((hr != ERROR_SUCCESS) && (m_dwTapiDev++ < dwNumDev - 1));
  2749. if (m_dwTapiDev >= dwNumDev)
  2750. {
  2751. m_dwTapiDev = 0;
  2752. }
  2753. //
  2754. // ditch it since we don't use it
  2755. //
  2756. GlobalFree(lpExtensionID);
  2757. lpExtensionID = NULL;
  2758. if (hr == ERROR_SUCCESS)
  2759. {
  2760. hr = lineTranslateDialog(m_hLineApp,
  2761. m_dwTapiDev,
  2762. m_dwAPIVersion,
  2763. GetActiveWindow(),
  2764. m_szPhoneNumber);
  2765. lineShutdown(m_hLineApp);
  2766. m_hLineApp = NULL;
  2767. }
  2768. }
  2769. }
  2770. if (hr == ERROR_SUCCESS)
  2771. {
  2772. GetDisplayableNumber();
  2773. *pbRetVal = TRUE;
  2774. }
  2775. return S_OK;
  2776. }
  2777. STDMETHODIMP CRefDial::ShowPhoneBook(DWORD dwCountryCode, long newVal, BOOL * pbRetVal)
  2778. {
  2779. USES_CONVERSION;
  2780. DWORD_PTR dwPhoneBook;
  2781. HINSTANCE hPHBKDll;
  2782. FARPROC fp;
  2783. BOOL bBookLoaded = FALSE;
  2784. *pbRetVal = FALSE; // Assume Failure
  2785. hPHBKDll = LoadLibrary(PHONEBOOK_LIBRARY);
  2786. if (hPHBKDll)
  2787. {
  2788. if (NULL != (fp = GetProcAddress(hPHBKDll,PHBK_LOADAPI)))
  2789. {
  2790. if (ERROR_SUCCESS == ((PFNPHONEBOOKLOAD)fp)(OLE2A(m_bstrISPFile),&dwPhoneBook))
  2791. {
  2792. bBookLoaded = TRUE;
  2793. m_pSuggestInfo->dwCountryID = dwCountryCode;
  2794. // Update the device type so we can distinguish ISDN numbers
  2795. TCHAR *pszNewType = m_emModemEnum.GetDeviceType(newVal);
  2796. m_ISPImport.m_bIsISDNDevice = (lstrcmpi(pszNewType, RASDT_Isdn) == 0);
  2797. m_lpGatherInfo->m_fType = TYPE_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  2798. m_lpGatherInfo->m_bMask = MASK_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  2799. if (ERROR_SUCCESS == UserPickANumber(GetActiveWindow(),
  2800. m_lpGatherInfo,
  2801. m_pSuggestInfo,
  2802. hPHBKDll,
  2803. dwPhoneBook,
  2804. &m_szConnectoid[0],
  2805. sizeof(m_szConnectoid),
  2806. DIALERR_IN_PROGRESS))
  2807. {
  2808. // Regenerate the displayable number
  2809. GetDisplayableNumber();
  2810. // Base the Country code on the ras entry, since it was
  2811. // directly modified in this case
  2812. LPRASENTRY lpRasEntry = NULL;
  2813. LPRASDEVINFO lpRasDevInfo = NULL;
  2814. DWORD dwRasEntrySize = 0;
  2815. DWORD dwRasDevInfoSize = 0;
  2816. if (SUCCEEDED(MyRasGetEntryProperties(NULL,
  2817. m_szConnectoid,
  2818. &lpRasEntry,
  2819. &dwRasEntrySize,
  2820. &lpRasDevInfo,
  2821. &dwRasDevInfoSize)))
  2822. {
  2823. m_dwCountryCode = lpRasEntry->dwCountryCode;
  2824. }
  2825. // Set the return code
  2826. *pbRetVal = TRUE;
  2827. }
  2828. }
  2829. }
  2830. FreeLibrary(hPHBKDll);
  2831. }
  2832. if (! bBookLoaded)
  2833. {
  2834. // Give the user a message
  2835. MsgBox(IDS_CANTINITPHONEBOOK,MB_MYERROR);
  2836. }
  2837. return S_OK;
  2838. }
  2839. BOOL CRefDial::IsSBCSString( TCHAR *sz )
  2840. {
  2841. Assert(sz);
  2842. #ifdef UNICODE
  2843. // Check if the string contains only ASCII chars.
  2844. int attrib = IS_TEXT_UNICODE_ASCII16 | IS_TEXT_UNICODE_CONTROLS;
  2845. return (BOOL)IsTextUnicode(sz, lstrlen(sz), &attrib);
  2846. #else
  2847. while( NULL != *sz )
  2848. {
  2849. if (IsDBCSLeadByte(*sz)) return FALSE;
  2850. sz++;
  2851. }
  2852. return TRUE;
  2853. #endif
  2854. }
  2855. TCHAR szValidPhoneCharacters[] = {TEXT("0123456789AaBbCcDdPpTtWw!@$ -.()+*#,&\0")};
  2856. STDMETHODIMP CRefDial::ValidatePhoneNumber(BSTR bstrPhoneNumber, BOOL * pbRetVal)
  2857. {
  2858. USES_CONVERSION;
  2859. // Bail if an empty string is passed
  2860. if (!bstrPhoneNumber || !wcslen(bstrPhoneNumber))
  2861. {
  2862. MsgBox(IDS_INVALIDPHONE,MB_MYERROR);
  2863. *pbRetVal = FALSE;
  2864. return(S_OK);
  2865. }
  2866. // Check that the phone number only contains valid characters
  2867. LPTSTR lpNum, lpValid;
  2868. LPTSTR lpszDialNumber = OLE2A(bstrPhoneNumber);
  2869. // vyung 03/06/99 Remove Easter egg as requested by NT5
  2870. #ifdef ICW_EASTEREGG
  2871. if (lstrcmp(lpszDialNumber, c_szCreditsMagicNum) == 0)
  2872. {
  2873. ShowCredits();
  2874. *pbRetVal = FALSE;
  2875. return(S_OK);
  2876. }
  2877. #endif
  2878. *pbRetVal = TRUE;
  2879. if (!IsSBCSString(lpszDialNumber))
  2880. {
  2881. MsgBox(IDS_SBCSONLY,MB_MYEXCLAMATION);
  2882. *pbRetVal = FALSE;
  2883. }
  2884. else
  2885. {
  2886. for (lpNum = lpszDialNumber;*lpNum;lpNum++)
  2887. {
  2888. for(lpValid = szValidPhoneCharacters;*lpValid;lpValid++)
  2889. {
  2890. if (*lpNum == *lpValid)
  2891. {
  2892. break; // p2 for loop
  2893. }
  2894. }
  2895. if (!*lpValid)
  2896. {
  2897. break; // p for loop
  2898. }
  2899. }
  2900. }
  2901. if (*lpNum)
  2902. {
  2903. MsgBox(IDS_INVALIDPHONE,MB_MYERROR);
  2904. *pbRetVal = FALSE;
  2905. }
  2906. return S_OK;
  2907. }
  2908. STDMETHODIMP CRefDial::get_HavePhoneBook(BOOL * pVal)
  2909. {
  2910. USES_CONVERSION;
  2911. DWORD_PTR dwPhoneBook;
  2912. HINSTANCE hPHBKDll;
  2913. FARPROC fp;
  2914. if (pVal == NULL)
  2915. return E_POINTER;
  2916. // Assume failure.
  2917. *pVal = FALSE;
  2918. // Try to load the phone book
  2919. hPHBKDll = LoadLibrary(PHONEBOOK_LIBRARY);
  2920. if (hPHBKDll)
  2921. {
  2922. if (NULL != (fp = GetProcAddress(hPHBKDll,PHBK_LOADAPI)))
  2923. {
  2924. if (ERROR_SUCCESS == ((PFNPHONEBOOKLOAD)fp)(OLE2A(m_bstrISPFile),&dwPhoneBook))
  2925. {
  2926. *pVal = TRUE; // Got IT!
  2927. }
  2928. }
  2929. FreeLibrary(hPHBKDll);
  2930. }
  2931. return S_OK;
  2932. }
  2933. STDMETHODIMP CRefDial::get_BrandingFlags(long * pVal)
  2934. {
  2935. if (pVal == NULL)
  2936. return E_POINTER;
  2937. *pVal = m_lBrandingFlags;
  2938. return S_OK;
  2939. }
  2940. STDMETHODIMP CRefDial::put_BrandingFlags(long newVal)
  2941. {
  2942. m_lBrandingFlags = newVal;
  2943. return S_OK;
  2944. }
  2945. /**********************************************************************/
  2946. //
  2947. // FUNCTION: get_CurrentModem
  2948. // put_CurrentModem
  2949. //
  2950. // DESCRIPTION:
  2951. // These functions are used to set the current modem
  2952. // based on the enumerated modem list, and should only
  2953. // be used after taking a snapshot of the modem list
  2954. // with the ModemEnum_* functions. The functions are also
  2955. // intended to be used with an existing RAS connectoid, not
  2956. // to set-up the RefDial object before connecting.
  2957. //
  2958. // HISTORY:
  2959. //
  2960. // donsc - 3/11/98 Added these functions to support the dial error
  2961. // page in the HTML JavaScript code.
  2962. //
  2963. /**********************************************************************/
  2964. //
  2965. // get_CurrentModem will return -1 if the modem list was not enumerated
  2966. // or no modem has been selected for this RefDial object
  2967. //
  2968. STDMETHODIMP CRefDial::get_CurrentModem(long * pVal)
  2969. {
  2970. if (pVal == NULL)
  2971. return E_POINTER;
  2972. *pVal = m_lCurrentModem;
  2973. return S_OK;
  2974. }
  2975. STDMETHODIMP CRefDial::put_CurrentModem(long newVal)
  2976. {
  2977. LPRASENTRY lpRasEntry = NULL;
  2978. LPRASDEVINFO lpRasDevInfo = NULL;
  2979. DWORD dwRasEntrySize = 0;
  2980. DWORD dwRasDevInfoSize = 0;
  2981. RNAAPI *pcRNA = NULL;
  2982. HRESULT hr = S_OK;
  2983. TCHAR *pszNewName = m_emModemEnum.GetDeviceName(newVal);
  2984. TCHAR *pszNewType = m_emModemEnum.GetDeviceType(newVal);
  2985. if((pszNewName==NULL) || (pszNewType==NULL))
  2986. return E_INVALIDARG;
  2987. if(m_lCurrentModem == newVal)
  2988. return S_OK;
  2989. //
  2990. // Must have a connectoid already established to set the
  2991. // current modem.
  2992. //
  2993. if(m_szConnectoid[0]=='\0')
  2994. return E_FAIL;
  2995. // Get the current RAS entry properties
  2996. hr = MyRasGetEntryProperties(NULL,
  2997. m_szConnectoid,
  2998. &lpRasEntry,
  2999. &dwRasEntrySize,
  3000. &lpRasDevInfo,
  3001. &dwRasDevInfoSize);
  3002. //
  3003. // The MyRas function returns 0 on success, not technically
  3004. // an HRESULT
  3005. //
  3006. if(hr!=0 || NULL == lpRasEntry)
  3007. hr = E_FAIL;
  3008. lpRasDevInfo = NULL;
  3009. dwRasDevInfoSize = 0;
  3010. if (SUCCEEDED(hr))
  3011. {
  3012. //
  3013. // Retrieve the dial entry params of the existing entry
  3014. //
  3015. LPRASDIALPARAMS lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR,sizeof(RASDIALPARAMS));
  3016. BOOL bPW = FALSE;
  3017. if (!lpRasDialParams)
  3018. {
  3019. hr = ERROR_NOT_ENOUGH_MEMORY;
  3020. goto PutModemExit;
  3021. }
  3022. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  3023. lstrcpyn(lpRasDialParams->szEntryName,m_szConnectoid,ARRAYSIZE(lpRasDialParams->szEntryName));
  3024. bPW = FALSE;
  3025. hr = MyRasGetEntryDialParams(NULL,lpRasDialParams,&bPW);
  3026. if (FAILED(hr))
  3027. goto PutModemExit;
  3028. //
  3029. // Enter the new ras device info.
  3030. //
  3031. lstrcpy(lpRasEntry->szDeviceName,pszNewName);
  3032. lstrcpy(lpRasEntry->szDeviceType,pszNewType);
  3033. //
  3034. // Set to dial as is
  3035. //
  3036. pcRNA = new RNAAPI;
  3037. if (pcRNA)
  3038. {
  3039. //
  3040. // When changing the actual device, it is not always reliable
  3041. // to just set the new properties. We need to remove the
  3042. // previous entry and create a new one.
  3043. //
  3044. pcRNA->RasDeleteEntry(NULL,m_szConnectoid);
  3045. if(pcRNA->RasSetEntryProperties(NULL,
  3046. m_szConnectoid,
  3047. (LPBYTE)lpRasEntry,
  3048. dwRasEntrySize,
  3049. (LPBYTE)NULL,
  3050. 0)==0)
  3051. {
  3052. //
  3053. // And set the other dialing parameters
  3054. //
  3055. if(pcRNA->RasSetEntryDialParams(NULL,lpRasDialParams,!bPW)!=0)
  3056. hr = E_FAIL;
  3057. }
  3058. else
  3059. hr = E_FAIL;
  3060. delete pcRNA;
  3061. }
  3062. else
  3063. hr = E_FAIL;
  3064. GlobalFree(lpRasDialParams);
  3065. }
  3066. PutModemExit:
  3067. if(SUCCEEDED(hr))
  3068. {
  3069. m_lCurrentModem = newVal;
  3070. lstrcpy(m_ISPImport.m_szDeviceName,pszNewName);
  3071. lstrcpy(m_ISPImport.m_szDeviceType,pszNewType);
  3072. // Get the device name and type in the registry, since ConfigRasEntryDevice
  3073. // will use them. ConfigRasEntryDevice is called when the new connectoid
  3074. // is being created, so if the user changes the modem, we want that
  3075. // reflected in the new connectoid (BUG 20841)
  3076. m_ISPImport.SetDeviceSelectedByUser(DEVICENAMEKEY, pszNewName);
  3077. m_ISPImport.SetDeviceSelectedByUser (DEVICETYPEKEY, pszNewType);
  3078. m_ISPImport.m_bIsISDNDevice = (lstrcmpi(pszNewType, RASDT_Isdn) == 0);
  3079. m_lpGatherInfo->m_fType = TYPE_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  3080. m_lpGatherInfo->m_bMask = MASK_SIGNUP_ANY | (m_ISPImport.m_bIsISDNDevice ? MASK_ISDN_BIT:MASK_ANALOG_BIT);
  3081. }
  3082. return hr;
  3083. }
  3084. STDMETHODIMP CRefDial::get_ISPSupportPhoneNumber(BSTR * pVal)
  3085. {
  3086. if (pVal == NULL)
  3087. return E_POINTER;
  3088. *pVal = m_bstrSupportNumber.Copy();
  3089. return S_OK;
  3090. }
  3091. STDMETHODIMP CRefDial::put_ISPSupportPhoneNumber(BSTR newVal)
  3092. {
  3093. // TODO: Add your implementation code here
  3094. m_bstrSupportNumber = newVal;
  3095. return S_OK;
  3096. }
  3097. STDMETHODIMP CRefDial::get_LoggingStartUrl(BSTR * pVal)
  3098. {
  3099. if(pVal == NULL)
  3100. return E_POINTER;
  3101. *pVal = m_bstrLoggingStartUrl;
  3102. return S_OK;
  3103. }
  3104. STDMETHODIMP CRefDial::get_LoggingEndUrl(BSTR * pVal)
  3105. {
  3106. if(pVal == NULL)
  3107. return E_POINTER;
  3108. *pVal = m_bstrLoggingEndUrl;
  3109. return S_OK;
  3110. }
  3111. void CRefDial::ShowCredits()
  3112. {
  3113. #ifdef ICW_EASTEREGG
  3114. HINSTANCE hinstMSHTML = LoadLibrary(TEXT("MSHTML.DLL"));
  3115. if(hinstMSHTML)
  3116. {
  3117. SHOWHTMLDIALOGFN *pfnShowHTMLDialog;
  3118. pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)GetProcAddress(hinstMSHTML, "ShowHTMLDialog");
  3119. if(pfnShowHTMLDialog)
  3120. {
  3121. IMoniker *pmk;
  3122. TCHAR szTemp[MAX_PATH*2];
  3123. BSTR bstr;
  3124. lstrcpy(szTemp, TEXT("res://"));
  3125. GetModuleFileName(_Module.GetModuleInstance(), szTemp + lstrlen(szTemp), ARRAYSIZE(szTemp) - lstrlen(szTemp));
  3126. lstrcat(szTemp, TEXT("/CREDITS_RESOURCE"));
  3127. bstr = A2BSTR((LPTSTR) szTemp);
  3128. CreateURLMoniker(NULL, bstr, &pmk);
  3129. if(pmk)
  3130. {
  3131. HRESULT hr;
  3132. VARIANT varReturn;
  3133. VariantInit(&varReturn);
  3134. hr = (*pfnShowHTMLDialog)(NULL, pmk, NULL, NULL, &varReturn);
  3135. pmk->Release();
  3136. }
  3137. SysFreeString(bstr);
  3138. }
  3139. FreeLibrary(hinstMSHTML);
  3140. }
  3141. #endif
  3142. }
  3143. STDMETHODIMP CRefDial::SelectedPhoneNumber(long newVal, BOOL * pbRetVal)
  3144. {
  3145. BOOL bSuccess = FALSE;
  3146. *pbRetVal = TRUE;
  3147. SetupConnectoid(m_pSuggestInfo,
  3148. newVal,
  3149. &m_szConnectoid[0],
  3150. sizeof(m_szConnectoid),
  3151. &bSuccess);
  3152. if( !bSuccess )
  3153. {
  3154. m_bQuitWizard = TRUE;
  3155. *pbRetVal = FALSE;
  3156. }
  3157. else
  3158. {
  3159. // Generate a Displayable number
  3160. m_hrDisplayableNumber = GetDisplayableNumber();
  3161. }
  3162. return S_OK;
  3163. }
  3164. STDMETHODIMP CRefDial::PhoneNumberEnum_Reset()
  3165. {
  3166. m_PhoneNumberEnumidx = 0;
  3167. return S_OK;
  3168. }
  3169. #define MAX_PAN_NUMBER_LEN 64
  3170. STDMETHODIMP CRefDial::PhoneNumberEnum_Next(BSTR *pNumber)
  3171. {
  3172. TCHAR szTemp[MAX_PAN_NUMBER_LEN + 1];
  3173. PACCESSENTRY pAE;
  3174. if (pNumber == NULL)
  3175. return E_POINTER;
  3176. if (m_PhoneNumberEnumidx > m_pSuggestInfo->wNumber - 1)
  3177. m_PhoneNumberEnumidx = m_pSuggestInfo->wNumber -1;
  3178. pAE = m_pSuggestInfo->rgpAccessEntry[m_PhoneNumberEnumidx];
  3179. wsprintf(szTemp,TEXT("%s (%s) %s"),pAE->szCity,pAE->szAreaCode,pAE->szAccessNumber);
  3180. ++m_PhoneNumberEnumidx;
  3181. *pNumber = A2BSTR(szTemp);
  3182. return S_OK;
  3183. }
  3184. STDMETHODIMP CRefDial::get_PhoneNumberEnum_NumDevices(long * pVal)
  3185. {
  3186. if (pVal == NULL)
  3187. return E_POINTER;
  3188. m_PhoneNumberEnumidx = 0;
  3189. *pVal = m_pSuggestInfo->wNumber;
  3190. return S_OK;
  3191. }
  3192. STDMETHODIMP CRefDial::get_bIsISDNDevice(BOOL *pVal)
  3193. {
  3194. if (pVal == NULL)
  3195. return E_POINTER;
  3196. // NOTE SetupForDialing needs to be called before this API, otherwise the return
  3197. // value is really undefined
  3198. // Set the return value based on the ISPImport object (that is the object which
  3199. // imports the data from the .ISP file, and also selects the RAS device used
  3200. // to connect
  3201. *pVal = m_ISPImport.m_bIsISDNDevice;
  3202. return (S_OK);
  3203. }
  3204. //+---------------------------------------------------------------------------
  3205. //
  3206. // Function: get_RasGetConnectStatus
  3207. //
  3208. // Synopsis: Checks for existing Ras connection
  3209. //
  3210. //+---------------------------------------------------------------------------
  3211. STDMETHODIMP CRefDial::get_RasGetConnectStatus(BOOL *pVal)
  3212. {
  3213. RNAAPI *pcRNA;
  3214. HRESULT hr = E_FAIL;
  3215. *pVal = FALSE;
  3216. if (NULL != m_hrasconn)
  3217. {
  3218. RASCONNSTATUS rasConnectState;
  3219. rasConnectState.dwSize = sizeof(RASCONNSTATUS);
  3220. pcRNA = new RNAAPI;
  3221. if (pcRNA)
  3222. {
  3223. if (0 == pcRNA->RasGetConnectStatus(m_hrasconn,
  3224. &rasConnectState))
  3225. {
  3226. if (RASCS_Disconnected != rasConnectState.rasconnstate)
  3227. *pVal = TRUE;
  3228. }
  3229. delete pcRNA;
  3230. pcRNA = NULL;
  3231. hr = S_OK;
  3232. }
  3233. }
  3234. return hr;
  3235. }