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.

958 lines
28 KiB

  1. /*-----------------------------------------------------------------------------
  2. dialutil.cpp
  3. Miscellenous housekeeping functions for autodial handler
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. ChrisK ChrisKauffman
  8. History:
  9. 7/22/96 ChrisK Cleaned and formatted
  10. -----------------------------------------------------------------------------*/
  11. #include "pch.hpp"
  12. #include <raserror.h>
  13. #include <tapi.h>
  14. #include "dialutil.h"
  15. #include "resource.h"
  16. #define CANONICAL_CAP TEXT("+%d (%s) %s")
  17. #define CANONICAL_CXP TEXT("+%d %s")
  18. #define TAPI_VERSION 0x00010004
  19. #define SMALLBUFLEN 80
  20. #define ASSERT(c)
  21. #define TRACE_OUT(c)
  22. #define lstrnicmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, sz1, cch, sz2, cch) - 2)
  23. #define lstrncmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, 0, sz1, cch, sz2, cch) - 2)
  24. typedef DWORD (WINAPI * RASGETENTRYPROPERTIES)
  25. (LPTSTR lpszPhonebook, LPTSTR szEntry, LPBYTE lpbEntry,
  26. LPDWORD lpdwEntrySize, LPBYTE lpb, LPDWORD lpdwSize);
  27. typedef DWORD (WINAPI * RASSETENTRYPROPERTIES)
  28. (LPTSTR lpszPhonebook, LPTSTR szEntry, LPBYTE lpbEntry,
  29. DWORD dwEntrySize, LPBYTE lpb, DWORD dwSize);
  30. extern HINSTANCE g_hInstance;
  31. static const HWND hwndNil = NULL;
  32. static const TCHAR szRnaAppWindowClass[] = TEXT("#32770"); // hard coded dialog class name
  33. static const CHAR szRasGetEntryProperties[] = "RasGetEntryProperties";
  34. static const CHAR szRasSetEntryProperties[] = "RasSetEntryProperties";
  35. static const TCHAR szRasDll[] = TEXT("rasapi32.dll");
  36. static const TCHAR szRnaPhDll[] = TEXT("rnaph.dll");
  37. void CALLBACK LineCallbackProc (DWORD handle, DWORD dwMsg, DWORD dwInst,
  38. DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
  39. //
  40. // defined in dialerr.cpp
  41. //
  42. void ProcessDBCS(HWND hDlg, int ctlID);
  43. /* C E N T E R W I N D O W */
  44. /*-------------------------------------------------------------------------
  45. %%Function: CenterWindow
  46. Center a window over another window.
  47. -------------------------------------------------------------------------*/
  48. VOID CenterWindow(HWND hwndChild, HWND hwndParent)
  49. {
  50. int xNew, yNew;
  51. int cxChild, cyChild;
  52. int cxParent, cyParent;
  53. int cxScreen, cyScreen;
  54. RECT rcChild, rcParent;
  55. HDC hdc;
  56. // Get the Height and Width of the child window
  57. GetWindowRect(hwndChild, &rcChild);
  58. cxChild = rcChild.right - rcChild.left;
  59. cyChild = rcChild.bottom - rcChild.top;
  60. // Get the Height and Width of the parent window
  61. GetWindowRect(hwndParent, &rcParent);
  62. cxParent = rcParent.right - rcParent.left;
  63. cyParent = rcParent.bottom - rcParent.top;
  64. // Get the display limits
  65. hdc = GetDC(hwndChild);
  66. if (hdc == NULL) {
  67. // major problems - move window to 0,0
  68. xNew = yNew = 0;
  69. } else {
  70. cxScreen = GetDeviceCaps(hdc, HORZRES);
  71. cyScreen = GetDeviceCaps(hdc, VERTRES);
  72. ReleaseDC(hwndChild, hdc);
  73. if (hwndParent == hwndNil) {
  74. cxParent = cxScreen;
  75. cyParent = cyScreen;
  76. SetRect(&rcParent, 0, 0, cxScreen, cyScreen);
  77. }
  78. // Calculate new X position, then adjust for screen
  79. xNew = rcParent.left + ((cxParent - cxChild) / 2);
  80. if (xNew < 0) {
  81. xNew = 0;
  82. } else if ((xNew + cxChild) > cxScreen) {
  83. xNew = cxScreen - cxChild;
  84. }
  85. // Calculate new Y position, then adjust for screen
  86. yNew = rcParent.top + ((cyParent - cyChild) / 2);
  87. if (yNew < 0) {
  88. yNew = 0;
  89. } else if ((yNew + cyChild) > cyScreen) {
  90. yNew = cyScreen - cyChild;
  91. }
  92. }
  93. SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0,
  94. SWP_NOSIZE | SWP_NOZORDER);
  95. }
  96. static HWND hwndFound = NULL;
  97. static BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam)
  98. {
  99. TCHAR szTemp[SMALLBUFLEN+2];
  100. PTSTR pszTitle;
  101. UINT uLen1, uLen2;
  102. if(!IsWindowVisible(hwnd))
  103. return TRUE;
  104. if(GetClassName(hwnd, szTemp, SMALLBUFLEN)==0)
  105. return TRUE; // continue enumerating
  106. if(lstrcmp(szTemp, szRnaAppWindowClass)!=0)
  107. return TRUE;
  108. if(GetWindowText(hwnd, szTemp, SMALLBUFLEN)==0)
  109. return TRUE;
  110. szTemp[SMALLBUFLEN] = 0;
  111. uLen1 = lstrlen(szTemp);
  112. if (uLen1 > 5)
  113. uLen1 -= 5; // skip last 5 chars of title (avoid "...")
  114. pszTitle = (PTSTR)lparam;
  115. ASSERT(pszTitle);
  116. uLen2 = lstrlen(pszTitle);
  117. TRACE_OUT(("Title=(%s), len=%d, Window=(%s), len=%d\r\n", pszTitle, uLen2, szTemp, uLen1));
  118. if(uLen2 < uLen1)
  119. return TRUE;
  120. if(lstrnicmp(pszTitle, szTemp, uLen1)!=0)
  121. return TRUE;
  122. hwndFound = hwnd;
  123. return FALSE;
  124. }
  125. static HWND MyFindRNAWindow(PTSTR pszTitle)
  126. {
  127. DWORD dwRet;
  128. hwndFound = NULL;
  129. dwRet = EnumWindows((WNDENUMPROC)(&MyEnumWindowsProc), (LPARAM)pszTitle);
  130. TRACE_OUT(("EnumWindows returned %d\r\n", dwRet));
  131. return hwndFound;
  132. }
  133. /*******************************************************************
  134. NAME: MinimizeRNAWindow
  135. SYNOPSIS: Finds and minimizes the annoying RNA window
  136. ENTRY: pszConnectoidName - name of connectoid launched
  137. ********************************************************************/
  138. BOOL MinimizeRNAWindow(TCHAR * pszConnectoidName)
  139. {
  140. HWND hwndRNAApp;
  141. TCHAR szFmt[SMALLBUFLEN + 1];
  142. TCHAR szTitle[RAS_MaxEntryName + SMALLBUFLEN + 1];
  143. // load the title format ("connected to <connectoid name>" from resource
  144. LoadString(g_hInstance, IDS_CONNECTED_TO, szFmt, SIZEOF_TCHAR_BUFFER(szFmt));
  145. // build the title
  146. wsprintf(szTitle, szFmt, pszConnectoidName);
  147. hwndRNAApp=MyFindRNAWindow(szTitle);
  148. if(hwndRNAApp)
  149. {
  150. // minimize the RNA window
  151. ShowWindow(hwndRNAApp,SW_MINIMIZE);
  152. return TRUE;
  153. }
  154. return FALSE;
  155. }
  156. //****************************************************************************
  157. // static LPTSTR NEAR PASCAL GetDisplayPhone (LPTSTR)
  158. //
  159. // This function returns the pointer to displayable phone number. It stripped
  160. // all the prefixes we do not want to show to the user.
  161. //
  162. // History:
  163. // Tue 26-Jul-1994 16:07:00 -by- Viroon Touranachun [viroont]
  164. // Created.
  165. //****************************************************************************
  166. LPTSTR NEAR PASCAL GetDisplayPhone (LPTSTR szPhoneNum)
  167. {
  168. // Check whether the first string is the know prefix
  169. //
  170. if ((*szPhoneNum == 'T') || (*szPhoneNum == 'P'))
  171. {
  172. // It is the prefix
  173. //
  174. szPhoneNum++;
  175. // The first displayable number is not white space after prefix
  176. //
  177. while ((*szPhoneNum == ' ') || (*szPhoneNum == '\t'))
  178. szPhoneNum++;
  179. };
  180. return szPhoneNum;
  181. }
  182. void CALLBACK LineCallbackProc (DWORD handle, DWORD dwMsg, DWORD dwInst,
  183. DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
  184. {
  185. }
  186. //****************************************************************************
  187. // TranslateCanonicalAddress()
  188. //
  189. // Function: This function translate a canonical address to a dialable address.
  190. //
  191. // Returns: SUCCESS or an error code
  192. //
  193. //****************************************************************************
  194. static DWORD NEAR PASCAL TranslateCanonicalAddress(DWORD dwID, LPTSTR szCanonical,
  195. LPTSTR szDialable, DWORD cb)
  196. {
  197. LINETRANSLATEOUTPUT lto, FAR* lplto;
  198. DWORD dwRet;
  199. DWORD cDevices;
  200. HLINEAPP hApp;
  201. if ((dwRet = lineInitialize(&hApp, g_hInstance,
  202. (LINECALLBACK)LineCallbackProc,
  203. NULL, &cDevices)) == SUCCESS)
  204. {
  205. // Get the actual buffer size
  206. lto.dwTotalSize = sizeof(lto);
  207. if ((dwRet = lineTranslateAddress(hApp, dwID,
  208. TAPI_VERSION, szCanonical, 0,
  209. LINETRANSLATEOPTION_CANCELCALLWAITING,
  210. &lto)) == SUCCESS)
  211. {
  212. // Allocate the dialable number buffer
  213. if ((lplto = (LPLINETRANSLATEOUTPUT)GlobalAlloc(LMEM_FIXED, lto.dwNeededSize))
  214. != NULL)
  215. {
  216. // Translate the phone number
  217. lplto->dwTotalSize = lto.dwNeededSize;
  218. if ((dwRet = lineTranslateAddress(hApp, dwID,
  219. TAPI_VERSION, szCanonical, 0,
  220. LINETRANSLATEOPTION_CANCELCALLWAITING,
  221. lplto)) == SUCCESS)
  222. {
  223. LPTSTR szPhone;
  224. szPhone = (LPTSTR)(((LPBYTE)lplto)+lplto->dwDialableStringOffset);
  225. lstrcpyn(szDialable, szPhone, cb);
  226. }
  227. else
  228. dwRet = ERROR_TAPI_CONFIGURATION;
  229. GlobalFree((HLOCAL)lplto);
  230. }
  231. else
  232. dwRet = ERROR_OUTOFMEMORY;
  233. }
  234. else
  235. dwRet = ERROR_TAPI_CONFIGURATION;
  236. }
  237. else
  238. dwRet = ERROR_TAPI_CONFIGURATION;
  239. lineShutdown(hApp);
  240. return dwRet;
  241. }
  242. //****************************************************************************
  243. // DWORD NEAR PASCAL BuildPhoneString (LPBYTE, LPPHONENUM)
  244. //
  245. // This function builds a phone number string from the phone number struct
  246. //
  247. // History:
  248. // Mon 14-Mar-1994 13:10:44 -by- Viroon Touranachun [viroont]
  249. // Created.
  250. //****************************************************************************
  251. static DWORD NEAR PASCAL BuildPhoneString (LPTSTR szPhoneNum, LPRASENTRY lpRasEntry)
  252. {
  253. if (*lpRasEntry->szAreaCode != '\0')
  254. {
  255. wsprintf(szPhoneNum, CANONICAL_CAP, lpRasEntry->dwCountryCode,
  256. lpRasEntry->szAreaCode, lpRasEntry->szLocalPhoneNumber);
  257. }
  258. else
  259. {
  260. wsprintf(szPhoneNum, CANONICAL_CXP, lpRasEntry->dwCountryCode,
  261. lpRasEntry->szLocalPhoneNumber);
  262. };
  263. return SUCCESS;
  264. };
  265. //****************************************************************************
  266. // BOOL NEAR PASCAL TranslatePhoneNumber(LPTSTR, LPPHONENUM, LPTSTR)
  267. //
  268. // Translate phone number into a dialble string.
  269. //
  270. // Returns TRUE if successful, FALSE if use default.
  271. //
  272. // History:
  273. // Fri 17-Jun-1994 08:42:49 -by- Viroon Touranachun [viroont]
  274. // Created
  275. //****************************************************************************
  276. static BOOL NEAR PASCAL TranslatePhoneNumber(LPRASENTRY lpRasEntry, LPTSTR szPhoneNumber)
  277. {
  278. TCHAR szOrgPhone[RAS_MaxPhoneNumber+1];
  279. // Do we need to use the addrees book phone number?
  280. //
  281. if (lpRasEntry != NULL)
  282. {
  283. // Yes! Do we need to translate anything?
  284. //
  285. if (lpRasEntry->dwCountryID == 0)
  286. {
  287. // No! we dial as is.
  288. //
  289. lstrcpyn(szOrgPhone, lpRasEntry->szLocalPhoneNumber, RAS_MaxPhoneNumber + 1);
  290. }
  291. else
  292. {
  293. // Yes! build the phone number
  294. //
  295. BuildPhoneString (szOrgPhone, lpRasEntry);
  296. };
  297. }
  298. else
  299. {
  300. // No! we have a overwritten phone number
  301. //
  302. ASSERT(lstrlen(szPhoneNumber) != 0);
  303. lstrcpyn(szOrgPhone, szPhoneNumber, RAS_MaxPhoneNumber+1);
  304. };
  305. // Attempt address translation
  306. //
  307. if (TranslateCanonicalAddress(0, szOrgPhone,
  308. szPhoneNumber, RAS_MaxPhoneNumber+1)
  309. != ERROR_SUCCESS)
  310. {
  311. // Translation fails, use default phone number
  312. //
  313. if (lpRasEntry != NULL)
  314. {
  315. // Use entry's local phone number
  316. //
  317. lstrcpy(szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  318. }
  319. else
  320. {
  321. // Restore the original phone number
  322. //
  323. lstrcpy(szPhoneNumber, szOrgPhone);
  324. };
  325. return FALSE;
  326. };
  327. return TRUE;
  328. }
  329. DWORD GetPhoneNumber(LPTSTR lpszEntryName, LPTSTR lpszPhoneNumber)
  330. {
  331. DWORD dwEntrySize = 0;
  332. DWORD dwSize = 0;
  333. DWORD dwRet;
  334. LPRASENTRY lpRasEntry = NULL;
  335. HINSTANCE hLib;
  336. RASGETENTRYPROPERTIES lpfnRasGetEntryProperties;
  337. // look for needed function in rasapi.dll
  338. hLib = LoadLibrary(szRasDll);
  339. if (NULL != hLib)
  340. {
  341. lpfnRasGetEntryProperties = (RASGETENTRYPROPERTIES)GetProcAddress(hLib, szRasGetEntryProperties);
  342. if (NULL != lpfnRasGetEntryProperties)
  343. {
  344. // we found the function
  345. goto get_entry;
  346. }
  347. FreeLibrary(hLib);
  348. }
  349. // try rnaph.dll if not on NT
  350. if (FALSE == IsNT ())
  351. {
  352. hLib = LoadLibrary(szRnaPhDll);
  353. if (NULL == hLib)
  354. {
  355. return ERROR_FILE_NOT_FOUND;
  356. }
  357. lpfnRasGetEntryProperties = (RASGETENTRYPROPERTIES)GetProcAddress(hLib, szRasGetEntryProperties);
  358. if (NULL == lpfnRasGetEntryProperties)
  359. {
  360. FreeLibrary(hLib);
  361. return ERROR_INVALID_FUNCTION;
  362. }
  363. }
  364. else
  365. {
  366. return ERROR_FILE_NOT_FOUND;
  367. }
  368. get_entry:
  369. // get size needed for RASENTRY struct
  370. lpfnRasGetEntryProperties(
  371. NULL,
  372. lpszEntryName,
  373. NULL,
  374. &dwEntrySize,
  375. NULL,
  376. &dwSize);
  377. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR, dwEntrySize + dwSize);
  378. if (NULL == lpRasEntry)
  379. {
  380. dwRet = ERROR_OUTOFMEMORY;
  381. }
  382. else
  383. {
  384. lpRasEntry->dwSize = dwEntrySize;
  385. dwRet = lpfnRasGetEntryProperties(
  386. NULL,
  387. lpszEntryName,
  388. (LPBYTE)lpRasEntry,
  389. &dwEntrySize,
  390. ((LPBYTE)lpRasEntry) + dwEntrySize,
  391. &dwSize);
  392. if (ERROR_SUCCESS == dwRet)
  393. {
  394. TranslatePhoneNumber(lpRasEntry, lpszPhoneNumber);
  395. }
  396. GlobalFree((HLOCAL)lpRasEntry);
  397. }
  398. FreeLibrary(hLib);
  399. return dwRet;
  400. }
  401. DWORD _RasGetStateString(RASCONNSTATE state, LPTSTR lpszState, DWORD cb)
  402. {
  403. UINT idString;
  404. switch(state)
  405. {
  406. case RASCS_OpenPort:
  407. idString = IDS_OPENPORT;
  408. break;
  409. case RASCS_PortOpened:
  410. idString = IDS_PORTOPENED;
  411. break;
  412. case RASCS_ConnectDevice:
  413. idString = IDS_CONNECTDEVICE;
  414. break;
  415. case RASCS_DeviceConnected:
  416. idString = IDS_DEVICECONNECTED;
  417. break;
  418. case RASCS_AllDevicesConnected:
  419. idString = IDS_ALLDEVICESCONNECTED;
  420. break;
  421. case RASCS_Authenticate:
  422. idString = IDS_AUTHENTICATE;
  423. break;
  424. case RASCS_AuthNotify:
  425. idString = IDS_AUTHNOTIFY;
  426. break;
  427. case RASCS_AuthRetry:
  428. idString = IDS_AUTHRETRY;
  429. break;
  430. case RASCS_AuthCallback:
  431. idString = IDS_AUTHCALLBACK;
  432. break;
  433. case RASCS_AuthChangePassword:
  434. idString = IDS_AUTHCHANGEPASSWORD;
  435. break;
  436. case RASCS_AuthProject:
  437. idString = IDS_AUTHPROJECT;
  438. break;
  439. case RASCS_AuthLinkSpeed:
  440. idString = IDS_AUTHLINKSPEED;
  441. break;
  442. case RASCS_AuthAck:
  443. idString = IDS_AUTHACK;
  444. break;
  445. case RASCS_ReAuthenticate:
  446. idString = IDS_REAUTHENTICATE;
  447. break;
  448. case RASCS_Authenticated:
  449. idString = IDS_AUTHENTICATED;
  450. break;
  451. case RASCS_PrepareForCallback:
  452. idString = IDS_PREPAREFORCALLBACK;
  453. break;
  454. case RASCS_WaitForModemReset:
  455. idString = IDS_WAITFORMODEMRESET;
  456. break;
  457. case RASCS_WaitForCallback:
  458. idString = IDS_WAITFORCALLBACK;
  459. break;
  460. case RASCS_Interactive:
  461. idString = IDS_INTERACTIVE;
  462. break;
  463. case RASCS_RetryAuthentication:
  464. idString = IDS_RETRYAUTHENTICATION;
  465. break;
  466. case RASCS_CallbackSetByCaller:
  467. idString = IDS_CALLBACKSETBYCALLER;
  468. break;
  469. case RASCS_PasswordExpired:
  470. idString = IDS_PASSWORDEXPIRED;
  471. break;
  472. case RASCS_Connected:
  473. idString = IDS_CONNECTED;
  474. break;
  475. case RASCS_Disconnected:
  476. idString = IDS_DISCONNECTED;
  477. break;
  478. default:
  479. idString = IDS_UNDEFINED_ERROR;
  480. break;
  481. }
  482. if (LoadString(g_hInstance, idString, lpszState, cb))
  483. {
  484. return GetLastError();
  485. }
  486. return ERROR_SUCCESS;
  487. }
  488. DWORD ReplacePhoneNumber(LPTSTR lpszEntryName, LPTSTR lpszPhoneNumber)
  489. {
  490. DWORD dwEntrySize = 0;
  491. DWORD dwSize = 0;
  492. DWORD dwRet;
  493. LPRASENTRY lpRasEntry = NULL;
  494. HINSTANCE hLib;
  495. RASGETENTRYPROPERTIES lpfnRasGetEntryProperties;
  496. RASSETENTRYPROPERTIES lpfnRasSetEntryProperties;
  497. // look for needed function in rasapi.dll
  498. hLib = LoadLibrary(szRasDll);
  499. if (NULL != hLib)
  500. {
  501. lpfnRasGetEntryProperties = (RASGETENTRYPROPERTIES)GetProcAddress(hLib, szRasGetEntryProperties);
  502. if (NULL != lpfnRasGetEntryProperties)
  503. {
  504. // we found the function
  505. goto get_entry2;
  506. }
  507. FreeLibrary(hLib);
  508. }
  509. // try rnaph.dll
  510. hLib = LoadLibrary(szRnaPhDll);
  511. if (NULL == hLib)
  512. {
  513. return ERROR_FILE_NOT_FOUND;
  514. }
  515. lpfnRasGetEntryProperties = (RASGETENTRYPROPERTIES)GetProcAddress(hLib, szRasGetEntryProperties);
  516. if (NULL == lpfnRasGetEntryProperties)
  517. {
  518. FreeLibrary(hLib);
  519. return ERROR_INVALID_FUNCTION;
  520. }
  521. get_entry2:
  522. // get size needed for RASENTRY struct
  523. lpfnRasGetEntryProperties(
  524. NULL,
  525. lpszEntryName,
  526. NULL,
  527. &dwEntrySize,
  528. NULL,
  529. &dwSize);
  530. lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR, dwEntrySize + dwSize);
  531. if (NULL == lpRasEntry)
  532. {
  533. dwRet = ERROR_OUTOFMEMORY;
  534. }
  535. else
  536. {
  537. lpRasEntry->dwSize = dwEntrySize;
  538. dwRet = lpfnRasGetEntryProperties(
  539. NULL,
  540. lpszEntryName,
  541. (LPBYTE)lpRasEntry,
  542. &dwEntrySize,
  543. ((LPBYTE)lpRasEntry) + dwEntrySize,
  544. &dwSize);
  545. if (ERROR_SUCCESS == dwRet)
  546. {
  547. //lstrcpyn(lpRasEntry->szLocalPhoneNumber,lpszPhoneNumber,RAS_MaxPhoneNumber);
  548. lstrcpy(lpRasEntry->szLocalPhoneNumber,lpszPhoneNumber);
  549. lpfnRasSetEntryProperties = (RASSETENTRYPROPERTIES)GetProcAddress(hLib, szRasSetEntryProperties);
  550. lpRasEntry->dwfOptions &= ~(RASEO_UseCountryAndAreaCodes);
  551. TranslatePhoneNumber(lpRasEntry, lpszPhoneNumber);
  552. dwRet = lpfnRasSetEntryProperties(
  553. NULL,
  554. lpszEntryName,
  555. (LPBYTE)lpRasEntry,
  556. dwEntrySize,
  557. NULL,
  558. 0);
  559. // ((LPBYTE)lpRasEntry) + dwEntrySize,
  560. // dwSize);
  561. #if !defined(WIN16)
  562. RasSetEntryPropertiesScriptPatch(lpRasEntry->szScript, lpszEntryName);
  563. #endif //!win16
  564. }
  565. GlobalFree((HLOCAL)lpRasEntry);
  566. }
  567. FreeLibrary(hLib);
  568. return dwRet;
  569. }
  570. // ############################################################################
  571. LPTSTR StrDup(LPTSTR *ppszDest,LPCTSTR pszSource)
  572. {
  573. if (ppszDest && pszSource)
  574. {
  575. *ppszDest = (LPTSTR)GlobalAlloc(GPTR,sizeof(TCHAR)*(lstrlen(pszSource)+1));
  576. if (*ppszDest)
  577. return (lstrcpy(*ppszDest,pszSource));
  578. }
  579. return NULL;
  580. }
  581. // ############################################################################
  582. // NAME: GenericDlgProc
  583. //
  584. // This is a common dlg proc that is shared by all of the signup connectoid
  585. // dialogs
  586. //
  587. // Notes:
  588. // This basically works because each dialog has an object associated
  589. // with it, and that object has a particular dlgproc that is called
  590. // at the end in order to handle specific functionality for the dialogs.
  591. //
  592. // Created 1/28/96, Chris Kauffman
  593. // ############################################################################
  594. INT_PTR CALLBACK GenericDlgProc(
  595. HWND hwndDlg, // handle to dialog box
  596. UINT uMsg, // message
  597. WPARAM wParam, // first message parameter
  598. LPARAM lParam // second message parameter
  599. )
  600. {
  601. CDialog *pcDlg = NULL;
  602. INT_PTR lRet;
  603. switch (uMsg)
  604. {
  605. case WM_QUERYENDSESSION:
  606. EndDialog(hwndDlg,IDC_CMDCANCEL);
  607. lRet = TRUE;
  608. break;
  609. case WM_INITDIALOG:
  610. pcDlg = (CDialog *)lParam;
  611. SetWindowLongPtr(hwndDlg,DWLP_USER,(LONG_PTR)lParam);
  612. lRet = TRUE;
  613. MakeBold(GetDlgItem(hwndDlg,IDC_LBLTITLE),TRUE,FW_BOLD);
  614. //
  615. // 7/18/97 jmazner Olympus #1111
  616. // dialing string could contain DBCS if using a calling card, so
  617. // make sure we display that correctly
  618. //
  619. ProcessDBCS(hwndDlg, IDC_LBLNUMBER);
  620. break;
  621. case WM_CLOSE:
  622. if (!pcDlg) pcDlg = (CDialog*)GetWindowLongPtr(hwndDlg,DWLP_USER);
  623. if (pcDlg)
  624. {
  625. if (pcDlg->m_bShouldAsk)
  626. {
  627. if (MessageBox(hwndDlg,GetSz(IDS_WANTTOEXIT),GetSz(IDS_TITLE),
  628. MB_APPLMODAL | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES)
  629. EndDialog(hwndDlg,IDC_CMDCANCEL);
  630. lRet = TRUE;
  631. }
  632. }
  633. break;
  634. default:
  635. // let the system process the message
  636. lRet = FALSE;
  637. }
  638. if (!pcDlg) pcDlg = (CDialog*)GetWindowLongPtr(hwndDlg,DWLP_USER);
  639. if (pcDlg)
  640. lRet = pcDlg->DlgProc(hwndDlg,uMsg,wParam,lParam,lRet);
  641. return lRet;
  642. }
  643. // ############################################################################
  644. HRESULT WINAPI ICWGetRasEntry(LPRASENTRY *ppRasEntry, LPDWORD lpdwRasEntrySize, LPRASDEVINFO *ppRasDevInfo, LPDWORD lpdwRasDevInfoSize, LPTSTR pszEntryName)
  645. {
  646. //DWORD dwRasEntrySize=0;
  647. //DWORD dwRasDevInfoSize=0;
  648. HINSTANCE hRasDll = NULL;
  649. HRESULT hr = ERROR_SUCCESS;
  650. FARPROC fp = NULL;
  651. RNAAPI *pcRNA;
  652. DWORD dwOldDevInfoBuffSize = 0;
  653. //
  654. // Validate parameters
  655. //
  656. if (!ppRasEntry || !lpdwRasEntrySize || !ppRasDevInfo || !lpdwRasDevInfoSize || !pszEntryName || !lstrlen(pszEntryName))
  657. {
  658. hr = ERROR_INVALID_PARAMETER;
  659. goto ICWGetRasEntryExit;
  660. }
  661. // *ppRasEntry and *ppRasDevInfo should not have memory allocated to them
  662. Assert( *ppRasEntry == NULL );
  663. Assert( *ppRasDevInfo == NULL );
  664. Assert( *lpdwRasEntrySize == 0);
  665. Assert( *lpdwRasDevInfoSize == 0);
  666. //
  667. // Instantiate RNA wrapper
  668. //
  669. pcRNA = new RNAAPI;
  670. if (NULL == pcRNA)
  671. {
  672. hr = ERROR_NOT_ENOUGH_MEMORY;
  673. goto ICWGetRasEntryExit;
  674. }
  675. // use RasGetEntryProperties with a NULL lpRasEntry pointer to find out size buffer we need
  676. // As per the docs' recommendation, do the same with a NULL lpRasDevInfo pointer.
  677. hr = pcRNA->RasGetEntryProperties(NULL,
  678. pszEntryName,
  679. //#ifdef WIN16
  680. (LPBYTE)
  681. //#endif
  682. *ppRasEntry,
  683. lpdwRasEntrySize,
  684. (LPBYTE)*ppRasDevInfo,
  685. lpdwRasDevInfoSize);
  686. // we expect the above call to fail because the buffer size is 0
  687. // If it doesn't fail, that means our RasEntry is messed, so we're in trouble
  688. if( ERROR_BUFFER_TOO_SMALL != hr )
  689. {
  690. goto ICWGetRasEntryExit;
  691. }
  692. // dwRasEntrySize and dwRasDevInfoSize now contain the size needed for their
  693. // respective buffers, so allocate the memory for them
  694. // dwRasEntrySize should never be less than the size of the RASENTRY struct.
  695. // If it is, we'll run into problems sticking values into the struct's fields
  696. Assert( *lpdwRasEntrySize >= sizeof(RASENTRY) );
  697. #if defined(WIN16)
  698. //
  699. // Allocate extra 256 bytes to workaround memory overrun bug in RAS
  700. //
  701. *ppRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,*lpdwRasEntrySize + 256);
  702. #else
  703. *ppRasEntry = (LPRASENTRY)GlobalAlloc(GPTR,*lpdwRasEntrySize);
  704. #endif
  705. if ( !(*ppRasEntry) )
  706. {
  707. hr = ERROR_NOT_ENOUGH_MEMORY;
  708. goto ICWGetRasEntryExit;
  709. }
  710. //
  711. // Allocate the DeviceInfo size that RasGetEntryProperties told us we needed.
  712. // If size is 0, don't alloc anything
  713. //
  714. if( *lpdwRasDevInfoSize > 0 )
  715. {
  716. Assert( *lpdwRasDevInfoSize >= sizeof(RASDEVINFO) );
  717. *ppRasDevInfo = (LPRASDEVINFO)GlobalAlloc(GPTR,*lpdwRasDevInfoSize);
  718. if ( !(*ppRasDevInfo) )
  719. {
  720. hr = ERROR_NOT_ENOUGH_MEMORY;
  721. goto ICWGetRasEntryExit;
  722. }
  723. } else
  724. {
  725. *ppRasDevInfo = NULL;
  726. }
  727. // This is a bit convoluted: lpRasEntrySize->dwSize needs to contain the size of _only_ the
  728. // RASENTRY structure, and _not_ the actual size of the buffer that lpRasEntrySize points to.
  729. // This is because the dwSize field is used by RAS for compatability purposes to determine which
  730. // version of the RASENTRY struct we're using.
  731. // Same holds for lpRasDevInfo->dwSize
  732. (*ppRasEntry)->dwSize = sizeof(RASENTRY);
  733. if( *ppRasDevInfo )
  734. {
  735. (*ppRasDevInfo)->dwSize = sizeof(RASDEVINFO);
  736. }
  737. //now we're ready to make the actual call to RasGetEntryProperties!
  738. /*
  739. // Load RAS DLL and locate API
  740. //
  741. hRasDll = LoadLibrary(RASAPI_LIBRARY);
  742. if (!hRasDll)
  743. {
  744. hr = GetLastError();
  745. goto ICWGetRasEntryExit;
  746. }
  747. fp =GetProcAddress(hRasDll,RASAPI_RASGETENTRY);
  748. if (!fp)
  749. {
  750. FreeLibrary(hRasDll);
  751. hRasDll = LoadLibrary(RNAPH_LIBRARY);
  752. if (!hRasDll)
  753. {
  754. hr = GetLastError();
  755. goto ICWGetRasEntryExit;
  756. }
  757. fp = GetProcAddress(hRasDll,RASAPI_RASGETENTRY);
  758. if (!fp)
  759. {
  760. hr = GetLastError();
  761. goto ICWGetRasEntryExit;
  762. }
  763. }
  764. */
  765. // Get RasEntry
  766. //
  767. //hr = ((PFNRASGETENTRYPROPERTIES)fp)(NULL,pszEntryName,(LPBYTE)*ppRasEntry,&dwRasEntrySize,(LPBYTE)*ppDevInfo,&dwRasDevInfoSize);
  768. // jmazner see below for why this is needed
  769. dwOldDevInfoBuffSize = *lpdwRasDevInfoSize;
  770. hr = pcRNA->RasGetEntryProperties(NULL,pszEntryName,(LPBYTE)*ppRasEntry,lpdwRasEntrySize,(LPBYTE)*ppRasDevInfo,lpdwRasDevInfoSize);
  771. // jmazner 10/7/96 Normandy #8763
  772. // For unknown reasons, in some cases on win95, devInfoBuffSize increases after the above call,
  773. // but the return code indicates success, not BUFFER_TOO_SMALL. If this happens, set the
  774. // size back to what it was before the call, so the DevInfoBuffSize and the actuall space allocated
  775. // for the DevInfoBuff match on exit.
  776. if( (ERROR_SUCCESS == hr) && (dwOldDevInfoBuffSize != *lpdwRasDevInfoSize) )
  777. {
  778. *lpdwRasDevInfoSize = dwOldDevInfoBuffSize;
  779. }
  780. ICWGetRasEntryExit:
  781. if (hRasDll) FreeLibrary(hRasDll);
  782. hRasDll = NULL;
  783. if (pcRNA) delete pcRNA;
  784. pcRNA = NULL;
  785. return hr;
  786. }
  787. //+----------------------------------------------------------------------------
  788. //
  789. // Function: FCampusNetOverride
  790. //
  791. // Synopsis: Detect if the dial should be skipped for the campus network
  792. //
  793. // Arguments: None
  794. //
  795. // Returns: TRUE - overide enabled
  796. //
  797. // History: 8/15/96 ChrisK Created
  798. //
  799. //-----------------------------------------------------------------------------
  800. #if !defined(WIN16) && defined(DEBUG)
  801. BOOL FCampusNetOverride()
  802. {
  803. HKEY hkey = NULL;
  804. BOOL bRC = FALSE;
  805. DWORD dwType = 0;
  806. DWORD dwSize = 0;
  807. DWORD dwData = 0;
  808. if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE,
  809. TEXT("Software\\Microsoft\\ISignup\\Debug"),&hkey))
  810. goto FCampusNetOverrideExit;
  811. dwSize = sizeof(dwData);
  812. if (ERROR_SUCCESS != RegQueryValueEx(hkey,TEXT("CampusNet"),0,&dwType,
  813. (LPBYTE)&dwData,&dwSize))
  814. goto FCampusNetOverrideExit;
  815. AssertMsg(REG_DWORD == dwType,"Wrong value type for CampusNet. Must be DWORD.\r\n");
  816. bRC = (0 != dwData);
  817. if (bRC)
  818. MessageBox(NULL,TEXT("DEBUG ONLY: CampusNet will be used."),TEXT("Testing Override"),0);
  819. FCampusNetOverrideExit:
  820. if (hkey)
  821. RegCloseKey(hkey);
  822. return bRC;
  823. }
  824. #endif //!WIN16 && DEBUG