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.

1150 lines
38 KiB

  1. #include "stdafx.h"
  2. #include <ole2.h>
  3. #include <shlobj.h>
  4. #include <iis64.h>
  5. #include "log.h"
  6. #include "shellutl.h"
  7. extern OCMANAGER_ROUTINES gHelperRoutines;
  8. HRESULT MySetLinkInfoTip(LPCTSTR lpszLink, LPCTSTR lpszDescription)
  9. {
  10. HRESULT hres;
  11. IShellLink* pShellLink;
  12. CoInitialize(NULL);
  13. hres = CoCreateInstance( CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&pShellLink);
  14. if (SUCCEEDED(hres))
  15. {
  16. IPersistFile* pPersistFile;
  17. hres = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
  18. if (SUCCEEDED(hres))
  19. {
  20. WCHAR wsz[_MAX_PATH];
  21. // Ensure that the string is WCHAR.
  22. #if defined(UNICODE) || defined(_UNICODE)
  23. _tcscpy(wsz, lpszLink);
  24. #else
  25. MultiByteToWideChar( CP_ACP, 0, lpszLink, -1, wsz, _MAX_PATH);
  26. #endif
  27. hres = pPersistFile->Load(wsz, STGM_READ);
  28. if (SUCCEEDED(hres))
  29. {
  30. hres = pShellLink->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI);
  31. if (SUCCEEDED(hres))
  32. {
  33. if (lpszDescription)
  34. {
  35. pShellLink->SetDescription(lpszDescription);
  36. // Save the link by calling IPersistFile::Save.
  37. hres = pPersistFile->Save(wsz, TRUE);
  38. }
  39. }
  40. else
  41. {
  42. iisDebugOut((LOG_TYPE_WARN, _T("MySetLinkInfoTip(): pShellLink->Resolve FAILED\n")));
  43. }
  44. }
  45. else
  46. {
  47. iisDebugOut((LOG_TYPE_WARN, _T("MySetLinkInfoTip(): pPersistFile->Load FAILED\n")));
  48. }
  49. pPersistFile->Release();
  50. }
  51. else
  52. {
  53. iisDebugOut((LOG_TYPE_WARN, _T("MySetLinkInfoTip(): QueryInterface FAILED\n")));
  54. }
  55. pShellLink->Release();
  56. }
  57. else
  58. {
  59. iisDebugOut((LOG_TYPE_WARN, _T("MySetLinkInfoTip(): CoCreateInstance FAILED\n")));
  60. }
  61. CoUninitialize();
  62. iisDebugOutSafeParams((LOG_TYPE_TRACE_WIN32_API, _T("MySetLinkInfoTip(): Link=%1!s!, Desc=%2!s!\n"), lpszLink, lpszDescription));
  63. return hres;
  64. }
  65. HRESULT MyQueryLink(LPCTSTR lpszLink, LPTSTR lpszProgram, LPTSTR lpszArgs, LPTSTR lpszDir, LPTSTR lpszIconPath, int *piIconIndex)
  66. {
  67. HRESULT hres;
  68. IShellLink* pShellLink;
  69. WIN32_FIND_DATA wfd;
  70. CoInitialize(NULL);
  71. hres = CoCreateInstance( CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&pShellLink);
  72. if (SUCCEEDED(hres))
  73. {
  74. IPersistFile* pPersistFile;
  75. hres = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
  76. if (SUCCEEDED(hres))
  77. {
  78. WCHAR wsz[_MAX_PATH];
  79. // Ensure that the string is WCHAR.
  80. #if defined(UNICODE) || defined(_UNICODE)
  81. _tcscpy(wsz, lpszLink);
  82. #else
  83. MultiByteToWideChar( CP_ACP, 0, lpszLink, -1, wsz, _MAX_PATH);
  84. #endif
  85. hres = pPersistFile->Load(wsz, STGM_READ);
  86. if (SUCCEEDED(hres))
  87. {
  88. hres = pShellLink->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI);
  89. if (SUCCEEDED(hres))
  90. {
  91. pShellLink->GetPath(lpszProgram, _MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH);
  92. pShellLink->GetArguments(lpszArgs, _MAX_PATH);
  93. pShellLink->GetWorkingDirectory(lpszDir, _MAX_PATH);
  94. pShellLink->GetIconLocation(lpszIconPath, _MAX_PATH, piIconIndex);
  95. }
  96. else
  97. {
  98. iisDebugOut((LOG_TYPE_ERROR, _T("MyQueryLink(): pShellLink->Resolve FAILED\n")));
  99. }
  100. }
  101. else
  102. {
  103. iisDebugOut((LOG_TYPE_WARN, _T("MyQueryLink(): pPersistFile->Load FAILED\n")));
  104. }
  105. pPersistFile->Release();
  106. }
  107. else
  108. {
  109. iisDebugOut((LOG_TYPE_ERROR, _T("MyQueryLink(): QueryInterface FAILED\n")));
  110. }
  111. pShellLink->Release();
  112. }
  113. else
  114. {
  115. iisDebugOut((LOG_TYPE_ERROR, _T("MyQueryLink(): CoCreateInstance FAILED\n")));
  116. }
  117. CoUninitialize();
  118. iisDebugOutSafeParams((LOG_TYPE_TRACE_WIN32_API, _T("MyQueryLink(): Program=%1!s!, Args=%2!s!, WorkDir=%3!s!, IconPath=%4!s!, IconIndex=%5!d!\n"), lpszProgram, lpszArgs, lpszDir, lpszIconPath, *piIconIndex));
  119. return hres;
  120. }
  121. HRESULT MyCreateLink(LPCTSTR lpszProgram, LPCTSTR lpszArgs, LPCTSTR lpszLink, LPCTSTR lpszDir, LPCTSTR lpszIconPath, int iIconIndex, LPCTSTR lpszDescription)
  122. {
  123. HRESULT hres;
  124. IShellLink* pShellLink;
  125. CoInitialize(NULL);
  126. //CoInitialize must be called before this
  127. // Get a pointer to the IShellLink interface.
  128. hres = CoCreateInstance( CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&pShellLink);
  129. if (SUCCEEDED(hres))
  130. {
  131. IPersistFile* pPersistFile;
  132. // Set the path to the shortcut target, and add the description.
  133. pShellLink->SetPath(lpszProgram);
  134. pShellLink->SetArguments(lpszArgs);
  135. pShellLink->SetWorkingDirectory(lpszDir);
  136. pShellLink->SetIconLocation(lpszIconPath, iIconIndex);
  137. if (lpszDescription)
  138. {
  139. pShellLink->SetDescription(lpszDescription);
  140. }
  141. // Query IShellLink for the IPersistFile interface for saving the
  142. // shortcut in persistent storage.
  143. hres = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
  144. if (SUCCEEDED(hres))
  145. {
  146. WCHAR wsz[_MAX_PATH];
  147. #if defined(UNICODE) || defined(_UNICODE)
  148. _tcscpy(wsz, lpszLink);
  149. #else
  150. // Ensure that the string is WCHAR.
  151. MultiByteToWideChar( CP_ACP,0,lpszLink,-1,wsz,_MAX_PATH);
  152. #endif
  153. // Save the link by calling IPersistFile::Save.
  154. hres = pPersistFile->Save(wsz, TRUE);
  155. if (!SUCCEEDED(hres))
  156. {
  157. iisDebugOut((LOG_TYPE_ERROR, _T("MyCreateLink(): pPersistFile->Save FAILED\n")));
  158. }
  159. pPersistFile->Release();
  160. }
  161. else
  162. {
  163. iisDebugOut((LOG_TYPE_ERROR, _T("MyCreateLink(): pShellLink->QueryInterface FAILED\n")));
  164. }
  165. pShellLink->Release();
  166. }
  167. else
  168. {
  169. iisDebugOut((LOG_TYPE_ERROR, _T("MyCreateLink(): CoCreateInstance FAILED\n")));
  170. }
  171. CoUninitialize();
  172. return hres;
  173. }
  174. BOOL MyDeleteLink(LPTSTR lpszShortcut)
  175. {
  176. TCHAR szFile[_MAX_PATH];
  177. SHFILEOPSTRUCT fos;
  178. ZeroMemory(szFile, sizeof(szFile));
  179. _tcscpy(szFile, lpszShortcut);
  180. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("MyDeleteLink(): %s.\n"), szFile));
  181. if (IsFileExist(szFile))
  182. {
  183. ZeroMemory(&fos, sizeof(fos));
  184. fos.hwnd = NULL;
  185. fos.wFunc = FO_DELETE;
  186. fos.pFrom = szFile;
  187. fos.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
  188. int iTemp = SHFileOperation(&fos);
  189. if (iTemp != 0)
  190. {
  191. iisDebugOut((LOG_TYPE_ERROR, _T("MyDeleteLink(): SHFileOperation FAILED\n")));
  192. }
  193. }
  194. return TRUE;
  195. }
  196. void MyMoveLink(LPCTSTR lpszItemDesc, LPCTSTR lpszOldGroup, LPCTSTR lpszNewGroup)
  197. {
  198. TCHAR szOldLink[_MAX_PATH], szNewLink[_MAX_PATH];
  199. TCHAR szProgram[_MAX_PATH], szArgs[_MAX_PATH], szDir[_MAX_PATH], szIconPath[_MAX_PATH];
  200. int iIconIndex;
  201. MyGetGroupPath(lpszOldGroup, szOldLink);
  202. _tcscat(szOldLink, _T("\\"));
  203. _tcscat(szOldLink, lpszItemDesc);
  204. _tcscat(szOldLink, _T(".lnk"));
  205. MyGetGroupPath(lpszNewGroup, szNewLink);
  206. if (!IsFileExist(szNewLink))
  207. MyAddGroup(lpszNewGroup);
  208. _tcscat(szNewLink, _T("\\"));
  209. _tcscat(szNewLink, lpszItemDesc);
  210. _tcscat(szNewLink, _T(".lnk"));
  211. MyQueryLink(szOldLink, szProgram, szArgs, szDir, szIconPath, &iIconIndex);
  212. MyDeleteLink(szOldLink);
  213. MyCreateLink(szProgram, szArgs, szNewLink, szDir, szIconPath, iIconIndex, NULL);
  214. return;
  215. }
  216. void MyGetSendToPath(LPTSTR szPath)
  217. {
  218. LPITEMIDLIST pidlSendTo;
  219. HRESULT hRes = NOERROR;
  220. iisDebugOutSafeParams((LOG_TYPE_TRACE_WIN32_API, _T("SendTo path=%1!s!\n"), szPath));
  221. hRes = SHGetSpecialFolderLocation(NULL, CSIDL_SENDTO, &pidlSendTo);
  222. if (hRes != NOERROR)
  223. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetSendToPath() SHGetSpecialFolderLocation (CSIDL_SENDTO) FAILED. hresult=0x%x\n"), hRes));}
  224. int iTemp = SHGetPathFromIDList(pidlSendTo, szPath);
  225. if (iTemp != TRUE)
  226. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetSendToPath() SHGetPathFromIDList FAILED\n")));}
  227. return;
  228. }
  229. void MyGetDeskTopPath(LPTSTR szPath)
  230. {
  231. LPITEMIDLIST pidlDeskTop;
  232. HRESULT hRes = NOERROR;
  233. #ifndef _CHICAGO_
  234. hRes = SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, &pidlDeskTop);
  235. #else
  236. hRes = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &pidlDeskTop);
  237. #endif
  238. if (hRes != NOERROR)
  239. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetDeskTopPath() SHGetSpecialFolderLocation (CSIDL_COMMON_DESKTOPDIRECTORY) FAILED. hresult=0x%x\n"), hRes));}
  240. int iTemp = SHGetPathFromIDList(pidlDeskTop, szPath);
  241. if (iTemp != TRUE)
  242. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetDeskTopPath() SHGetPathFromIDList FAILED\n")));}
  243. return;
  244. }
  245. void MyGetGroupPath(LPCTSTR szGroupName, LPTSTR szPath)
  246. {
  247. int nLen = 0;
  248. LPITEMIDLIST pidlPrograms;
  249. HRESULT hRes = NOERROR;
  250. #ifndef _CHICAGO_
  251. hRes = SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_PROGRAMS, &pidlPrograms);
  252. if (hRes != NOERROR)
  253. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetGroupPath() SHGetSpecialFolderLocation (CSIDL_COMMON_PROGRAMS) FAILED. hresult=0x%x\n"), hRes));}
  254. #else
  255. hRes = SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlPrograms);
  256. if (hRes != NOERROR)
  257. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetGroupPath() SHGetSpecialFolderLocation (CSIDL_PROGRAMS) FAILED. hresult=0x%x\n"), hRes));}
  258. #endif
  259. int iTemp = SHGetPathFromIDList(pidlPrograms, szPath);
  260. if (iTemp != TRUE)
  261. {iisDebugOut((LOG_TYPE_ERROR, _T("MyGetGroupPath() SHGetPathFromIDList FAILED\n")));}
  262. nLen = _tcslen(szPath);
  263. if (szGroupName)
  264. {
  265. if (szPath[nLen-1] != _T('\\')){_tcscat(szPath, _T("\\"));}
  266. _tcscat(szPath, szGroupName);
  267. }
  268. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("MyGetGroupPath(%s). Returns %s.\n"), szGroupName, szPath));
  269. return;
  270. }
  271. BOOL MyAddGroup(LPCTSTR szGroupName)
  272. {
  273. CString csPath;
  274. TCHAR szPath[_MAX_PATH];
  275. MyGetGroupPath(szGroupName, szPath);
  276. csPath = szPath;
  277. if (CreateLayerDirectory(csPath) != TRUE)
  278. {
  279. iisDebugOut((LOG_TYPE_ERROR, _T("MyAddGroup() CreateLayerDirectory FAILED\n")));
  280. }
  281. SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, szPath, 0);
  282. return TRUE;
  283. }
  284. BOOL MyIsGroupEmpty(LPCTSTR szGroupName)
  285. {
  286. TCHAR szPath[_MAX_PATH];
  287. TCHAR szFile[_MAX_PATH];
  288. WIN32_FIND_DATA FindData;
  289. HANDLE hFind;
  290. BOOL bFindFile = TRUE;
  291. BOOL fReturn = TRUE;
  292. MyGetGroupPath(szGroupName, szPath);
  293. _tcscpy(szFile, szPath);
  294. _tcscat(szFile, _T("\\*.*"));
  295. hFind = FindFirstFile(szFile, &FindData);
  296. while((INVALID_HANDLE_VALUE != hFind) && bFindFile)
  297. {
  298. if(*(FindData.cFileName) != _T('.'))
  299. {
  300. fReturn = FALSE;
  301. break;
  302. }
  303. //find the next file
  304. bFindFile = FindNextFile(hFind, &FindData);
  305. }
  306. FindClose(hFind);
  307. return fReturn;
  308. }
  309. BOOL MyDeleteGroup(LPCTSTR szGroupName)
  310. {
  311. BOOL fResult;
  312. TCHAR szPath[_MAX_PATH];
  313. TCHAR szFile[_MAX_PATH];
  314. SHFILEOPSTRUCT fos;
  315. WIN32_FIND_DATA FindData;
  316. HANDLE hFind;
  317. BOOL bFindFile = TRUE;
  318. MyGetGroupPath(szGroupName, szPath);
  319. //we can't remove a directory that is not empty, so we need to empty this one
  320. _tcscpy(szFile, szPath);
  321. _tcscat(szFile, _T("\\*.*"));
  322. ZeroMemory(&fos, sizeof(fos));
  323. fos.hwnd = NULL;
  324. fos.wFunc = FO_DELETE;
  325. fos.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
  326. hFind = FindFirstFile(szFile, &FindData);
  327. while((INVALID_HANDLE_VALUE != hFind) && bFindFile)
  328. {
  329. if(*(FindData.cFileName) != _T('.'))
  330. {
  331. //copy the path and file name to our temp buffer
  332. memset( (PVOID)szFile, 0, sizeof(szFile));
  333. _tcscpy(szFile, szPath);
  334. _tcscat(szFile, _T("\\"));
  335. _tcscat(szFile, FindData.cFileName);
  336. //add a second NULL because SHFileOperation is looking for this
  337. _tcscat(szFile, _T("\0"));
  338. //delete the file
  339. fos.pFrom = szFile;
  340. int iTemp = SHFileOperation(&fos);
  341. if (iTemp != 0)
  342. {iisDebugOut((LOG_TYPE_ERROR, _T("MyDeleteGroup(): SHFileOperation FAILED\n")));}
  343. }
  344. //find the next file
  345. bFindFile = FindNextFile(hFind, &FindData);
  346. }
  347. FindClose(hFind);
  348. fResult = RemoveDirectory(szPath);
  349. if (fResult)
  350. {
  351. SHChangeNotify(SHCNE_RMDIR, SHCNF_PATH, szPath, 0);
  352. }
  353. return(fResult);
  354. }
  355. void MyAddSendToItem(LPCTSTR szItemDesc, LPCTSTR szProgram, LPCTSTR szArgs, LPCTSTR szDir)
  356. {
  357. TCHAR szPath[_MAX_PATH];
  358. MyGetSendToPath(szPath);
  359. _tcscat(szPath, _T("\\"));
  360. _tcscat(szPath, szItemDesc);
  361. _tcscat(szPath, _T(".lnk"));
  362. MyCreateLink(szProgram, szArgs, szPath, szDir, NULL, 0, NULL);
  363. }
  364. void MyDeleteLinkWildcard(TCHAR *szDir, TCHAR *szFileName)
  365. {
  366. WIN32_FIND_DATA FindFileData;
  367. HANDLE hFile = INVALID_HANDLE_VALUE;
  368. TCHAR szFileToBeDeleted[_MAX_PATH];
  369. _stprintf(szFileToBeDeleted, _T("%s\\%s"), szDir, szFileName);
  370. hFile = FindFirstFile(szFileToBeDeleted, &FindFileData);
  371. if (hFile != INVALID_HANDLE_VALUE)
  372. {
  373. do {
  374. if ( _tcsicmp(FindFileData.cFileName, _T(".")) != 0 && _tcsicmp(FindFileData.cFileName, _T("..")) != 0 )
  375. {
  376. if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  377. {
  378. // this is a directory, so let's skip it
  379. }
  380. else
  381. {
  382. // this is a file, so let's Delete it.
  383. TCHAR szTempFileName[_MAX_PATH];
  384. _stprintf(szTempFileName, _T("%s\\%s"), szDir, FindFileData.cFileName);
  385. // set to normal attributes, so we can delete it
  386. SetFileAttributes(szTempFileName, FILE_ATTRIBUTE_NORMAL);
  387. // delete it, hopefully
  388. InetDeleteFile(szTempFileName);
  389. }
  390. }
  391. // get the next file
  392. if ( !FindNextFile(hFile, &FindFileData) )
  393. {
  394. FindClose(hFile);
  395. break;
  396. }
  397. } while (TRUE);
  398. }
  399. return;
  400. }
  401. void MyDeleteSendToItem(LPCTSTR szAppName)
  402. {
  403. TCHAR szPath[_MAX_PATH];
  404. TCHAR szPath2[_MAX_PATH];
  405. /*
  406. MyGetSendToPath(szPath);
  407. _tcscat(szPath, _T("\\"));
  408. _tcscat(szPath, szAppName);
  409. _tcscat(szPath, _T(".lnk"));
  410. MyDeleteLink(szPath);
  411. */
  412. MyGetSendToPath(szPath);
  413. _tcscpy(szPath2, szAppName);
  414. _tcscat(szPath2, _T(".lnk"));
  415. MyDeleteLinkWildcard(szPath, szPath2);
  416. }
  417. void MyAddDeskTopItem(LPCTSTR szItemDesc, LPCTSTR szProgram, LPCTSTR szArgs, LPCTSTR szDir, LPCTSTR szIconPath, int iIconIndex)
  418. {
  419. TCHAR szPath[_MAX_PATH];
  420. MyGetDeskTopPath(szPath);
  421. _tcscat(szPath, _T("\\"));
  422. _tcscat(szPath, szItemDesc);
  423. _tcscat(szPath, _T(".lnk"));
  424. MyCreateLink(szProgram, szArgs, szPath, szDir, szIconPath, iIconIndex, NULL);
  425. }
  426. HRESULT GetLNKProgramRunInfo(LPCTSTR lpszLink, LPTSTR lpszProgram)
  427. {
  428. HRESULT hres;
  429. int iDoUninit = FALSE;
  430. IShellLink* pShellLink = NULL;
  431. WIN32_FIND_DATA wfd;
  432. if (SUCCEEDED(CoInitialize(NULL)))
  433. {iDoUninit = TRUE;}
  434. hres = CoCreateInstance( CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&pShellLink);
  435. if (SUCCEEDED(hres))
  436. {
  437. IPersistFile* pPersistFile = NULL;
  438. hres = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
  439. if (SUCCEEDED(hres))
  440. {
  441. WCHAR wsz[_MAX_PATH];
  442. // Ensure that the string is WCHAR.
  443. #if defined(UNICODE) || defined(_UNICODE)
  444. _tcscpy(wsz, lpszLink);
  445. #else
  446. MultiByteToWideChar( CP_ACP, 0, lpszLink, -1, wsz, _MAX_PATH);
  447. #endif
  448. hres = pPersistFile->Load(wsz, STGM_READ);
  449. if (SUCCEEDED(hres))
  450. {
  451. hres = pShellLink->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI);
  452. if (SUCCEEDED(hres))
  453. {
  454. pShellLink->GetPath(lpszProgram, _MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH);
  455. }
  456. }
  457. if (pPersistFile)
  458. {pPersistFile->Release();pPersistFile = NULL;}
  459. }
  460. if (pShellLink)
  461. {pShellLink->Release();pShellLink = NULL;}
  462. }
  463. if (TRUE == iDoUninit)
  464. {CoUninitialize();}
  465. return hres;
  466. }
  467. BOOL IsFileNameInDelimitedList(LPTSTR szCommaDelimList,LPTSTR szExeNameWithoutPath)
  468. {
  469. BOOL bReturn = FALSE;
  470. TCHAR *token = NULL;
  471. TCHAR szCopyOfDataBecauseStrTokIsLame[_MAX_PATH];
  472. _tcscpy(szCopyOfDataBecauseStrTokIsLame,szCommaDelimList);
  473. // breakup the szCommaDelimList into strings and see if it contains the szExeNameWithoutPath string
  474. token = _tcstok(szCopyOfDataBecauseStrTokIsLame, _T(",;\t\n\r"));
  475. while(token != NULL)
  476. {
  477. // check if it matches our .exe name.
  478. if (0 == _tcsicmp(token,szExeNameWithoutPath))
  479. {
  480. return TRUE;
  481. }
  482. // Get next token
  483. token = _tcstok(NULL, _T(",;\t\n\r"));
  484. }
  485. return FALSE;
  486. }
  487. int LNKSearchAndDestroyRecursive(LPTSTR szDirToLookThru, LPTSTR szSemiColonDelmitedListOfExeNames, BOOL bDeleteItsDirToo)
  488. {
  489. int iReturn = FALSE;
  490. WIN32_FIND_DATA FindFileData;
  491. HANDLE hFile = INVALID_HANDLE_VALUE;
  492. TCHAR szFilePath[_MAX_PATH];
  493. TCHAR szFilename_ext_only[_MAX_EXT];
  494. DWORD retCode = GetFileAttributes(szDirToLookThru);
  495. if (retCode == 0xFFFFFFFF || !(retCode & FILE_ATTRIBUTE_DIRECTORY))
  496. {
  497. return FALSE;
  498. }
  499. _tcscpy(szFilePath, szDirToLookThru);
  500. AddPath(szFilePath, _T("*.*"));
  501. iisDebugOut((LOG_TYPE_TRACE, _T("LNKSearchAndDestroyRecursive:%s,%s,%d\n"),szDirToLookThru, szSemiColonDelmitedListOfExeNames, bDeleteItsDirToo));
  502. hFile = FindFirstFile(szFilePath, &FindFileData);
  503. if (hFile != INVALID_HANDLE_VALUE)
  504. {
  505. do {
  506. if ( _tcsicmp(FindFileData.cFileName, _T(".")) != 0 && _tcsicmp(FindFileData.cFileName, _T("..")) != 0 )
  507. {
  508. if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  509. {
  510. TCHAR szFullNewDirToLookInto[_MAX_EXT];
  511. _tcscpy(szFullNewDirToLookInto, szDirToLookThru);
  512. AddPath(szFullNewDirToLookInto,FindFileData.cFileName);
  513. // this is a directory, so let's go into this
  514. // directory recursively
  515. LNKSearchAndDestroyRecursive(szFullNewDirToLookInto,szSemiColonDelmitedListOfExeNames,bDeleteItsDirToo);
  516. }
  517. else
  518. {
  519. // check if this file is a .lnk file
  520. // if it is then let's open it and
  521. // see if it points to our .exe we're looking for...
  522. // get only the filename's extention
  523. _tsplitpath( FindFileData.cFileName, NULL, NULL, NULL, szFilename_ext_only);
  524. // check for .lnk
  525. if (0 == _tcsicmp(szFilename_ext_only, _T(".lnk")))
  526. {
  527. TCHAR szFilename_only[_MAX_FNAME];
  528. TCHAR szFullPathAndFilename[_MAX_PATH];
  529. TCHAR szTemporaryString[_MAX_PATH];
  530. // this is a .lnk,
  531. // open it and check the .exe..
  532. _tcscpy(szFullPathAndFilename,szDirToLookThru);
  533. AddPath(szFullPathAndFilename,FindFileData.cFileName);
  534. _tcscpy(szTemporaryString,_T(""));
  535. if (SUCCEEDED(GetLNKProgramRunInfo(szFullPathAndFilename, szTemporaryString)))
  536. {
  537. _tsplitpath( szTemporaryString, NULL, NULL, szFilename_only, szFilename_ext_only);
  538. _tcscpy(szTemporaryString, szFilename_only);
  539. _tcscat(szTemporaryString, szFilename_ext_only);
  540. //iisDebugOut((LOG_TYPE_TRACE, _T("open:%s,%s\n"),szFullPathAndFilename,szTemporaryString));
  541. // see if it is on our list of comma delimited names...
  542. if (TRUE == IsFileNameInDelimitedList(szSemiColonDelmitedListOfExeNames,szTemporaryString))
  543. {
  544. SetFileAttributes(szFullPathAndFilename, FILE_ATTRIBUTE_NORMAL);
  545. // delete it, hopefully
  546. InetDeleteFile(szFullPathAndFilename);
  547. // DELETE the file that references this .exe
  548. if (bDeleteItsDirToo)
  549. {
  550. // Get it's dirname and delete that too...
  551. RecRemoveEmptyDir(szDirToLookThru);
  552. }
  553. iReturn = TRUE;
  554. }
  555. }
  556. }
  557. }
  558. }
  559. // get the next file
  560. if ( !FindNextFile(hFile, &FindFileData) )
  561. {
  562. FindClose(hFile);
  563. break;
  564. }
  565. } while (TRUE);
  566. }
  567. return iReturn;
  568. }
  569. void MyDeleteDeskTopItem(LPCTSTR szAppName)
  570. {
  571. TCHAR szPath[_MAX_PATH];
  572. TCHAR szPath2[_MAX_PATH];
  573. /*
  574. MyGetDeskTopPath(szPath);
  575. _tcscat(szPath, _T("\\"));
  576. _tcscat(szPath, szAppName);
  577. _tcscat(szPath, _T(".lnk"));
  578. //if this is an upgrade, then the directories could have changed.
  579. //see if we need to delete the old one...
  580. MyDeleteLink(szPath);
  581. */
  582. MyGetDeskTopPath(szPath);
  583. _tcscpy(szPath2, szAppName);
  584. _tcscat(szPath2, _T(".lnk"));
  585. MyDeleteLinkWildcard(szPath, szPath2);
  586. }
  587. void DeleteFromGroup(LPCTSTR szGroupName, LPTSTR szApplicationExec)
  588. {
  589. TCHAR szPath[_MAX_PATH];
  590. // Get path to that group
  591. MyGetGroupPath(szGroupName, szPath);
  592. LNKSearchAndDestroyRecursive(szPath, szApplicationExec, FALSE);
  593. }
  594. void MyDeleteDeskTopItem2(LPTSTR szSemiColonDelmitedListOfExeNames, BOOL bDeleteItsDirToo)
  595. {
  596. TCHAR szPath[_MAX_PATH];
  597. MyGetDeskTopPath(szPath);
  598. LNKSearchAndDestroyRecursive(szPath, szSemiColonDelmitedListOfExeNames, bDeleteItsDirToo);
  599. }
  600. // boydm -------------------------------------------------------------------------------------------
  601. // Adds a web URL shortcut file . The URL is passed in and is put into the file in the form of a INI file.
  602. BOOL AddURLShortcutItem( LPCTSTR szGroupName, LPCTSTR szItemDesc, LPCTSTR szURL )
  603. {
  604. iisDebugOutSafeParams((LOG_TYPE_TRACE_WIN32_API, _T("AddURLShortcutItem(): %1!s!,%2!s!,%3!s!\n"), szGroupName, szItemDesc, szURL));
  605. // this first part of getting the paths is copied from MyAddItem below
  606. TCHAR szPath[_MAX_PATH];
  607. MyGetGroupPath(szGroupName, szPath);
  608. if (!IsFileExist(szPath))
  609. {
  610. MyAddGroup(szGroupName);
  611. }
  612. _tcscat(szPath, _T("\\"));
  613. _tcscat(szPath, szItemDesc);
  614. _tcscat(szPath, _T(".url"));
  615. // now use the private profile routines to easily create and fill in the content for the .url file
  616. return WritePrivateProfileString(
  617. _T("InternetShortcut"), // pointer to section name
  618. _T("URL"), // pointer to key name
  619. szURL, // pointer to string to add
  620. szPath // pointer to initialization filename
  621. );
  622. }
  623. void MyAddItem(LPCTSTR szGroupName, LPCTSTR szItemDesc, LPCTSTR szProgram, LPCTSTR szArgs, LPCTSTR szDir, LPCTSTR lpszIconPath)
  624. {
  625. TCHAR szPath[_MAX_PATH];
  626. MyGetGroupPath(szGroupName, szPath);
  627. if (!IsFileExist(szPath))
  628. MyAddGroup(szGroupName);
  629. _tcscat(szPath, _T("\\"));
  630. _tcscat(szPath, szItemDesc);
  631. _tcscat(szPath, _T(".lnk"));
  632. if (lpszIconPath && IsFileExist(lpszIconPath))
  633. {
  634. MyCreateLink(szProgram, szArgs, szPath, szDir, lpszIconPath, 0, NULL);
  635. }
  636. else
  637. {
  638. MyCreateLink(szProgram, szArgs, szPath, szDir, NULL, 0, NULL);
  639. }
  640. }
  641. void MyAddItemInfoTip(LPCTSTR szGroupName, LPCTSTR szAppName, LPCTSTR szDescription)
  642. {
  643. TCHAR szPath[_MAX_PATH];
  644. MyGetGroupPath(szGroupName, szPath);
  645. _tcscat(szPath, _T("\\"));
  646. _tcscat(szPath, szAppName);
  647. _tcscat(szPath, _T(".lnk"));
  648. MySetLinkInfoTip(szPath, szDescription);
  649. }
  650. void MyDeleteItem(LPCTSTR szGroupName, LPCTSTR szAppName)
  651. {
  652. TCHAR szPath[_MAX_PATH];
  653. TCHAR szPath2[_MAX_PATH];
  654. /*
  655. MyGetGroupPath(szGroupName, szPath);
  656. _tcscat(szPath, _T("\\"));
  657. _tcscat(szPath, szAppName);
  658. _tcscat(szPath, _T(".lnk"));
  659. MyDeleteLink(szPath);
  660. // try to remove items added by AddURLShortcutItem()
  661. MyGetGroupPath(szGroupName, szPath);
  662. _tcscat(szPath, _T("\\"));
  663. _tcscat(szPath2, szAppName);
  664. _tcscat(szPath2, _T(".url"));
  665. MyDeleteLink(szPath);
  666. */
  667. MyGetGroupPath(szGroupName, szPath);
  668. _tcscpy(szPath2, szAppName);
  669. _tcscat(szPath2, _T(".lnk"));
  670. MyDeleteLinkWildcard(szPath, szPath2);
  671. MyGetGroupPath(szGroupName, szPath);
  672. _tcscpy(szPath2, szAppName);
  673. _tcscat(szPath2, _T(".url"));
  674. MyDeleteLinkWildcard(szPath, szPath2);
  675. if (MyIsGroupEmpty(szGroupName)) {MyDeleteGroup(szGroupName);}
  676. }
  677. //
  678. // Used when the strings are passed in.
  679. //
  680. int MyMessageBox(HWND hWnd, LPCTSTR lpszTheMessage, UINT style)
  681. {
  682. int iReturn = TRUE;
  683. CString csTitle;
  684. MyLoadString(IDS_IIS_ERROR_MSGBOXTITLE,csTitle);
  685. // call MyMessageBox which will log to the log file and
  686. // check the global variable to see if we can even display the popup
  687. iReturn = MyMessageBox(hWnd, lpszTheMessage, csTitle, style | MB_SETFOREGROUND);
  688. return iReturn;
  689. }
  690. //
  691. // Used when the strings are passed in.
  692. //
  693. int MyMessageBox(HWND hWnd, LPCTSTR lpszTheMessage, LPCTSTR lpszTheTitle, UINT style)
  694. {
  695. int iReturn = IDOK;
  696. // make sure it goes to iisdebugoutput
  697. iisDebugOutSafeParams((LOG_TYPE_TRACE, _T("MyMessageBox: Title:%1!s!, Msg:%2!s!\n"), lpszTheTitle, lpszTheMessage));
  698. if (style & MB_ABORTRETRYIGNORE)
  699. {
  700. iReturn = IDIGNORE;
  701. }
  702. // Check global variable to see if we can even display the popup!
  703. if (g_pTheApp->m_bAllowMessageBoxPopups)
  704. {
  705. // Suppress the message if unattened or remove all
  706. // Who cares the user can't do anything about it anyway?
  707. // no use upsetting them, we do log to the OCM though
  708. //
  709. if (! g_pTheApp->m_fUnattended || g_pTheApp->m_dwSetupMode != SETUPMODE_REMOVEALL)
  710. {
  711. iReturn = MessageBox(hWnd, lpszTheMessage, lpszTheTitle, style | MB_SETFOREGROUND);
  712. }
  713. }
  714. return iReturn;
  715. }
  716. //
  717. // Used when the string and an error code passed in.
  718. //
  719. int MyMessageBox(HWND hWnd, CString csTheMessage, HRESULT iTheErrorCode, UINT style)
  720. {
  721. SetErrorFlag(__FILE__, __LINE__);
  722. int iReturn = TRUE;
  723. CString csMsg, csErrMsg;
  724. csMsg = csTheMessage;
  725. TCHAR pMsg[_MAX_PATH] = _T("");
  726. HRESULT nNetErr = (HRESULT) iTheErrorCode;
  727. DWORD dwFormatReturn = 0;
  728. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  729. if ( dwFormatReturn == 0) {
  730. if (nNetErr >= NERR_BASE)
  731. {
  732. HMODULE hDll = (HMODULE)LoadLibrary(_T("netmsg.dll"));
  733. if (hDll)
  734. {
  735. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,hDll, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  736. FreeLibrary(hDll);
  737. }
  738. }
  739. }
  740. HandleSpecificErrors(iTheErrorCode, dwFormatReturn, csMsg, pMsg, &csErrMsg);
  741. // Call MyMessageBox which will add title bar and log to log file
  742. iReturn = MyMessageBox(hWnd, csErrMsg, style | MB_SETFOREGROUND);
  743. // Log the eror message to OCM
  744. if (gHelperRoutines.OcManagerContext)
  745. {
  746. if ( gHelperRoutines.ReportExternalError ) {gHelperRoutines.ReportExternalError(gHelperRoutines.OcManagerContext,_T("IIS"),NULL,(DWORD_PTR)(LPCTSTR)csErrMsg,ERRFLG_PREFORMATTED);}
  747. }
  748. return iReturn;
  749. }
  750. //
  751. // Used when the String ID's are passed in.
  752. //
  753. int MyMessageBox(HWND hWnd, UINT iTheMessage, UINT style)
  754. {
  755. int iReturn = TRUE;
  756. CString csMsg;
  757. MyLoadString(iTheMessage,csMsg);
  758. // Call MyMessageBox which will add title bar and log to log file
  759. iReturn = MyMessageBox(hWnd, csMsg, style | MB_SETFOREGROUND);
  760. return iReturn;
  761. }
  762. //
  763. // Used when the String ID's are passed in.
  764. // And the tthere is an error code which needs to get shown and
  765. //
  766. int MyMessageBox(HWND hWnd, UINT iTheMessage, int iTheErrorCode, UINT style)
  767. {
  768. SetErrorFlag(__FILE__, __LINE__);
  769. int iReturn = TRUE;
  770. CString csMsg, csErrMsg;
  771. MyLoadString(iTheMessage,csMsg);
  772. TCHAR pMsg[_MAX_PATH] = _T("");
  773. int nNetErr = (int)iTheErrorCode;
  774. DWORD dwFormatReturn = 0;
  775. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  776. if ( dwFormatReturn == 0) {
  777. if (nNetErr >= NERR_BASE)
  778. {
  779. HMODULE hDll = (HMODULE)LoadLibrary(_T("netmsg.dll"));
  780. if (hDll)
  781. {
  782. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,hDll, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  783. FreeLibrary(hDll);
  784. }
  785. }
  786. }
  787. HandleSpecificErrors(iTheErrorCode, dwFormatReturn, csMsg, pMsg, &csErrMsg);
  788. // Call MyMessageBox which will add title bar and log to log file
  789. iReturn = MyMessageBox(hWnd, csErrMsg, style | MB_SETFOREGROUND);
  790. // Log the eror message to OCM
  791. if (gHelperRoutines.OcManagerContext)
  792. {
  793. if ( gHelperRoutines.ReportExternalError ) {gHelperRoutines.ReportExternalError(gHelperRoutines.OcManagerContext,_T("IIS"),NULL,(DWORD_PTR)(LPCTSTR)csErrMsg,ERRFLG_PREFORMATTED);}
  794. }
  795. return iReturn;
  796. }
  797. int MyMessageBox(HWND hWnd, UINT iTheMessage, LPCTSTR lpszTheFileNameOrWhatever, UINT style)
  798. {
  799. int iReturn = TRUE;
  800. CString csMsgForSprintf, csMsg;
  801. // Get the iTheMessage from the resouce file
  802. // csMsgForSprintf should now look something like: "cannot find file %s".
  803. MyLoadString(iTheMessage,csMsgForSprintf);
  804. // now load the passed in filename or whatever.
  805. // csMsg should now look like: "cannot find file Whatever";
  806. csMsg.Format( csMsgForSprintf, lpszTheFileNameOrWhatever);
  807. // Call MyMessageBox which will add title bar and log to log file
  808. iReturn = MyMessageBox(hWnd, csMsg, style | MB_SETFOREGROUND);
  809. return iReturn;
  810. }
  811. int MyMessageBox(HWND hWnd, UINT iTheMessage, LPCTSTR lpszTheFileNameOrWhatever, int iTheErrorCode, UINT style)
  812. {
  813. SetErrorFlag(__FILE__, __LINE__);
  814. int iReturn = TRUE;
  815. CString csMsgForSprintf, csMsg, csErrMsg;
  816. // Get the iTheMessage from the resouce file
  817. // csMsgForSprintf should now look something like: "cannot find file %s".
  818. MyLoadString(iTheMessage,csMsgForSprintf);
  819. // now load the passed in filename or whatever.
  820. // csMsg should now look like: "cannot find file Whatever";
  821. csMsg.Format( csMsgForSprintf, lpszTheFileNameOrWhatever);
  822. TCHAR pMsg[_MAX_PATH] = _T("");
  823. int nNetErr = (int)iTheErrorCode;
  824. DWORD dwFormatReturn = 0;
  825. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  826. if ( dwFormatReturn == 0) {
  827. if (nNetErr >= NERR_BASE)
  828. {
  829. HMODULE hDll = (HMODULE)LoadLibrary(_T("netmsg.dll"));
  830. if (hDll)
  831. {
  832. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,hDll, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  833. FreeLibrary(hDll);
  834. }
  835. }
  836. }
  837. HandleSpecificErrors(iTheErrorCode, dwFormatReturn, csMsg, pMsg, &csErrMsg);
  838. // Call MyMessageBox which will add title bar and log to log file
  839. iReturn = MyMessageBox(hWnd, csErrMsg, style | MB_SETFOREGROUND);
  840. // Log the eror message to OCM
  841. if (gHelperRoutines.OcManagerContext)
  842. {
  843. if ( gHelperRoutines.ReportExternalError ) {gHelperRoutines.ReportExternalError(gHelperRoutines.OcManagerContext,_T("IIS"),NULL,(DWORD_PTR)(LPCTSTR)csErrMsg,ERRFLG_PREFORMATTED);}
  844. }
  845. return iReturn;
  846. }
  847. int MyMessageBox(HWND hWnd, UINT iTheMessage, LPCTSTR lpszTheFileNameOrWhatever1, LPCTSTR lpszTheFileNameOrWhatever2, int iTheErrorCode, UINT style)
  848. {
  849. SetErrorFlag(__FILE__, __LINE__);
  850. int iReturn = TRUE;
  851. CString csMsgForSprintf, csMsg, csErrMsg;
  852. // Get the iTheMessage from the resouce file
  853. // csMsgForSprintf should now look something like: "cannot find file %s %s".
  854. MyLoadString(iTheMessage,csMsgForSprintf);
  855. // now load the passed in filename or whatever.
  856. // csMsg should now look like: "cannot find file Whatever1 Whatever2";
  857. csMsg.Format( csMsgForSprintf, lpszTheFileNameOrWhatever1, lpszTheFileNameOrWhatever2);
  858. TCHAR pMsg[_MAX_PATH] = _T("");
  859. int nNetErr = (int)iTheErrorCode;
  860. DWORD dwFormatReturn = 0;
  861. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  862. if ( dwFormatReturn == 0) {
  863. if (nNetErr >= NERR_BASE)
  864. {
  865. HMODULE hDll = (HMODULE)LoadLibrary(_T("netmsg.dll"));
  866. if (hDll)
  867. {
  868. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,hDll, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  869. FreeLibrary(hDll);
  870. }
  871. }
  872. }
  873. HandleSpecificErrors(iTheErrorCode, dwFormatReturn, csMsg, pMsg, &csErrMsg);
  874. // Call MyMessageBox which will add title bar and log to log file
  875. iReturn = MyMessageBox(hWnd, csErrMsg, style | MB_SETFOREGROUND);
  876. // Log the eror message to OCM
  877. if (gHelperRoutines.OcManagerContext)
  878. {
  879. if ( gHelperRoutines.ReportExternalError ) {gHelperRoutines.ReportExternalError(gHelperRoutines.OcManagerContext,_T("IIS"),NULL,(DWORD_PTR)(LPCTSTR)csErrMsg,ERRFLG_PREFORMATTED);}
  880. }
  881. return iReturn;
  882. }
  883. int MyMessageBox(HWND hWnd, UINT iTheMessage, LPCTSTR lpszTheFileNameOrWhatever1, LPCTSTR lpszTheFileNameOrWhatever2, LPCTSTR lpszTheFileNameOrWhatever3, int iTheErrorCode, UINT style)
  884. {
  885. SetErrorFlag(__FILE__, __LINE__);
  886. int iReturn = TRUE;
  887. CString csMsgForSprintf, csMsg, csErrMsg;
  888. // Get the iTheMessage from the resouce file
  889. // csMsgForSprintf should now look something like: "cannot find file %s %s".
  890. MyLoadString(iTheMessage,csMsgForSprintf);
  891. // now load the passed in filename or whatever.
  892. // csMsg should now look like: "cannot find file Whatever1 Whatever2 Whatever3";
  893. csMsg.Format( csMsgForSprintf, lpszTheFileNameOrWhatever1, lpszTheFileNameOrWhatever2, lpszTheFileNameOrWhatever3);
  894. TCHAR pMsg[_MAX_PATH] = _T("");
  895. int nNetErr = (int)iTheErrorCode;
  896. DWORD dwFormatReturn = 0;
  897. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  898. if ( dwFormatReturn == 0) {
  899. if (nNetErr >= NERR_BASE)
  900. {
  901. HMODULE hDll = (HMODULE)LoadLibrary(_T("netmsg.dll"));
  902. if (hDll)
  903. {
  904. dwFormatReturn = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,hDll, iTheErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  905. FreeLibrary(hDll);
  906. }
  907. }
  908. }
  909. HandleSpecificErrors(iTheErrorCode, dwFormatReturn, csMsg, pMsg, &csErrMsg);
  910. // Call MyMessageBox which will add title bar and log to log file
  911. iReturn = MyMessageBox(hWnd, csErrMsg, style | MB_SETFOREGROUND);
  912. // Log the eror message to OCM
  913. if (gHelperRoutines.OcManagerContext)
  914. {
  915. if ( gHelperRoutines.ReportExternalError ) {gHelperRoutines.ReportExternalError(gHelperRoutines.OcManagerContext,_T("IIS"),NULL,(DWORD_PTR)(LPCTSTR)csErrMsg,ERRFLG_PREFORMATTED);}
  916. }
  917. return iReturn;
  918. }
  919. int MyMessageBoxArgs(HWND hWnd, TCHAR *pszfmt, ...)
  920. {
  921. int iReturn = TRUE;
  922. TCHAR tszString[1000];
  923. va_list va;
  924. va_start(va, pszfmt);
  925. _vstprintf(tszString, pszfmt, va);
  926. va_end(va);
  927. // Call MyMessageBox which will add title bar and log to log file
  928. iReturn = MyMessageBox(hWnd, tszString, MB_OK | MB_SETFOREGROUND);
  929. return iReturn;
  930. }
  931. void GetErrorMsg(int errCode, LPCTSTR szExtraMsg)
  932. {
  933. SetErrorFlag(__FILE__, __LINE__);
  934. TCHAR pMsg[_MAX_PATH];
  935. FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),pMsg, _MAX_PATH, NULL);
  936. _tcscat(pMsg, szExtraMsg);
  937. MyMessageBox(NULL, pMsg, _T(""), MB_OK | MB_SETFOREGROUND);
  938. return;
  939. }
  940. void MyLoadString(int nID, CString &csResult)
  941. {
  942. TCHAR buf[MAX_STR_LEN];
  943. if (LoadString((HINSTANCE) g_MyModuleHandle, nID, buf, MAX_STR_LEN))
  944. csResult = buf;
  945. return;
  946. }