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.

415 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. allutils.h
  5. Abstract:
  6. Includes all header files necessary to use the libraries generated under the
  7. utils directory. Declares many macros and MAX constants.
  8. Author:
  9. Jim Schmidt (jimschm) 23-Aug-1996
  10. Revision History:
  11. marcw 2-Sep-1999 Ported over from win95upg project (migutil.h) Needs lots of cleanup.
  12. --*/
  13. #pragma once
  14. //
  15. // Includes
  16. //
  17. #include "utiltypes.h"
  18. #include "main.h"
  19. #include "dbgtrack.h"
  20. #include "basemem.h"
  21. #include "log.h"
  22. #include "growbuf.h"
  23. #include "strings.h"
  24. #include "poolmem.h"
  25. #include "growlist.h"
  26. #include "version.h"
  27. #include "unicode.h"
  28. #include "hash.h"
  29. #include "basefile.h"
  30. #include "memdb.h"
  31. #include "inf.h"
  32. #include "ini.h"
  33. #include "blobs.h"
  34. #include "objstr.h"
  35. #include "exclist.h"
  36. #include "reg.h"
  37. #include "regenum.h"
  38. #include "fileenum.h"
  39. #include "wnd.h"
  40. //
  41. // Strings
  42. //
  43. // None
  44. //
  45. // Constants
  46. //
  47. #define MAX_PATH_PLUS_NUL (MAX_PATH+1)
  48. #define MAX_MBCHAR_PATH (MAX_PATH_PLUS_NUL*2)
  49. #define MAX_WCHAR_PATH MAX_PATH_PLUS_NUL
  50. #define MAX_MBCHAR_PRINTABLE_PATH (MAX_PATH*2)
  51. #define MAX_WCHAR_PRINTABLE_PATH MAX_PATH
  52. #define MAX_SERVER_NAMEA (64*2)
  53. #define MAX_USER_NAMEA (MAX_SERVER_NAMEA + (20 * 2))
  54. #define MAX_REGISTRY_KEYA (1024 * 2)
  55. #define MAX_REGISTRY_VALUE_NAMEA (260 * 2)
  56. #define MAX_COMPONENT_NAMEA (256 * 2)
  57. #define MAX_COMPUTER_NAMEA (64 * 2)
  58. #define MAX_CMDLINEA (1024 * 2) // maximum number of chars in a Win95 command line
  59. #define MAX_KEYBOARDLAYOUT 64
  60. #define MAX_INF_SECTION_NAME 128
  61. #define MAX_INF_KEY_NAME 128
  62. #define MAX_SERVER_NAMEW 64
  63. #define MAX_USER_NAMEW (MAX_SERVER_NAMEW + 20)
  64. #define MAX_REGISTRY_KEYW 1024
  65. #define MAX_REGISTRY_VALUE_NAMEW 260
  66. #define MAX_COMPONENT_NAMEW 256
  67. #define MAX_COMPUTER_NAMEW 64
  68. #define MAX_CMDLINEW 1024 // maximum number of chars in a Win95 command line
  69. #ifdef UNICODE
  70. #define MAX_SERVER_NAME MAX_SERVER_NAMEW
  71. #define MAX_USER_NAME MAX_USER_NAMEW
  72. #define MAX_REGISTRY_KEY MAX_REGISTRY_KEYW
  73. #define MAX_REGISTRY_VALUE_NAME MAX_REGISTRY_VALUE_NAMEW
  74. #define MAX_COMPONENT_NAME MAX_COMPONENT_NAMEW
  75. #define MAX_COMPUTER_NAME MAX_COMPUTER_NAMEW
  76. #define MAX_CMDLINE MAX_CMDLINEW
  77. #define MAX_TCHAR_PATH MAX_WCHAR_PATH
  78. #define MAX_TCHAR_PRINTABLE_PATH MAX_WCHAR_PRINTABLE_PATH
  79. #else
  80. #define MAX_SERVER_NAME MAX_SERVER_NAMEA
  81. #define MAX_USER_NAME MAX_USER_NAMEA
  82. #define MAX_REGISTRY_KEY MAX_REGISTRY_KEYA
  83. #define MAX_REGISTRY_VALUE_NAME MAX_REGISTRY_VALUE_NAMEA
  84. #define MAX_COMPONENT_NAME MAX_COMPONENT_NAMEA
  85. #define MAX_COMPUTER_NAME MAX_COMPUTER_NAMEA
  86. #define MAX_CMDLINE MAX_CMDLINEA
  87. #define MAX_TCHAR_PATH MAX_MBCHAR_PATH
  88. #define MAX_TCHAR_PRINTABLE_PATH MAX_MBCHAR_PRINTABLE_PATH
  89. #endif
  90. //
  91. // Macros
  92. //
  93. //
  94. // OSVERSION macros...
  95. //
  96. #define ISNT() (g_OsInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  97. #define ISWIN9X() (g_OsInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  98. #define ISWIN95_GOLDEN() (ISWIN95() && WORD(g_OsInfo.dwBuildNumber) <= 1000)
  99. #define ISWIN95_OSR2() (ISWIN95() && WORD(g_OsInfo.dwBuildNumber) > 1000)
  100. #define ISWIN95() (ISWIN9X() && !ISMEMPHIS())
  101. #define ISMEMPHIS() (ISWIN9X() && g_OsInfo.dwMajorVersion==4 && g_OsInfo.dwMinorVersion==10)
  102. #define BUILDNUMBER() (g_OsInfo.dwBuildNumber)
  103. //
  104. // Error condition tags.
  105. //
  106. // These tags should be used for all error conditions.
  107. //
  108. #define ERROR_CRITICAL
  109. #define ERROR_NONCRITICAL
  110. #define ERROR_TRIVIAL
  111. #define ERROR_ABNORMAL_CONDITION
  112. //
  113. // Types
  114. //
  115. typedef struct {
  116. HANDLE EventHandle;
  117. } OUR_CRITICAL_SECTION, *POUR_CRITICAL_SECTION;
  118. //
  119. // String Mapping
  120. //
  121. typedef struct {
  122. BOOL UnicodeData;
  123. //
  124. // The filter can replace NewSubString. (The filter must also
  125. // set NewSubStringSizeInBytes when replacing NewSubString.)
  126. //
  127. union {
  128. struct {
  129. PCWSTR OriginalString;
  130. PCWSTR CurrentString;
  131. PCWSTR OldSubString;
  132. PCWSTR NewSubString;
  133. INT NewSubStringSizeInBytes;
  134. } Unicode;
  135. struct {
  136. PCSTR OriginalString;
  137. PCSTR CurrentString;
  138. PCSTR OldSubString;
  139. PCSTR NewSubString;
  140. INT NewSubStringSizeInBytes;
  141. } Ansi;
  142. };
  143. } REG_REPLACE_DATA, *PREG_REPLACE_DATA;
  144. typedef BOOL(REG_REPLACE_FILTER_PROTOTYPE)(PREG_REPLACE_DATA Data);
  145. typedef REG_REPLACE_FILTER_PROTOTYPE * REG_REPLACE_FILTER;
  146. typedef struct _tagCHARNODE {
  147. WORD Char;
  148. WORD Flags;
  149. PVOID OriginalStr;
  150. PVOID ReplacementStr;
  151. INT ReplacementBytes;
  152. struct _tagCHARNODE *NextLevel;
  153. struct _tagCHARNODE *NextPeer;
  154. REG_REPLACE_FILTER Filter;
  155. } CHARNODE, *PCHARNODE;
  156. typedef struct {
  157. PMHANDLE Pool;
  158. PCHARNODE FirstLevelRoot;
  159. } MAPSTRUCT, *PMAPSTRUCT;
  160. //
  161. // Globals
  162. //
  163. extern HINSTANCE g_hInst;
  164. extern HANDLE g_hHeap;
  165. extern OSVERSIONINFOA g_OsInfo;
  166. extern BOOL g_IsPc98;
  167. //
  168. // Boot drive letter
  169. //
  170. extern PCSTR g_BootDrivePathA;
  171. extern PCWSTR g_BootDrivePathW;
  172. extern PCSTR g_BootDriveA;
  173. extern PCWSTR g_BootDriveW;
  174. extern CHAR g_BootDriveLetterA;
  175. extern WCHAR g_BootDriveLetterW;
  176. //
  177. // Macro expansion list
  178. //
  179. // None
  180. //
  181. // Public function prototypes
  182. //
  183. //
  184. // Critical Section APIs, implemented because TryEnterCriticalSection is
  185. // supported only on NT, and we need it on Win9x.
  186. //
  187. BOOL
  188. InitializeOurCriticalSection (
  189. OUR_CRITICAL_SECTION *pcs
  190. );
  191. VOID
  192. DeleteOurCriticalSection (
  193. OUR_CRITICAL_SECTION *pcs
  194. );
  195. BOOL
  196. EnterOurCriticalSection (
  197. OUR_CRITICAL_SECTION *pcs
  198. );
  199. VOID
  200. LeaveOurCriticalSection (
  201. OUR_CRITICAL_SECTION *pcs
  202. );
  203. BOOL
  204. TryEnterOurCriticalSection (
  205. OUR_CRITICAL_SECTION *pcs
  206. );
  207. //
  208. // Includes of util modules
  209. //
  210. VOID
  211. CenterWindow (
  212. HWND Wnd,
  213. HWND Parent OPTIONAL
  214. );
  215. VOID
  216. TurnOnWaitCursor (
  217. VOID
  218. );
  219. VOID
  220. TurnOffWaitCursor (
  221. VOID
  222. );
  223. VOID
  224. OutOfMemory_Terminate (
  225. VOID
  226. );
  227. VOID
  228. SetOutOfMemoryParent (
  229. HWND hwnd
  230. );
  231. PMAPSTRUCT
  232. CreateStringMapping (
  233. VOID
  234. );
  235. VOID
  236. DestroyStringMapping (
  237. IN PMAPSTRUCT Map
  238. );
  239. VOID
  240. AddStringMappingPairExA (
  241. IN OUT PMAPSTRUCT Map,
  242. IN PCSTR Old,
  243. IN PCSTR New,
  244. IN REG_REPLACE_FILTER Filter OPTIONAL
  245. );
  246. #define AddStringMappingPairA(Map,Old,New) AddStringMappingPairExA(Map,Old,New,NULL)
  247. VOID
  248. AddStringMappingPairExW (
  249. IN OUT PMAPSTRUCT Map,
  250. IN PCWSTR Old,
  251. IN PCWSTR New,
  252. IN REG_REPLACE_FILTER Filter OPTIONAL
  253. );
  254. #define AddStringMappingPairW(Map,Old,New) AddStringMappingPairExW(Map,Old,New,NULL)
  255. BOOL
  256. MappingSearchAndReplaceExA (
  257. IN PMAPSTRUCT Map,
  258. IN PCSTR SrcBuffer,
  259. OUT PSTR Buffer, // can be the same as SrcBuffer
  260. IN INT InboundBytes, OPTIONAL
  261. OUT PINT OutboundBytes, OPTIONAL
  262. IN INT MaxSizeInBytes,
  263. IN BOOL CompleteMatchOnly
  264. );
  265. #define MappingSearchAndReplaceA(map,buffer,maxbytes) MappingSearchAndReplaceExA(map,buffer,buffer,0,NULL,maxbytes,FALSE)
  266. BOOL
  267. MappingSearchAndReplaceExW (
  268. IN PMAPSTRUCT Map,
  269. IN PCWSTR SrcBuffer,
  270. OUT PWSTR Buffer, // can be the same as SrcBuffer
  271. IN INT InboundBytes, OPTIONAL
  272. OUT PINT OutboundBytes, OPTIONAL
  273. IN INT MaxSizeInBytes,
  274. IN BOOL CompleteMatchOnly
  275. );
  276. #define MappingSearchAndReplaceW(map,buffer,maxbytes) MappingSearchAndReplaceExW(map,buffer,buffer,0,NULL,maxbytes,FALSE)
  277. HANDLE
  278. StartThread (
  279. IN PTHREAD_START_ROUTINE Address,
  280. IN PVOID Arg
  281. );
  282. //
  283. // Macro expansion definition
  284. //
  285. // None
  286. //
  287. // Unicode/Ansi mappings.
  288. //
  289. #ifdef UNICODE
  290. #define g_BootDrivePath g_BootDrivePathW
  291. #define g_BootDrive g_BootDriveW
  292. #define g_BootDriveLetter g_BootDriveLetterW
  293. #define VERSION_STRUCT VERSION_STRUCTW
  294. #define PVERSION_STRUCT PVERSION_STRUCTW
  295. #define CreateVersionStruct CreateVersionStructW
  296. #define DestroyVersionStruct DestroyVersionStructW
  297. #define EnumFirstVersionTranslation EnumFirstVersionTranslationW
  298. #define EnumNextVersionTranslation EnumNextVersionTranslationW
  299. #define EnumFirstVersionValue EnumFirstVersionValueW
  300. #define EnumNextVersionValue EnumNextVersionValueW
  301. #define AddStringMappingPair AddStringMappingPairW
  302. #define AddStringMappingPairEx AddStringMappingPairExW
  303. #define MappingSearchAndReplace MappingSearchAndReplaceW
  304. #define MappingSearchAndReplaceEx MappingSearchAndReplaceExW
  305. #else
  306. #define g_BootDrivePath g_BootDrivePathA
  307. #define g_BootDrive g_BootDriveA
  308. #define g_BootDriveLetter g_BootDriveLetterA
  309. #define VERSION_STRUCT VERSION_STRUCTA
  310. #define PVERSION_STRUCT PVERSION_STRUCTA
  311. #define CreateVersionStruct CreateVersionStructA
  312. #define DestroyVersionStruct DestroyVersionStructA
  313. #define EnumFirstVersionTranslation EnumFirstVersionTranslationA
  314. #define EnumNextVersionTranslation EnumNextVersionTranslationA
  315. #define EnumFirstVersionValue EnumFirstVersionValueA
  316. #define EnumNextVersionValue EnumNextVersionValueA
  317. #define AddStringMappingPair AddStringMappingPairA
  318. #define AddStringMappingPairEx AddStringMappingPairExA
  319. #define MappingSearchAndReplace MappingSearchAndReplaceA
  320. #define MappingSearchAndReplaceEx MappingSearchAndReplaceExA
  321. #endif