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.

258 lines
6.3 KiB

  1. // stdafx.h : include file for standard system include files,
  2. // or project specific include files that are used frequently,
  3. // but are changed infrequently
  4. #if !defined(AFX_STDAFX_H__4AD508C0_3D5F_4F04_AAC2_814BF64663A6__INCLUDED_)
  5. #define AFX_STDAFX_H__4AD508C0_3D5F_4F04_AAC2_814BF64663A6__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #define STRICT
  10. #ifndef _WIN32_WINNT
  11. #define _WIN32_WINNT 0x0400
  12. #endif
  13. #define _ATL_APARTMENT_THREADED
  14. #include <afxwin.h>
  15. #include <afxtempl.h>
  16. #include <atlbase.h>
  17. #include <initguid.h>
  18. #include <dbgeng.h>
  19. #include "emsvc.h"
  20. #include "svcobjdef.h"
  21. #include "comdef.h"
  22. #include "Trace.h"
  23. #include "GenCriticalSection.h"
  24. #include "genobjdef.h"
  25. #include "genlog.h"
  26. #define OPT
  27. //You may derive a class from CComModule and use it if you want to override
  28. //something, but do not change the name of _Module
  29. #define WINOS_NONE 0
  30. #define WINOS_NT4 4
  31. #define WINOS_WIN2K 5
  32. /* _afxMonthDays */
  33. AFX_STATIC_DATA int MonthDays[13] =
  34. {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
  35. class CServiceModule : public CComModule
  36. {
  37. public:
  38. HRESULT RegisterServer(BOOL bRegTypeLib, BOOL bService);
  39. HRESULT UnregisterServer();
  40. void Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, UINT nServiceNameID, const GUID* plibid = NULL);
  41. void Start();
  42. void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
  43. void Handler(DWORD dwOpcode);
  44. void Run();
  45. BOOL IsInstalled();
  46. BOOL Install();
  47. BOOL Uninstall();
  48. LONG Unlock();
  49. void LogEvent(LPCTSTR pszFormat, ...);
  50. void SetServiceStatus(DWORD dwState);
  51. void SetupAsLocalServer();
  52. /* _AfxOleDateFromTm */
  53. static bool DateFromTm(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMinute, WORD wSecond, DATE& dtDest);
  54. static DATE GetCurrentTime();
  55. static DATE GetDateFromFileTm(const FILETIME& filetimeSrc);
  56. HRESULT GetCompName( BSTR &bstrCompName );
  57. HRESULT GetTempEmFileName ( short nObjType, BSTR &bstrFileName );
  58. HRESULT GetEmDirectory (
  59. EmObjectType eObjectType,
  60. LPTSTR pszDirectory,
  61. LONG cchDirectory,
  62. LPTSTR pszExt,
  63. LONG cchExt
  64. );
  65. HRESULT GetEmFilePath ( short nFileType, bstr_t& bstrFilePath );
  66. HRESULT GetPathFromReg (
  67. HKEY hKeyParent,
  68. LPCTSTR lpszKeyName,
  69. LPCTSTR lpszQueryKey,
  70. LPTSTR pszDirectory,
  71. ULONG *cchDirectory
  72. );
  73. HRESULT CreateEmDirectory (
  74. LPTSTR lpDirName,
  75. LONG ccDirName,
  76. LPCTSTR lpParentDirPath = NULL
  77. );
  78. HRESULT RegisterDir (
  79. HKEY hKeyParent,
  80. LPCTSTR lpszKeyName,
  81. LPCTSTR lpszNamedValue,
  82. LPCTSTR lpValue
  83. );
  84. HRESULT CreateEmDirAndRegister (
  85. LPTSTR lpDirName,
  86. LONG ccDirName,
  87. HKEY hKeyParent,
  88. LPCTSTR lpszKeyName,
  89. LPCTSTR lpszNamedValue
  90. );
  91. HRESULT GetCDBInstallDir (
  92. LPTSTR lpCdbDir,
  93. ULONG *pccCdbDir
  94. );
  95. HRESULT GetEmInstallDir (
  96. LPTSTR lpEmDir,
  97. ULONG *pccEmDir
  98. );
  99. HRESULT
  100. GetMsInfoPath (
  101. LPTSTR lpMsInfoPath,
  102. ULONG *pccMsInfoPath
  103. );
  104. HRESULT
  105. GetOsVersion (
  106. OUT DWORD *pdwOsVer
  107. );
  108. //Implementation
  109. private:
  110. static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
  111. static void WINAPI _Handler(DWORD dwOpcode);
  112. // data members
  113. public:
  114. TCHAR m_szServiceName[256];
  115. SERVICE_STATUS_HANDLE m_hServiceStatus;
  116. SERVICE_STATUS m_status;
  117. DWORD dwThreadID;
  118. BOOL m_bService;
  119. CExcepMonSessionManager m_SessionManager;
  120. bstr_t m_bstrLogFilePath;
  121. bstr_t m_bstrLogFileExt;
  122. bstr_t m_bstrDumpFilePath;
  123. bstr_t m_bstrDumpFileExt;
  124. bstr_t m_bstrEcxFilePath;
  125. bstr_t m_bstrEcxFileExt;
  126. bstr_t m_bstrMsInfoFilePath;
  127. bstr_t m_bstrMsInfoFileExt;
  128. };
  129. extern CServiceModule _Module;
  130. inline LONG GetEmUniqueId()
  131. {
  132. static LONG nId = 0;
  133. return ::InterlockedIncrement(&nId);
  134. }
  135. inline BSTR CopyBSTR( LPBYTE pb, ULONG cb)
  136. {
  137. return ::SysAllocStringByteLen ((LPCSTR)pb, cb);
  138. }
  139. inline PEmObject GetEmObj(BSTR bstrEmObj)
  140. {
  141. //Do a simple cast from a BSTR to an EmObject
  142. return ((PEmObject)bstrEmObj);
  143. }
  144. inline HRESULT
  145. GetUniqueFileName
  146. (
  147. IN PEmObject pEmObj,
  148. OUT LPTSTR lpszFileName,
  149. IN LPCTSTR lpszPostFix = NULL,
  150. IN LPCTSTR lpszFileExt = NULL,
  151. IN bool bForSearch = false
  152. )
  153. {
  154. ATLTRACE(_T("GetUniqueFileName\n"));
  155. _ASSERTE( pEmObj != NULL );
  156. _ASSERTE( lpszFileName != NULL );
  157. HRESULT hr = E_FAIL;
  158. do
  159. {
  160. if( pEmObj == NULL ||
  161. lpszFileName == NULL ) {
  162. hr = E_INVALIDARG;
  163. break;
  164. }
  165. _tcscpy(lpszFileName, _T(""));
  166. if( _tcslen(pEmObj->szSecName) > 0 ) { _tcscpy( lpszFileName, pEmObj->szSecName ); }
  167. else if( _tcslen(pEmObj->szName) > 0 ) { _tcscpy( lpszFileName, pEmObj->szName ); }
  168. if( strlen((const char *)pEmObj->guidstream) > 0 ) {
  169. TCHAR szGuid[_MAX_FNAME] = _T("");
  170. StringFromGUID2( *(GUID *)(pEmObj->guidstream), szGuid, _MAX_FNAME );
  171. _tcscat( lpszFileName, _T("_") );
  172. _tcscat( lpszFileName, szGuid );
  173. }
  174. if( lpszPostFix && _tcslen(lpszPostFix) > 0 ) {
  175. _tcscat( lpszFileName, _T("_") );
  176. _tcscat( lpszFileName, lpszPostFix );
  177. }
  178. if( bForSearch == false ) {
  179. TCHAR szUniqueId[100] = _T("");
  180. _ltot(GetEmUniqueId(), szUniqueId, 10);
  181. _tcscat( lpszFileName, _T("_") );
  182. _tcscat( lpszFileName, szUniqueId );
  183. }
  184. else {
  185. _tcscat( lpszFileName, _T("*") );
  186. }
  187. if( lpszFileExt && _tcslen(lpszFileExt) > 0 ) {
  188. if(*lpszFileExt != _T('.')){ _tcscat( lpszFileName, _T(".") ); }
  189. _tcscat( lpszFileName, lpszFileExt );
  190. }
  191. hr = S_OK;
  192. }
  193. while( false );
  194. return hr;
  195. }
  196. #include <atlcom.h>
  197. //{{AFX_INSERT_LOCATION}}
  198. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  199. #endif // !defined(AFX_STDAFX_H__4AD508C0_3D5F_4F04_AAC2_814BF64663A6__INCLUDED)