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.

1515 lines
42 KiB

  1. /*-----------------------------------------------------------------------------
  2. main.cpp
  3. Main entry and code for ICWCONN2
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved
  6. Authors:
  7. ChrisK Chris Kauffman
  8. VetriV Vellore Vetrivelkumaran
  9. Histroy:
  10. 7/22/96 ChrisK Cleaned and formatted
  11. 8/5/96 VetriV Added WIN16 code
  12. 4/29/98 donaldm removed WIN16 code
  13. -----------------------------------------------------------------------------*/
  14. #include "pch.hpp"
  15. #include "globals.h"
  16. #include "..\inc\semaphor.h"
  17. #define IEAPPPATHKEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE")
  18. DWORD CallCMConfig(LPCTSTR lpszINSFile, LPTSTR lpszConnectoidName);
  19. TCHAR pszINSFileName[MAX_PATH+2];
  20. TCHAR pszFinalConnectoid[MAX_PATH+1];
  21. HRASCONN hrasconn;
  22. TCHAR pszSetupClientURL[1024];
  23. UINT uiSetupClientNewPhoneCall;
  24. ShowProgressParams SPParams;
  25. RECT rect;
  26. HBRUSH hbBackBrush;
  27. BOOL fUserCanceled;
  28. TCHAR szBuff256[256];
  29. HANDLE hThread;
  30. DWORD dwThreadID;
  31. DWORD_PTR dwDownLoad;
  32. DWORD g_fNeedReboot;
  33. BOOL g_bProgressBarVisible;
  34. BOOL g_bINSFileExists;
  35. TCHAR szStrTable[irgMaxSzs][256];
  36. int iSzTable;
  37. extern HWND g_hDialDlgWnd;
  38. // The following two functions are for My[16|32]ShellExecute
  39. BOOL fStrNCmpI (LPTSTR lp1, LPTSTR lp2, UINT iNum)
  40. {
  41. UINT i;
  42. for (i = 0; (i < iNum) && (toupper(lp1[i]) == toupper(lp2[i])); i++) {}
  43. return (i == iNum);
  44. }
  45. //+----------------------------------------------------------------------------
  46. //
  47. // Function: IsURL
  48. //
  49. // Synopsis: Determines whether a string is URL
  50. //
  51. // Arguments: lpszCommand - the string to check
  52. //
  53. // Returns: TRUE - For our purposes, it's a URL
  54. // FALSE - Do not treat as a URL
  55. //
  56. // History: jmazner Created 10/23/96
  57. //
  58. //-----------------------------------------------------------------------------
  59. BOOL IsURL( LPTSTR lpszCommand )
  60. {
  61. return (fStrNCmpI(lpszCommand, TEXT("HTTP:"), 5) ||
  62. fStrNCmpI(lpszCommand, TEXT("HTTPS:"), 6) ||
  63. fStrNCmpI(lpszCommand, TEXT("FTP:"), 4) ||
  64. fStrNCmpI(lpszCommand, TEXT("GOPHER:"), 7) ||
  65. fStrNCmpI(lpszCommand, TEXT("FILE:"), 5));
  66. }
  67. int FindFirstWhiteSpace( LPTSTR szString ); //declared below
  68. //+----------------------------------------------------------------------------
  69. //
  70. // Function: My32ShellExecute
  71. //
  72. // Synopsis: ShellExecute a command in such a way that browsers other than
  73. // IE won't get called to handle URLs.
  74. //
  75. // If command is a URL, explicitly ShellExec IE on it,
  76. // if it's empty, shellExec IE with no parameters, and
  77. // if it's anything else, assume it's a command followed by a
  78. // parameter list, and shellExec that.
  79. //
  80. // Arguments: lpszCommand - the command to execute
  81. //
  82. // Returns: TRUE - For our purposes, it's a URL
  83. // FALSE - Do not treat as a URL
  84. //
  85. // History: 10/23/96 jmazner Created
  86. // 11/5/96 jmazner updated to use ShellExec in all cases,
  87. // to mimick behavior of start->run,
  88. // rather than dos box command line.
  89. // 4/30/97 jmazner updated to use IE AppPath reg key
  90. // (Olympus bug #200)
  91. //
  92. //-----------------------------------------------------------------------------
  93. void My32ShellExecute(LPTSTR lpszCommand)
  94. {
  95. HINSTANCE hInst = NULL;
  96. TCHAR * szParameter = NULL;
  97. TCHAR * pszIEAppPath = NULL;
  98. const TCHAR * cszGenericIE = TEXT("IEXPLORE.EXE");
  99. DWORD dwErr = ERROR_GEN_FAILURE;
  100. LONG lSize = 0;
  101. Assert( lpszCommand );
  102. dwErr = RegQueryValue(HKEY_LOCAL_MACHINE,IEAPPPATHKEY,NULL,&lSize);
  103. if ((ERROR_SUCCESS == dwErr || ERROR_MORE_DATA == dwErr) && (0 != lSize))
  104. {
  105. //
  106. // add 1 for null and 10 for slop
  107. //
  108. pszIEAppPath = (LPTSTR)LocalAlloc(LPTR,lSize+2+1+10);
  109. if( pszIEAppPath )
  110. {
  111. dwErr = RegQueryValue(HKEY_LOCAL_MACHINE,IEAPPPATHKEY,
  112. pszIEAppPath,&lSize);
  113. if( ERROR_SUCCESS != dwErr )
  114. {
  115. LocalFree( pszIEAppPath );
  116. pszIEAppPath = NULL;
  117. }
  118. else
  119. {
  120. Dprintf(TEXT("ICWCONN2: got IE Path of %s\n"), pszIEAppPath);
  121. }
  122. }
  123. }
  124. if( !pszIEAppPath )
  125. {
  126. pszIEAppPath = (TCHAR *) cszGenericIE;
  127. Dprintf(TEXT("ICWCONN2: Couldn't find IE appPath, using generic %s"), pszIEAppPath);
  128. }
  129. if( IsURL(lpszCommand) )
  130. {
  131. // If the command looks like a URL, explicitly call IE to open it
  132. // (don't want to rely on default browser)
  133. hInst = ShellExecute(NULL,TEXT("open"),pszIEAppPath,lpszCommand,NULL,SW_SHOWNORMAL);
  134. }
  135. else if( !lpszCommand[0] )
  136. {
  137. // If there is no command, just exec IE
  138. hInst = ShellExecute(NULL,TEXT("open"),pszIEAppPath,NULL,NULL,SW_SHOWNORMAL);
  139. }
  140. else
  141. {
  142. int i = FindFirstWhiteSpace( lpszCommand );
  143. if( 0 == i )
  144. {
  145. hInst = ShellExecute(NULL, TEXT("open"), lpszCommand, NULL, NULL, SW_SHOWNORMAL);
  146. }
  147. else
  148. {
  149. lpszCommand[i] = '\0';
  150. // now skip past all consecutive white space
  151. while( ' ' == lpszCommand[++i] );
  152. szParameter = lpszCommand + i;
  153. hInst = ShellExecute(NULL, TEXT("open"), lpszCommand, szParameter, NULL, SW_SHOWNORMAL);
  154. }
  155. }
  156. if (hInst < (HINSTANCE)32)
  157. {
  158. Dprintf(TEXT("ICWCONN2: Couldn't execute the command '%s %s'\n"),
  159. lpszCommand, szParameter ? szParameter : TEXT("\0"));
  160. MessageBox(NULL,GetSz(IDS_CANTEXECUTE),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  161. }
  162. }
  163. //+----------------------------------------------------------------------------
  164. //
  165. // Function: FindFirstWhiteSpace
  166. //
  167. // Synopsis: Return the index of the first whtie space character in the
  168. // string that's not enclosed in a double quote substring
  169. //
  170. // eg: "iexplore foo.htm" should return 8,
  171. // ""c:\program files\ie" foo.htm" should return 21
  172. //
  173. // Arguments: szString - the string to search through
  174. //
  175. // Returns: index of first qualifying white space.
  176. // if no qualifying character exists, returns 0
  177. //
  178. // History: 11/5/96 jmazner Created for Normandy #9867
  179. //
  180. //-----------------------------------------------------------------------------
  181. int FindFirstWhiteSpace( LPTSTR szString )
  182. {
  183. int i = 0;
  184. Assert( szString );
  185. if( '\"' == szString[0] )
  186. {
  187. // Don't look for spaces within a double quoted string
  188. // (example string "c:\Program Files\bob.exe" foo.bob)
  189. i++;
  190. while( '\"' != szString[i] )
  191. {
  192. if( NULL == szString[i] )
  193. {
  194. AssertSz(0, "ExploreNow command has unmatched quotes!\n");
  195. Dprintf(TEXT("ICWCONN2: FindFirstWhiteSpace discovered unmatched quote.\n"));
  196. return( 0 );
  197. }
  198. i++;
  199. }
  200. }
  201. while( ' ' != szString[i] )
  202. {
  203. if( NULL == szString[i] )
  204. //there is no white space to be found
  205. return 0;
  206. i++;
  207. }
  208. return( i );
  209. }
  210. //+---------------------------------------------------------------------------
  211. //
  212. // Function: WaitForConnectionTermination
  213. //
  214. // Synopsis: Waits for the given Ras Connection to complete termination
  215. //
  216. // Arguments: hConn - Connection handle of the RAS connection being terminated
  217. //
  218. // Returns: TRUE if wait till connection termination was successful
  219. // FALSE otherwise
  220. //
  221. // History: 6/30/96 VetriV Created
  222. // 8/19/96 ValdonB Moved from duplicate in icwconn1\dialdlg.cpp
  223. // 8/29/96 VetriV Added code to sleep for a second on WIN 3.1
  224. //----------------------------------------------------------------------------
  225. // Normandy #12547 Chrisk 12-18-96
  226. #define MAX_TIME_FOR_TERMINATION 5
  227. BOOL WaitForConnectionTermination(HRASCONN hConn)
  228. {
  229. RASCONNSTATUS RasConnStatus;
  230. DWORD dwRetCode;
  231. INT cnt = 0;
  232. //
  233. // Get Connection status for hConn in a loop until
  234. // RasGetConnectStatus returns ERROR_INVALID_HANDLE
  235. //
  236. do
  237. {
  238. //
  239. // Intialize RASCONNSTATUS struct
  240. // GetConnectStatus API will fail if dwSize is not set correctly!!
  241. //
  242. ZeroMemory(&RasConnStatus, sizeof(RASCONNSTATUS));
  243. RasConnStatus.dwSize = sizeof(RASCONNSTATUS);
  244. //
  245. // Sleep for a second and then get the connection status
  246. //
  247. Sleep(1000L);
  248. // Normandy #12547 Chrisk 12-18-96
  249. cnt++;
  250. dwRetCode = RasGetConnectStatus(hConn, &RasConnStatus);
  251. if (0 != dwRetCode)
  252. return FALSE;
  253. // Normandy #12547 Chrisk 12-18-96
  254. } while ((ERROR_INVALID_HANDLE != RasConnStatus.dwError) && (cnt < MAX_TIME_FOR_TERMINATION));
  255. return TRUE;
  256. }
  257. // ############################################################################
  258. // NAME: GetSz
  259. //
  260. // Load strings from resources
  261. //
  262. // Created 1/28/96, Chris Kauffman
  263. // ############################################################################
  264. LPTSTR GetSz(WORD wszID)
  265. {
  266. LPTSTR psz = &szStrTable[iSzTable][0];
  267. iSzTable++;
  268. if (iSzTable >= irgMaxSzs)
  269. iSzTable = 0;
  270. if (!LoadString(GetModuleHandle(NULL), wszID, psz, 256))
  271. {
  272. Dprintf(TEXT("CONNECT2:LoadString failed %d\n"), (DWORD) wszID);
  273. *psz = 0;
  274. }
  275. return (psz);
  276. }
  277. // ############################################################################
  278. HRESULT ReleaseBold(HWND hwnd)
  279. {
  280. HFONT hfont = NULL;
  281. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  282. if (hfont) DeleteObject(hfont);
  283. return ERROR_SUCCESS;
  284. }
  285. // ############################################################################
  286. HRESULT MakeBold (HWND hwnd, BOOL fSize, LONG lfWeight)
  287. {
  288. HRESULT hr = ERROR_SUCCESS;
  289. HFONT hfont = NULL;
  290. HFONT hnewfont = NULL;
  291. LOGFONT* plogfont = NULL;
  292. if (!hwnd) goto MakeBoldExit;
  293. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  294. if (!hfont)
  295. {
  296. hr = GetLastError();
  297. goto MakeBoldExit;
  298. }
  299. plogfont = (LOGFONT*)GlobalAlloc(GPTR,sizeof(LOGFONT));
  300. if (!plogfont)
  301. {
  302. hr = GetLastError();
  303. goto MakeBoldExit;
  304. }
  305. if (!GetObject(hfont,sizeof(LOGFONT),(LPVOID)plogfont))
  306. {
  307. hr = GetLastError();
  308. goto MakeBoldExit;
  309. }
  310. if (abs(plogfont->lfHeight) < 24 && fSize)
  311. {
  312. plogfont->lfHeight = plogfont->lfHeight + (plogfont->lfHeight / 4);
  313. }
  314. plogfont->lfWeight = (int)lfWeight;
  315. if (!(hnewfont = CreateFontIndirect(plogfont)))
  316. {
  317. hr = GetLastError();
  318. goto MakeBoldExit;
  319. }
  320. SendMessage(hwnd,WM_SETFONT,(WPARAM)hnewfont,MAKELPARAM(TRUE,0));
  321. MakeBoldExit:
  322. // if (hfont) DeleteObject(hfont);
  323. // BUG:? Do I need to delete hnewfont at some time?
  324. return hr;
  325. }
  326. // ############################################################################
  327. extern "C" INT_PTR CALLBACK FAR PASCAL DoneDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  328. {
  329. BOOL bRet = TRUE;
  330. switch(uMsg)
  331. {
  332. case WM_COMMAND:
  333. switch(LOWORD(wParam))
  334. {
  335. case IDC_CMDCLOSE:
  336. case IDC_CMDEXPLORE:
  337. EndDialog(hwnd,LOWORD(wParam));
  338. break;
  339. }
  340. break;
  341. case WM_INITDIALOG:
  342. MakeBold(GetDlgItem(hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  343. GetPrivateProfileString(
  344. INSFILE_APPNAME,INFFILE_DONE_MESSAGE,
  345. NULLSZ,szBuff256,255,pszINSFileName);
  346. SetDlgItemText(hwnd,IDC_LBLEXPLORE,szBuff256);
  347. break;
  348. case WM_DESTROY:
  349. ReleaseBold(GetDlgItem(hwnd,IDC_LBLTITLE));
  350. bRet = FALSE;
  351. break;
  352. case WM_CLOSE:
  353. EndDialog(hwnd,IDC_CMDCLOSE);
  354. break;
  355. default:
  356. bRet = FALSE;
  357. break;
  358. }
  359. return bRet;
  360. }
  361. // ############################################################################
  362. extern "C" INT_PTR CALLBACK FAR PASCAL DoneRebootDlgProc(HWND hwnd,UINT uMsg,
  363. WPARAM wParam,
  364. LPARAM lParam)
  365. {
  366. BOOL bRet = TRUE;
  367. switch(uMsg)
  368. {
  369. case WM_COMMAND:
  370. switch(LOWORD(wParam))
  371. {
  372. case WM_CLOSE:
  373. case IDC_CMDEXPLORE:
  374. EndDialog(hwnd,LOWORD(wParam));
  375. break;
  376. }
  377. break;
  378. case WM_INITDIALOG:
  379. MakeBold(GetDlgItem(hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  380. GetPrivateProfileString(
  381. INSFILE_APPNAME,INFFILE_DONE_MESSAGE,
  382. NULLSZ,szBuff256,255,pszINSFileName);
  383. SetDlgItemText(hwnd,IDC_LBLEXPLORE,szBuff256);
  384. break;
  385. case WM_DESTROY:
  386. ReleaseBold(GetDlgItem(hwnd,IDC_LBLTITLE));
  387. bRet = FALSE;
  388. break;
  389. default:
  390. bRet = FALSE;
  391. break;
  392. }
  393. return bRet;
  394. }
  395. // ############################################################################
  396. extern "C" BOOL CALLBACK FAR PASCAL StepTwoDlgProc(HWND hwnd,UINT uMsg,
  397. WPARAM wParam,
  398. LPARAM lParam)
  399. {
  400. BOOL bRet = TRUE;
  401. switch(uMsg)
  402. {
  403. default:
  404. bRet = FALSE;
  405. break;
  406. case WM_COMMAND:
  407. switch(LOWORD(wParam))
  408. {
  409. case IDC_CMDNEXT:
  410. EndDialog(hwnd,IDC_CMDNEXT);
  411. break;
  412. case IDC_CMDCANCEL:
  413. EndDialog(hwnd,IDC_CMDCANCEL);
  414. break;
  415. }
  416. break;
  417. case WM_INITDIALOG:
  418. MakeBold(GetDlgItem(hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  419. break;
  420. case WM_DESTROY:
  421. ReleaseBold(GetDlgItem(hwnd,IDC_LBLTITLE));
  422. bRet = FALSE;
  423. break;
  424. }
  425. return bRet;
  426. }
  427. /*
  428. // ############################################################################
  429. BOOL CALLBACK ContextDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  430. {
  431. LRESULT lRet = TRUE;
  432. switch(uMsg)
  433. {
  434. case WM_INITDIALOG:
  435. MakeBold (GetDlgItem(hwnd, IDC_LBLARROW3NUM), FALSE, FW_BOLD);
  436. MakeBold (GetDlgItem(hwnd, IDC_LBLARROW3TEXT), FALSE, FW_BOLD);
  437. break;
  438. case WM_COMMAND:
  439. switch(LOWORD(wParam))
  440. {
  441. case IDC_CMDHELP:
  442. WinHelp(hwnd,TEXT("connect.hlp>proc4"),HELP_CONTEXT,(DWORD)idh_icwoverview);
  443. break;
  444. }
  445. break;
  446. case WM_QUIT:
  447. PostQuitMessage(0);
  448. break;
  449. default:
  450. lRet = FALSE;
  451. break;
  452. }
  453. return lRet;
  454. }
  455. */
  456. /*
  457. // ############################################################################
  458. BOOL CALLBACK BackDlgProc(
  459. HWND hwndDlg, // handle to dialog box
  460. UINT uMsg, // message
  461. WPARAM wParam, // first message parameter
  462. LPARAM lParam // second message parameter
  463. )
  464. {
  465. HDC hdc;
  466. LRESULT lRet = TRUE;
  467. switch (uMsg)
  468. {
  469. case WM_INITDIALOG:
  470. // SET WINDOW TEXT HERE
  471. hbBackBrush = (HBRUSH)(COLOR_BACKGROUND + 1);
  472. break;
  473. case WM_SIZE:
  474. GetClientRect(hwndDlg,&rect);
  475. lRet = FALSE; // enable default processing
  476. break;
  477. case WM_CLOSE:
  478. //PostQuitMessage(0);
  479. //EndDialog(hwndDlg,FALSE);
  480. break;
  481. case WM_PAINT:
  482. hdc = GetDC(hwndDlg);
  483. FillRect(hdc,&rect,hbBackBrush);
  484. ReleaseDC(hwndDlg,hdc);
  485. lRet = 0;
  486. break;
  487. default:
  488. // let the system process the message
  489. lRet = FALSE;
  490. }
  491. return lRet;
  492. }
  493. */
  494. // ############################################################################
  495. void CALLBACK ProgressCallBack(
  496. HINTERNET hInternet,
  497. DWORD_PTR dwContext,
  498. DWORD dwInternetStatus,
  499. LPVOID lpvStatusInformation,
  500. DWORD dwStatusInformationLength
  501. )
  502. {
  503. LPTSTR pszStatus = NULL;
  504. int prc;
  505. static BOOL bMessageSet = FALSE;
  506. switch(dwInternetStatus)
  507. {
  508. case 99:
  509. prc = *(int*)lpvStatusInformation;
  510. if (!g_bProgressBarVisible)
  511. {
  512. ShowWindow(GetDlgItem(SPParams.hwnd,IDC_PROGRESS),SW_SHOW);
  513. g_bProgressBarVisible = TRUE;
  514. }
  515. SendDlgItemMessage(SPParams.hwnd,
  516. IDC_PROGRESS,
  517. PBM_SETPOS,
  518. (WPARAM)prc,
  519. 0);
  520. if (!bMessageSet)
  521. {
  522. bMessageSet = TRUE;
  523. pszStatus = GetSz(IDS_RECEIVING_RESPONSE);
  524. }
  525. break;
  526. }
  527. if (pszStatus)
  528. SetDlgItemText(SPParams.hwnd,IDC_LBLSTATUS,pszStatus);
  529. }
  530. // ############################################################################
  531. DWORD WINAPI ThreadInit()
  532. {
  533. HINSTANCE hDLDLL;
  534. HINSTANCE hADDll = NULL;
  535. FARPROC fp;
  536. HRESULT hr;
  537. hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  538. if (!hDLDLL)
  539. {
  540. hr = GetLastError();
  541. goto ThreadInitExit;
  542. }
  543. // Set up for download
  544. //
  545. fp = GetProcAddress(hDLDLL,DOWNLOADINIT);
  546. AssertSz(fp,"DownLoadInit API missing");
  547. dwDownLoad = 0;
  548. hr = ((PFNDOWNLOADINIT)fp)(pszSetupClientURL, &dwDownLoad, g_hDialDlgWnd);
  549. if (hr != ERROR_SUCCESS) goto ThreadInitExit;
  550. // Set up progress call back
  551. //
  552. fp = GetProcAddress(hDLDLL,DOWNLOADSETSTATUS);
  553. Assert(fp);
  554. hr = ((PFNDOWNLOADSETSTATUS)fp)(dwDownLoad, &ProgressCallBack);
  555. // Download stuff
  556. //
  557. fp = GetProcAddress(hDLDLL,DOWNLOADEXECUTE);
  558. Assert(fp);
  559. hr = ((PFNDOWNLOADEXECUTE)fp)(dwDownLoad);
  560. // if there is an error, we still have to take down the window and
  561. // release the WinInet Internet handle.
  562. if (hr == ERROR_SUCCESS)
  563. {
  564. fp = GetProcAddress(hDLDLL,DOWNLOADPROCESS);
  565. Assert(fp);
  566. hr = ((PFNDOWNLOADPROCESS)fp)(dwDownLoad);
  567. }
  568. fp = GetProcAddress(hDLDLL,DOWNLOADCLOSE);
  569. Assert(fp);
  570. ((PFNDOWNLOADCLOSE)fp)(dwDownLoad);
  571. dwDownLoad = 0;
  572. ThreadInitExit:
  573. PostMessage(SPParams.hwnd,WM_DOWNLOAD_DONE,0,0);
  574. if (hDLDLL) FreeLibrary(hDLDLL);
  575. if (hADDll) FreeLibrary(hADDll);
  576. return hr;
  577. }
  578. HRESULT HangUpAll()
  579. {
  580. LPRASCONN lprasconn;
  581. DWORD cb;
  582. DWORD cConnections;
  583. DWORD idx;
  584. HRESULT hr;
  585. hr = ERROR_NOT_ENOUGH_MEMORY;
  586. lprasconn = (LPRASCONN)GlobalAlloc(GPTR,sizeof(RASCONN));
  587. if (!lprasconn) goto SkipHangUp;
  588. cb = sizeof(RASCONN);
  589. cConnections = 0;
  590. lprasconn->dwSize = cb;
  591. //if(RasEnumConnections(lprasconn,&cb,&cConnections))
  592. {
  593. GlobalFree(lprasconn);
  594. lprasconn = (LPRASCONN)GlobalAlloc(GPTR,(size_t)cb);
  595. if (!lprasconn) goto SkipHangUp;
  596. lprasconn->dwSize = cb;
  597. RasEnumConnections(lprasconn,&cb,&cConnections);
  598. }
  599. if (cConnections)
  600. {
  601. for (idx = 0; idx<cConnections; idx++)
  602. {
  603. RasHangUp(lprasconn[idx].hrasconn);
  604. WaitForConnectionTermination(lprasconn[idx].hrasconn);
  605. }
  606. }
  607. if (lprasconn) GlobalFree(lprasconn);
  608. hr = ERROR_SUCCESS;
  609. SkipHangUp:
  610. return hr;
  611. }
  612. // ############################################################################
  613. BOOL FShouldRetry(HRESULT hrErr)
  614. {
  615. BOOL bRC;
  616. if (hrErr == ERROR_LINE_BUSY ||
  617. hrErr == ERROR_VOICE_ANSWER ||
  618. hrErr == ERROR_NO_ANSWER ||
  619. hrErr == ERROR_NO_CARRIER ||
  620. hrErr == ERROR_AUTHENTICATION_FAILURE ||
  621. hrErr == ERROR_PPP_TIMEOUT ||
  622. hrErr == ERROR_REMOTE_DISCONNECTION ||
  623. hrErr == ERROR_AUTH_INTERNAL ||
  624. hrErr == ERROR_PROTOCOL_NOT_CONFIGURED ||
  625. hrErr == ERROR_PPP_NO_PROTOCOLS_CONFIGURED)
  626. {
  627. bRC = TRUE;
  628. } else {
  629. bRC = FALSE;
  630. }
  631. return bRC;
  632. }
  633. // ############################################################################
  634. HRESULT CallDownLoad(LPTSTR pszUrl, HINSTANCE hInst)
  635. {
  636. FARPROC fp = NULL;
  637. HRESULT hr = ERROR_SUCCESS;
  638. HKEY hKey = NULL;
  639. DWORD dwType=0;
  640. DWORD dwSize=0;
  641. GATHEREDINFO gi;
  642. LPTSTR pszConnectoid=NULL;
  643. BOOL fEnabled;
  644. HINSTANCE hInet = NULL;
  645. INT cRetry;
  646. TCHAR szCallHomeMsg[CALLHOME_SIZE];
  647. DWORD dwCMRet = NULL;
  648. // 11/25/96 jmazner Normandy #12109
  649. // load in connectoid name before we get to ShowExploreNow
  650. //// BUG: If isignup keep creating unique filenames, this will only
  651. //// find the first connectoid created for this ISP.
  652. ////
  653. //
  654. pszConnectoid = (LPTSTR)GlobalAlloc(GPTR,RAS_MaxEntryName + 1);
  655. if (!pszConnectoid)
  656. {
  657. hr = ERROR_NOT_ENOUGH_MEMORY;
  658. goto CallDownLoadExit;
  659. }
  660. hInet = LoadLibrary(TEXT("INETCFG.DLL"));
  661. if (!hInet)
  662. {
  663. AssertSz(0,"Failed to load inetcfg.dll.\r\n");
  664. hr = GetLastError();
  665. goto CallDownLoadExit;
  666. }
  667. fp = GetProcAddress(hInet,"InetGetAutodial");
  668. if (!fp)
  669. {
  670. AssertSz(0,"Failed to load InetGetAutodial.\r\n");
  671. hr = GetLastError();
  672. goto CallDownLoadExit;
  673. }
  674. //
  675. // Get name of autodial connectoid
  676. //
  677. fEnabled = FALSE;
  678. hr = ((PFNINETGETAUTODIAL)fp)(&fEnabled,pszConnectoid,RAS_MaxEntryName);
  679. if ( hr != ERROR_SUCCESS)
  680. goto CallDownLoadExit;
  681. if (hInet) FreeLibrary(hInet);
  682. hInet = NULL;
  683. fp = NULL;
  684. Dprintf(TEXT("CONNECT2: call back using the '%s' connectoid.\n"),pszConnectoid);
  685. if (pszUrl[0] == '\0')
  686. {
  687. Dprintf(TEXT("CONNECT2: Client setup URL in .ins file is empty.\n"));
  688. goto ShowExploreNow;
  689. }
  690. SPParams.hwnd = NULL;
  691. SPParams.hwndParent = NULL;
  692. SPParams.hinst = hInst;
  693. //
  694. hr = RegOpenKey(HKEY_LOCAL_MACHINE,SIGNUPKEY,&hKey);
  695. if (hr == ERROR_SUCCESS)
  696. {
  697. dwType = REG_BINARY;
  698. dwSize = sizeof(gi);
  699. ZeroMemory(&gi,sizeof(gi));
  700. hr = RegQueryValueEx(hKey,GATHERINFOVALUENAME,0,&dwType,(LPBYTE)&gi,&dwSize);
  701. RegCloseKey(hKey);
  702. hKey = NULL;
  703. } else {
  704. goto CallDownLoadExit;
  705. }
  706. ZeroMemory(szCallHomeMsg,CALLHOME_SIZE);
  707. GetPrivateProfileString(
  708. INSFILE_APPNAME,INFFILE_ISPSUPP,
  709. NULLSZ,szCallHomeMsg,CALLHOME_SIZE,pszINSFileName);
  710. TryDial:
  711. cRetry = 0;
  712. TryRedial:
  713. //
  714. // ChrisK 8/20/97
  715. // Pass .ins file to dialer so that the dialer can find the password
  716. //
  717. hr = ShowDialingDialog(pszConnectoid, &gi, pszUrl, hInst, NULL, pszINSFileName);
  718. cRetry++;
  719. if ((cRetry < MAX_RETIES) && FShouldRetry(hr))
  720. goto TryRedial;
  721. if (hr != ERROR_USERNEXT)
  722. {
  723. if (!uiSetupClientNewPhoneCall)
  724. {
  725. hr = ShowDialReallyCancelDialog(hInst, NULL, szCallHomeMsg);
  726. if (hr == ERROR_USERNEXT)
  727. goto TryDial;
  728. else if (hr == ERROR_USERCANCEL)
  729. goto CallDownLoadExit;
  730. } else {
  731. if (RASBASE > hr || RASBASEEND < hr)
  732. hr = ERROR_DOWNLOADDIDNT;
  733. hr = ShowDialErrDialog(&gi, hr, pszConnectoid, hInst, NULL);
  734. if (hr == ERROR_USERNEXT)
  735. goto TryDial;
  736. else
  737. {
  738. hr = ShowDialReallyCancelDialog(hInst, NULL, szCallHomeMsg);
  739. if (hr == ERROR_USERNEXT)
  740. goto TryDial;
  741. else if (hr == ERROR_USERCANCEL)
  742. goto CallDownLoadExit;
  743. }
  744. }
  745. }
  746. //
  747. // Determine if we should hang up
  748. //
  749. ShowExploreNow:
  750. if (0 == uiSetupClientNewPhoneCall)
  751. {
  752. HangUpAll();
  753. }
  754. //
  755. // 1/8/96 jmazner Normanmdy #12930
  756. // function moved to isign32.dll
  757. //
  758. //
  759. // 5/9/97 jmazner Olympus #416
  760. //
  761. dwCMRet = CallCMConfig(pszINSFileName, pszConnectoid);
  762. switch( dwCMRet )
  763. {
  764. case ERROR_SUCCESS:
  765. break;
  766. case ERROR_MOD_NOT_FOUND:
  767. case ERROR_DLL_NOT_FOUND:
  768. Dprintf(TEXT("ICWCONN2: CMCFG32 DLL not found, I guess CM ain't installed.\n"));
  769. break;
  770. default:
  771. //ErrorMsg(hwnd, IDS_SBSCFGERROR);
  772. break;
  773. }
  774. if (g_fNeedReboot){
  775. int iReturnCode = 0;
  776. iReturnCode = (int)DialogBox(hInst,MAKEINTRESOURCE(IDD_DONEREBOOT),
  777. NULL,DoneRebootDlgProc);
  778. switch(iReturnCode)
  779. {
  780. case IDC_CMDEXPLORE:
  781. ExitWindowsEx(EWX_REBOOT,0);
  782. break;
  783. case IDC_CMDCLOSE:
  784. HangUpAll();
  785. break;
  786. }
  787. } else {
  788. int iReturnCode = 0;
  789. iReturnCode = (int)DialogBox(hInst,MAKEINTRESOURCE(IDD_DONE),
  790. NULL,DoneDlgProc);
  791. switch(iReturnCode)
  792. {
  793. case IDC_CMDEXPLORE:
  794. GetPrivateProfileString(
  795. INSFILE_APPNAME,INFFILE_EXPLORE_CMD,
  796. NULLSZ,szBuff256,255,pszINSFileName);
  797. My32ShellExecute(szBuff256);
  798. break;
  799. case IDC_CMDCLOSE:
  800. HangUpAll();
  801. break;
  802. }
  803. }
  804. CallDownLoadExit:
  805. if (pszConnectoid)
  806. GlobalFree(pszConnectoid);
  807. pszConnectoid = NULL;
  808. return hr;
  809. }
  810. // ############################################################################
  811. HRESULT FindCurrentConn ()
  812. {
  813. LPRASCONN lprasconn = NULL;
  814. DWORD cb = sizeof(RASCONN);
  815. DWORD cConnections = 0;
  816. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  817. unsigned int idx;
  818. lprasconn = (LPRASCONN)GlobalAlloc(GPTR,sizeof(RASCONN));
  819. if (!lprasconn) goto FindCurrentConnExit;
  820. lprasconn[0].dwSize = sizeof(RASCONN);
  821. if(RasEnumConnections(lprasconn,&cb,&cConnections))
  822. {
  823. GlobalFree(lprasconn);
  824. lprasconn = (LPRASCONN)GlobalAlloc(GPTR,(size_t)cb);
  825. if (!lprasconn) goto FindCurrentConnExit;
  826. RasEnumConnections(lprasconn,&cb,&cConnections);
  827. }
  828. if (pszFinalConnectoid[0] != '\0')
  829. {
  830. if (cConnections)
  831. {
  832. for (idx = 0; idx<cConnections; idx++)
  833. {
  834. if (lstrcmpi(lprasconn[idx].szEntryName,pszFinalConnectoid)==0)
  835. {
  836. hrasconn = lprasconn[idx].hrasconn;
  837. break;
  838. }
  839. }
  840. if (!hrasconn) goto FindCurrentConnExit;
  841. }
  842. } else {
  843. // if they don't tell us the connectoid on the command line
  844. // we assume there is only one and the first one is the one we are going to use!!
  845. if (cConnections)
  846. {
  847. lstrcpyn(pszFinalConnectoid,lprasconn[0].szEntryName,sizeof(pszFinalConnectoid)/sizeof(TCHAR));
  848. hrasconn = lprasconn[0].hrasconn;
  849. }
  850. }
  851. hr = ERROR_SUCCESS;
  852. FindCurrentConnExit:
  853. if (lprasconn) GlobalFree(lprasconn);
  854. return hr;
  855. }
  856. // ############################################################################
  857. HRESULT CopyCmdLineData (LPTSTR pszCmdLine, LPTSTR pszField, LPTSTR pszOut)
  858. {
  859. HRESULT hr = ERROR_SUCCESS;
  860. TCHAR *s;
  861. TCHAR *t;
  862. BOOL fQuote = FALSE;
  863. s = _tcsstr(pszCmdLine,pszField);
  864. if (s)
  865. {
  866. s += lstrlen(pszField);
  867. t = pszOut;
  868. *t = '\0';
  869. if (fQuote =(*s == '"'))
  870. s++;
  871. while (*s &&
  872. ((*s != ' ' && !fQuote)
  873. || (*s != '"' && fQuote ))) // copy until the end of the string or a space char
  874. {
  875. *t = *s;
  876. t++;
  877. s++;
  878. }
  879. *t = '\0'; // add null terminator
  880. }
  881. else
  882. {
  883. hr = ERROR_INVALID_PARAMETER;
  884. }
  885. return hr;
  886. }
  887. // ############################################################################
  888. HRESULT ParseCommandLine(LPTSTR pszCmdLine)
  889. {
  890. HRESULT hr;
  891. // jmazner 10/15/96 make parsing of cmd line options case insensitive
  892. CharUpper( pszCmdLine );
  893. g_fNeedReboot = (_tcsstr(pszCmdLine, CMD_REBOOT) != NULL);
  894. hr = CopyCmdLineData (pszCmdLine, CMD_CONNECTOID, &pszFinalConnectoid[0]);
  895. if (hr != ERROR_SUCCESS) pszFinalConnectoid[0] = '\0';
  896. hr = CopyCmdLineData (pszCmdLine, CMD_INS, &pszINSFileName[0]);
  897. //ParseCommandLineExit:
  898. return hr;
  899. }
  900. // ############################################################################
  901. HRESULT DeleteIRN()
  902. {
  903. HRESULT hr = ERROR_SUCCESS;
  904. HKEY hKey;
  905. DWORD dwType;
  906. DWORD dwSize;
  907. TCHAR szRasEntry[MAX_RASENTRYNAME+1];
  908. RNAAPI *pRnaapi = NULL;
  909. pRnaapi = new RNAAPI;
  910. if(!pRnaapi)
  911. {
  912. return ERROR_NOT_ENOUGH_MEMORY;
  913. }
  914. dwSize = sizeof(szRasEntry);
  915. dwType = REG_SZ;
  916. hKey = NULL;
  917. hr = RegOpenKey(HKEY_LOCAL_MACHINE,SIGNUPKEY,&hKey);
  918. ZeroMemory(szRasEntry,sizeof(szRasEntry));
  919. if (hr == ERROR_SUCCESS)
  920. {
  921. hr = RegQueryValueEx(hKey,RASENTRYVALUENAME,NULL,&dwType,(LPBYTE)szRasEntry,&dwSize);
  922. //if (hr == ERROR_SUCCESS && fp)
  923. if (hr == ERROR_SUCCESS)
  924. pRnaapi->RasDeleteEntry(NULL, szRasEntry);
  925. }
  926. if (hKey) RegCloseKey(hKey);
  927. //if (hDLL) FreeLibrary(hDLL);
  928. if (pRnaapi)
  929. {
  930. delete pRnaapi;
  931. pRnaapi = NULL;
  932. }
  933. hKey = NULL;
  934. return hr;
  935. }
  936. // ############################################################################
  937. int WINAPI WinMain(
  938. HINSTANCE hInstance, // handle to current instance
  939. HINSTANCE hPrevInstance, // handle to previous instance
  940. LPSTR lpCmdLine, // pointer to command line
  941. int nShowCmd // show state of window
  942. )
  943. {
  944. int irc = 1;
  945. BOOL fHangUp = TRUE;
  946. HKEY hkey = NULL;
  947. RNAAPI *pRnaapi = NULL;
  948. #ifdef UNICODE
  949. // Initialize the C runtime locale to the system locale.
  950. setlocale(LC_ALL, "");
  951. #endif
  952. // Initialize globals
  953. //
  954. ZeroMemory(pszINSFileName,MAX_PATH+1);
  955. ZeroMemory(pszFinalConnectoid,MAX_PATH+1);
  956. ZeroMemory(pszSetupClientURL,1024);
  957. // 12/3/96 jmazner Normandy #12140, 12088
  958. // create a semaphore to signal other icw components that we're running
  959. // Since conn2 is not single instance (see semaphor.h), we don't care if
  960. // the semaphore already exists.
  961. HANDLE hSemaphore = NULL;
  962. hSemaphore = CreateSemaphore(NULL, 1, 1, ICW_ELSE_SEMAPHORE);
  963. hrasconn = NULL;
  964. uiSetupClientNewPhoneCall = FALSE;
  965. fUserCanceled = FALSE;
  966. dwDownLoad = 0;
  967. g_bProgressBarVisible =FALSE;
  968. //
  969. // Delete referal service connectoid
  970. //
  971. DeleteIRN();
  972. //
  973. // Parse command line
  974. //
  975. if (ParseCommandLine(GetCommandLine()) != ERROR_SUCCESS)
  976. {
  977. irc = 2;
  978. Dprintf(TEXT("ICWCONN2: Malformed cmd line '%s'\n"), lpCmdLine);
  979. AssertSz(0,"Command Line parsing failed\r\n.");
  980. //CHAR szTemp[2048] = "not initialized\0";
  981. //wsprintf(szTemp, GetSz(IDS_BAD_CMDLINE), lpCmdLine);
  982. MessageBox(NULL,GetSz(IDS_BAD_CMDLINE),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  983. goto WinMainExit;
  984. }
  985. g_bINSFileExists = TRUE;
  986. if( !FileExists(pszINSFileName) )
  987. {
  988. g_bINSFileExists = FALSE;
  989. irc = 2;
  990. TCHAR *pszTempBuff = NULL;
  991. TCHAR *pszErrString = NULL;
  992. DWORD dwBuffSize = 0;
  993. pszErrString = GetSz(IDS_MISSING_FILE);
  994. // If we can't access a resource string, we may as well just give up and quit silently
  995. if( !pszErrString ) goto WinMainExit;
  996. dwBuffSize = MAX_PATH + lstrlen( pszErrString ) + 3; //two quotes and terminating null
  997. pszTempBuff = (TCHAR *)GlobalAlloc( GPTR, dwBuffSize );
  998. if( !pszTempBuff )
  999. {
  1000. MessageBox(NULL,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  1001. goto WinMainExit;
  1002. }
  1003. wsprintf(pszTempBuff, pszErrString);
  1004. lstrcat(pszTempBuff, TEXT("\""));
  1005. lstrcat(pszTempBuff, pszINSFileName);
  1006. lstrcat(pszTempBuff, TEXT("\""));
  1007. MessageBox(NULL,pszTempBuff,GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  1008. GlobalFree(pszTempBuff);
  1009. pszTempBuff = NULL;
  1010. goto WinMainExit;
  1011. }
  1012. //
  1013. // Find the handle to the current connection
  1014. //
  1015. if (FindCurrentConn() != ERROR_SUCCESS)
  1016. {
  1017. irc = 2;
  1018. AssertSz(0,"Finding current connection failed\r\n.");
  1019. goto WinMainExit;
  1020. }
  1021. //
  1022. // Get SetUp Client URL
  1023. //
  1024. GetPrivateProfileString(
  1025. INSFILE_APPNAME,INFFILE_SETUP_CLIENT_URL,
  1026. NULLSZ,pszSetupClientURL,1024,pszINSFileName);
  1027. //if (pszSetupClientURL[0])
  1028. //{
  1029. uiSetupClientNewPhoneCall = GetPrivateProfileInt(
  1030. INSFILE_APPNAME,INFFILE_SETUP_NEW_CALL,0,pszINSFileName);
  1031. if (uiSetupClientNewPhoneCall == 1 && hrasconn)
  1032. {
  1033. RasHangUp(hrasconn);
  1034. WaitForConnectionTermination(hrasconn);
  1035. pRnaapi = new RNAAPI;
  1036. if(!pRnaapi)
  1037. {
  1038. MessageBox(NULL,GetSz(IDS_OUTOFMEMORY),GetSz(IDS_TITLE),MB_APPLMODAL | MB_ICONERROR);
  1039. goto WinMainExit;
  1040. }
  1041. pRnaapi->RasDeleteEntry(NULL,pszFinalConnectoid);
  1042. pszFinalConnectoid[0] = '\0';
  1043. hrasconn = NULL;
  1044. }
  1045. CallDownLoad(&pszSetupClientURL[0],hInstance);
  1046. //}
  1047. //else
  1048. //{
  1049. // if (hrasconn)
  1050. // {
  1051. // RasHangUp(hrasconn);
  1052. // Sleep(3000);
  1053. // }
  1054. //}
  1055. WinMainExit:
  1056. hkey = NULL;
  1057. if ((RegOpenKey(HKEY_LOCAL_MACHINE,SIGNUPKEY,&hkey)) == ERROR_SUCCESS)
  1058. {
  1059. RegDeleteValue(hkey,GATHERINFOVALUENAME);
  1060. RegCloseKey(hkey);
  1061. }
  1062. if (g_bINSFileExists && pszINSFileName)
  1063. {
  1064. if (pszINSFileName[0] != '\0')
  1065. {
  1066. DeleteFileKindaLikeThisOne(pszINSFileName);
  1067. }
  1068. }
  1069. Dprintf(TEXT("CONNECT2:Quitting WinMain.\n"));
  1070. if (hrasconn)
  1071. {
  1072. RasHangUp(hrasconn);
  1073. if (pszFinalConnectoid[0])
  1074. {
  1075. if(!pRnaapi)
  1076. {
  1077. pRnaapi = new RNAAPI;
  1078. if(!pRnaapi)
  1079. {
  1080. // no point in notifying user with message, we're quitting anyways
  1081. Dprintf(TEXT("ICWCONN2: couldn't allocate pRnaapi memory in WinMainExit\n"));
  1082. }
  1083. else
  1084. {
  1085. pRnaapi->RasDeleteEntry(NULL,pszFinalConnectoid);
  1086. }
  1087. }
  1088. }
  1089. pszFinalConnectoid[0] = '\0';
  1090. WaitForConnectionTermination(hrasconn);
  1091. hrasconn = NULL;
  1092. }
  1093. if (g_pdevice) GlobalFree(g_pdevice);
  1094. ExitProcess(0);
  1095. if (pRnaapi)
  1096. {
  1097. delete pRnaapi;
  1098. pRnaapi = NULL;
  1099. }
  1100. if( hSemaphore )
  1101. CloseHandle( hSemaphore );
  1102. return irc;
  1103. }
  1104. static const TCHAR cszBrandingSection[] = TEXT("Branding");
  1105. static const TCHAR cszBrandingServerless[] = TEXT("Serverless");
  1106. // ############################################################################
  1107. // This function serve the single function of cleaning up after IE3.0, because
  1108. // IE3.0 will issue multiple POST and get back multiple .INS files. These files
  1109. // contain sensative data that we don't want lying arround, so we are going out,
  1110. // guessing what their names are, and deleting them.
  1111. HRESULT DeleteFileKindaLikeThisOne(LPTSTR lpszFileName)
  1112. {
  1113. LPTSTR lpNext = NULL;
  1114. HRESULT hr = ERROR_SUCCESS;
  1115. WORD wRes = 0;
  1116. HANDLE hFind = NULL;
  1117. WIN32_FIND_DATA sFoundFile;
  1118. TCHAR szPath[MAX_PATH];
  1119. TCHAR szSearchPath[MAX_PATH + 1];
  1120. LPTSTR lpszFilePart = NULL;
  1121. // Validate parameter
  1122. //
  1123. if (!lpszFileName || lstrlen(lpszFileName) <= 4)
  1124. {
  1125. hr = ERROR_INVALID_PARAMETER;
  1126. goto DeleteFileKindaLikeThisOneExit;
  1127. }
  1128. // Check for serverless signup
  1129. if (0 != GetPrivateProfileInt(cszBrandingSection,cszBrandingServerless,0,lpszFileName))
  1130. goto DeleteFileKindaLikeThisOneExit;
  1131. // Determine the directory name where the INS files are located
  1132. //
  1133. ZeroMemory(szPath,MAX_PATH);
  1134. if (GetFullPathName(lpszFileName,MAX_PATH,szPath,&lpszFilePart))
  1135. {
  1136. *lpszFilePart = '\0';
  1137. } else {
  1138. hr = GetLastError();
  1139. goto DeleteFileKindaLikeThisOneExit;
  1140. };
  1141. // Munge filename into search parameters
  1142. //
  1143. lpNext = &lpszFileName[lstrlen(lpszFileName)-4];
  1144. if (CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE,lpNext,4,TEXT(".INS"),4) != 2) goto DeleteFileKindaLikeThisOneExit;
  1145. ZeroMemory(szSearchPath,MAX_PATH + 1);
  1146. lstrcpyn(szSearchPath,szPath,MAX_PATH);
  1147. lstrcat(szSearchPath,TEXT("*.INS"));
  1148. // Start wiping out files
  1149. //
  1150. ZeroMemory(&sFoundFile,sizeof(sFoundFile));
  1151. hFind = FindFirstFile(szSearchPath,&sFoundFile);
  1152. if (hFind)
  1153. {
  1154. do {
  1155. lstrcpy(lpszFilePart,sFoundFile.cFileName);
  1156. SetFileAttributes(szPath,FILE_ATTRIBUTE_NORMAL);
  1157. DeleteFile(szPath);
  1158. ZeroMemory(&sFoundFile,sizeof(sFoundFile));
  1159. } while (FindNextFile(hFind,&sFoundFile));
  1160. FindClose(hFind);
  1161. }
  1162. hFind = NULL;
  1163. DeleteFileKindaLikeThisOneExit:
  1164. return hr;
  1165. }
  1166. //+----------------------------------------------------------------------------
  1167. //
  1168. // Function: StrDup
  1169. //
  1170. // Synopsis: Duplicate given string
  1171. //
  1172. // Arguments: ppszDest - pointer to pointer that will point to string
  1173. // pszSource - pointer to the string to be copied
  1174. //
  1175. // Returns: NULL - failure
  1176. // Pointer to duplicate - success
  1177. //
  1178. // History: 7/26/96 ChrisK Created
  1179. //
  1180. //-----------------------------------------------------------------------------
  1181. LPTSTR StrDup(LPTSTR *ppszDest,LPCTSTR pszSource)
  1182. {
  1183. if (ppszDest && pszSource)
  1184. {
  1185. *ppszDest = (LPTSTR)GlobalAlloc(NONZEROLPTR,lstrlen(pszSource)+1);
  1186. if (*ppszDest)
  1187. return (lstrcpy(*ppszDest,pszSource));
  1188. }
  1189. return NULL;
  1190. }
  1191. //+----------------------------------------------------------------------------
  1192. //
  1193. // Function: FileExists
  1194. //
  1195. // Synopsis: Uses FindFirstFile to determine whether a file exists on disk
  1196. //
  1197. // Arguments: None
  1198. //
  1199. // Returns: TRUE - Found the file on disk
  1200. // FALSE - No file found
  1201. //
  1202. // History: jmazner Created 9/11/96 (as fix for Normandy #7020)
  1203. //
  1204. //-----------------------------------------------------------------------------
  1205. BOOL FileExists(TCHAR *pszINSFileName)
  1206. {
  1207. Assert (pszINSFileName);
  1208. HANDLE hFindResult;
  1209. WIN32_FIND_DATA foundData;
  1210. hFindResult = FindFirstFile( (LPCTSTR)pszINSFileName, &foundData );
  1211. FindClose( hFindResult );
  1212. if (INVALID_HANDLE_VALUE == hFindResult)
  1213. {
  1214. return( FALSE );
  1215. }
  1216. else
  1217. {
  1218. return(TRUE);
  1219. }
  1220. }
  1221. //+----------------------------------------------------------------------------
  1222. //
  1223. // Function: CallCMConfig
  1224. //
  1225. // Synopsis: Call into the CMCFG32 dll's Configure function to allow Connection
  1226. // manager to process the .ins file as needed
  1227. //
  1228. // Arguements: hwnd -- hwnd of parent, in case sbs wants to put up messages
  1229. // lpszINSFile -- full path to the .ins file
  1230. //
  1231. // Returns: windows error code that cmcfg32 returns.
  1232. //
  1233. // History: 2/19/97 jmazner Created for Olympus #1106 (as CallSBSCfg )
  1234. // 5/9/97 jmazner Stolen from isign32 for Olympus #416
  1235. //
  1236. //-----------------------------------------------------------------------------
  1237. DWORD CallCMConfig(LPCTSTR lpszINSFile, LPTSTR lpszConnectoidName)
  1238. {
  1239. HINSTANCE hCMDLL = NULL;
  1240. DWORD dwRet = ERROR_SUCCESS;
  1241. TCHAR FAR cszCMCFG_DLL[] = TEXT("CMCFG32.DLL\0");
  1242. CHAR FAR cszCMCFG_CONFIGURE[] = "_CMConfig@8\0";
  1243. typedef DWORD (WINAPI * CMCONFIGURE) (LPTSTR lpszINSFile, LPTSTR lpszConnectoidName);
  1244. CMCONFIGURE lpfnConfigure = NULL;
  1245. Dprintf(TEXT("ICWCONN2: Calling LoadLibrary on %s\n"), cszCMCFG_DLL);
  1246. hCMDLL = LoadLibrary(cszCMCFG_DLL);
  1247. //
  1248. // Load DLL and entry point
  1249. //
  1250. if (NULL != hCMDLL)
  1251. {
  1252. Dprintf(TEXT("ICWCONN2: Calling GetProcAddress on %s\n"), cszCMCFG_CONFIGURE);
  1253. lpfnConfigure = (CMCONFIGURE)GetProcAddress(hCMDLL,cszCMCFG_CONFIGURE);
  1254. }
  1255. else
  1256. {
  1257. //
  1258. // 4/2/97 ChrisK Olympus 2759
  1259. // If the DLL can't be loaded, pick a specific error message to return.
  1260. //
  1261. dwRet = ERROR_DLL_NOT_FOUND;
  1262. goto CallCMConfigExit;
  1263. }
  1264. //
  1265. // Call function
  1266. //
  1267. if( hCMDLL && lpfnConfigure )
  1268. {
  1269. Dprintf(TEXT("ICWCONN2: Calling the %d entry point\n"), cszCMCFG_CONFIGURE);
  1270. dwRet = lpfnConfigure((TCHAR *)lpszINSFile, lpszConnectoidName);
  1271. }
  1272. else
  1273. {
  1274. Dprintf(TEXT("ICWCONN2: Unable to call the Configure entry point\n"));
  1275. dwRet = GetLastError();
  1276. }
  1277. CallCMConfigExit:
  1278. if( hCMDLL )
  1279. FreeLibrary(hCMDLL);
  1280. if( lpfnConfigure )
  1281. lpfnConfigure = NULL;
  1282. Dprintf(TEXT("ICWCONN2: CallCMConfig exiting with error code %d \n"), dwRet);
  1283. return dwRet;
  1284. }