Source code of Windows XP (NT5)
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.

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