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.

267 lines
7.8 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // UTIL.H - utilities
  7. //
  8. // HISTORY:
  9. //
  10. // 1/27/99 a-jaswed Created.
  11. //
  12. // Common utilities for printing out messages
  13. #ifndef _UTIL_H_
  14. #define _UTIL_H_
  15. #include <assert.h>
  16. #include <tchar.h>
  17. #include <windows.h>
  18. #include <ole2.h>
  19. #include <setupapi.h>
  20. #include <syssetup.h>
  21. //////////////////////////////////////////////////////////////////////////////
  22. //
  23. // System boot mode
  24. //
  25. // Constants for values returned by GetSystemMetrics(SM_CLEANBOOT)
  26. //
  27. #define BOOT_CLEAN 0
  28. #define BOOT_SAFEMODE 1
  29. #define BOOT_SAFEMODEWITHNET 2
  30. BOOL InSafeMode();
  31. BOOL InDsRestoreMode();
  32. // Displays a message box with an error string in it.
  33. void ErrorMessage(LPCWSTR str, HRESULT hr) ;
  34. // Determine if two interfaces below to the same component.
  35. BOOL InterfacesAreOnSameComponent(IUnknown* pI1, IUnknown* pI2) ;
  36. bool GetOOBEPath(LPWSTR szOOBEPath);
  37. bool GetOOBEMUIPath(LPWSTR szOOBEPath);
  38. // Displays messages using OutputDebugString
  39. void __cdecl MyTrace(LPCWSTR lpszFormat, ...);
  40. // Determine if an address is accessable.
  41. BOOL IsValidAddress(const void* lp, UINT nBytes = 1, BOOL bReadWrite = FALSE) ;
  42. bool GetCanonicalizedPath(LPWSTR szCompletePath, LPCWSTR szFileName);
  43. bool GetString(HINSTANCE hInstance, UINT uiID, LPWSTR szString, UINT uiStringLen = MAX_PATH);
  44. HRESULT GetINIKey(HINSTANCE hInstance, LPCWSTR szINIFileName, UINT uiSectionName, UINT uiKeyName, LPVARIANT pvResult);
  45. HRESULT GetINIKeyBSTR(HINSTANCE hInstance, LPCWSTR szINIFileName, UINT uiSectionName, UINT uiKeyName, LPVARIANT pvResult);
  46. HRESULT GetINIKeyUINT(HINSTANCE hInstance, LPCWSTR szINIFileName, UINT uiSectionName, UINT uiKeyName, LPVARIANT pvResult);
  47. HRESULT SetINIKey(HINSTANCE hInstance, LPCWSTR szINIFileName, UINT uiSectionName, UINT uiKeyName, LPVARIANT pvResult);
  48. void WINAPI URLEncode(WCHAR* pszUrl, size_t bsize);
  49. void WINAPI URLAppendQueryPair
  50. (
  51. LPWSTR lpszQuery,
  52. LPWSTR lpszName,
  53. LPWSTR lpszValue
  54. );
  55. void GetCmdLineToken(LPWSTR *ppszCmd, LPWSTR pszOut);
  56. VOID PumpMessageQueue( );
  57. BOOL IsOEMDebugMode();
  58. BOOL IsThreadActive(HANDLE hThread);
  59. void GetDesktopDirectory(WCHAR* pszPath);
  60. void RemoveDesktopShortCut(LPWSTR lpszShortcutName);
  61. BOOL InvokeExternalApplication(
  62. IN PCWSTR ApplicationName, OPTIONAL
  63. IN PCWSTR CommandLine,
  64. IN OUT PDWORD ExitCode OPTIONAL
  65. );
  66. BOOL SignalComputerNameChangeComplete();
  67. BOOL IsUserAdmin(VOID);
  68. typedef struct tagSTRINGLIST {
  69. struct tagSTRINGLIST* Next;
  70. PTSTR String;
  71. } STRINGLIST, *PSTRINGLIST;
  72. PSTRINGLIST
  73. CreateStringCell(
  74. IN PCTSTR String
  75. );
  76. VOID
  77. DeleteStringCell(
  78. IN PSTRINGLIST Cell
  79. );
  80. BOOL
  81. InsertList(
  82. IN OUT PSTRINGLIST* List,
  83. IN PSTRINGLIST NewList
  84. );
  85. VOID
  86. DestroyList(
  87. IN PSTRINGLIST List
  88. );
  89. BOOL
  90. RemoveListI(
  91. IN OUT PSTRINGLIST* List,
  92. IN PCTSTR String
  93. );
  94. BOOL
  95. ExistInListI(
  96. IN PSTRINGLIST List,
  97. IN PCTSTR String
  98. );
  99. BOOL IsDriveNTFS(IN TCHAR Drive);
  100. BOOL
  101. HasTablet();
  102. DWORD
  103. MyGetModuleFileName (
  104. IN HMODULE Module,
  105. OUT PTSTR Buffer,
  106. IN DWORD BufferLength
  107. );
  108. // Determine if interface pointer is accessable.
  109. inline BOOL IsValidInterface(IUnknown* p)
  110. {
  111. return (p != NULL) && IsValidAddress(p, sizeof(IUnknown*), FALSE) ;
  112. }
  113. // Determine if the out parameter for an interface pointer is accessable.
  114. template <class T>
  115. inline BOOL IsValidInterfaceOutParam(T** p)
  116. {
  117. return (p != NULL) && IsValidAddress(p, sizeof(IUnknown*), TRUE) ;
  118. }
  119. inline VARIANT_BOOL Bool2VarBool(BOOL b)
  120. {
  121. return (b) ? -1 : 0;
  122. }
  123. inline BOOL VarBool2Bool(VARIANT_BOOL b)
  124. {
  125. return (0 == b) ? 0 : 1;
  126. }
  127. ///////////////////////////////////////////////////////////
  128. // Diagnostic support
  129. //
  130. #if defined(DBG) && !defined(ASSERTS_ON)
  131. #define ASSERTS_ON 1
  132. #endif
  133. #if ASSERTS_ON
  134. VOID
  135. AssertFail(
  136. IN PSTR FileName,
  137. IN UINT LineNumber,
  138. IN PSTR Condition
  139. );
  140. #define MYASSERT(x) if(!(x)) { AssertFail(__FILE__,__LINE__,#x); }
  141. #define VERIFY(x) MYASSERT(x)
  142. #else
  143. #define MYASSERT(x)
  144. #define VERIFY(f) ((void)(f))
  145. #endif
  146. // Helper function for checking HRESULTs.
  147. #ifdef DBG
  148. inline void CheckResult(HRESULT hr)
  149. {
  150. if (FAILED(hr))
  151. {
  152. ErrorMessage(NULL, hr) ;
  153. assert(FAILED(hr)) ;
  154. }
  155. }
  156. #define ASSERT_HRESULT CheckResult
  157. #else
  158. #define ASSERT_HRESULT
  159. #endif
  160. ///////////////////////////////////////////////////////////
  161. //
  162. // More Diagnostic support which mimics MFC
  163. //
  164. #ifndef __AFX_H__ // Only define these if MFC has not already been included
  165. #define TRACE(_fmt_) \
  166. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_)
  167. #define TRACE1(_fmt_,_arg1_) \
  168. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_)
  169. #define TRACE2(_fmt_,_arg1_,_arg2_) \
  170. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_,_arg2_)
  171. #define TRACE3(_fmt_,_arg1_,_arg2_,_arg3_) \
  172. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_,_arg2_,_arg3_)
  173. #define TRACE4(_fmt_,_arg1_,_arg2_,_arg3_,_arg4_) \
  174. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_,_arg2_,_arg3_,_arg4_)
  175. #define TRACE5(_fmt_,_arg1_,_arg2_,_arg3_,_arg4_,_arg5_) \
  176. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_,_arg2_,_arg3_,_arg4_,_arg5_)
  177. #define TRACE6(_fmt_,_arg1_,_arg2_,_arg3_,_arg4_,_arg5_,_arg6_) \
  178. pSetupDebugPrint(TEXT(__FILE__),__LINE__,NULL,_fmt_,_arg1_,_arg2_,_arg3_,_arg4_,_arg5_,_arg6_)
  179. #define ASSERT_POINTER(p, type) \
  180. MYASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
  181. #define ASSERT_NULL_OR_POINTER(p, type) \
  182. MYASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
  183. #endif // TRACE
  184. //////////////////////////////////////////////////////////////////////////////
  185. //
  186. // macro for QueryInterface and related functions
  187. // that require a IID and a (void **)
  188. // this will insure that the cast is safe and appropriate on C++
  189. //
  190. // IID_PPV_ARG(IType, ppType)
  191. // IType is the type of pType
  192. // ppType is the variable of type IType that will be filled
  193. //
  194. // RESULTS in: IID_IType, ppvType
  195. // will create a compiler error if wrong level of indirection is used.
  196. //
  197. // Just like IID_PPV_ARG, except that it sticks a NULL between the
  198. // IID and PPV (for IShellFolder::GetUIObjectOf).
  199. //
  200. // IID_PPV_ARG_NULL(IType, ppType)
  201. //
  202. #ifdef __cplusplus
  203. #define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast<void**>(static_cast<IType**>(ppType))
  204. #define IID_X_PPV_ARG(IType, X, ppType) IID_##IType, X, reinterpret_cast<void**>(static_cast<IType**>(ppType))
  205. #else
  206. #define IID_PPV_ARG(IType, ppType) &IID_##IType, (void**)(ppType)
  207. #define IID_X_PPV_ARG(IType, X, ppType) &IID_##IType, X, (void**)(ppType)
  208. #endif
  209. #define IID_PPV_ARG_NULL(IType, ppType) IID_X_PPV_ARG(IType, NULL, ppType)
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // Types of actions OOBE requires after shutdown. The type and amount of
  213. // cleanup done by OOBE on exit are dependent on these. This includes
  214. // notifying WinLogon of the necessity of reboot, deleting persistent data,
  215. // and setting the keys in HKLM\System\Setup.
  216. //
  217. typedef enum _OOBE_SHUTDOWN_ACTION
  218. {
  219. SHUTDOWN_NOACTION,
  220. SHUTDOWN_LOGON,
  221. SHUTDOWN_REBOOT,
  222. SHUTDOWN_POWERDOWN,
  223. SHUTDOWN_MAX // this entry must always be last
  224. } OOBE_SHUTDOWN_ACTION;
  225. #endif // _UTIL_H_