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.

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