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.

80 lines
2.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SPAWNTHR.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 7/24/1998
  12. *
  13. * DESCRIPTION: Spawn an app with an argument. Wait for it to close, then delete
  14. * the file.
  15. *
  16. *******************************************************************************/
  17. #ifndef __SPAWNTHR_H_INCLUDED
  18. #define __SPAWNTHR_H_INCLUDED
  19. class CTempImageOpenThread
  20. {
  21. private:
  22. TCHAR m_szApp[MAX_PATH];
  23. TCHAR m_szFile[MAX_PATH];
  24. private:
  25. // Hidden, can't use
  26. CTempImageOpenThread(void);
  27. CTempImageOpenThread( const CTempImageOpenThread & );
  28. CTempImageOpenThread &operator=( const CTempImageOpenThread & );
  29. private:
  30. CTempImageOpenThread( LPCTSTR pszApp, LPCTSTR pszFile )
  31. {
  32. if (pszApp)
  33. lstrcpy(m_szApp,pszApp);
  34. if (pszFile)
  35. lstrcpy(m_szFile,pszFile);
  36. }
  37. virtual ~CTempImageOpenThread(void)
  38. {
  39. }
  40. static DWORD ThreadProc( LPVOID pParam )
  41. {
  42. DWORD dwResult = 0;
  43. CTempImageOpenThread *This = (CTempImageOpenThread *)pParam;
  44. if (This)
  45. {
  46. dwResult = (DWORD)This->Spawn();
  47. delete This;
  48. }
  49. return dwResult;
  50. }
  51. bool Spawn(void)
  52. {
  53. SHELLEXECUTEINFO sei;
  54. ZeroMemory( &sei, sizeof(sei) );
  55. sei.cbSize = sizeof(sei);
  56. sei.lpFile = m_szApp;
  57. sei.lpParameters = m_szFile;
  58. sei.nShow = SW_NORMAL;
  59. sei.fMask = SEE_MASK_NOCLOSEPROCESS|SEE_MASK_DOENVSUBST;
  60. if (ShellExecuteEx( &sei ) && sei.hProcess)
  61. WaitForSingleObject( sei.hProcess, INFINITE );
  62. if (lstrlen(m_szFile))
  63. DeleteFile(m_szFile);
  64. return true;
  65. }
  66. public:
  67. static HANDLE Spawn( LPCTSTR pszApp, LPCTSTR pszFile )
  68. {
  69. CTempImageOpenThread *pTempImageOpenThread = new CTempImageOpenThread(pszApp, pszFile);
  70. if (pTempImageOpenThread)
  71. {
  72. DWORD dwThreadId;
  73. return ::CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, pTempImageOpenThread, 0, &dwThreadId );
  74. }
  75. return NULL;
  76. }
  77. };
  78. #endif // __SPAWNTHR_H_INCLUDED