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.

395 lines
7.9 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. sputils.w (generates sputils.h)
  5. Abstract:
  6. Header file for utility routines used primarily by setupapi that's also
  7. used by other components for convinience.
  8. Link to either sputils.lib (static version) or spapip.lib (dll version)
  9. For internal use only.
  10. Author:
  11. Jamie Hunter (jamiehun) Jun-26-2000
  12. Revision History:
  13. --*/
  14. #if defined(SPUTILSW) && defined(UNICODE)
  15. //
  16. // SPUTILSW.LIB is cut down version of SPUTILSU.LIB
  17. // with renamed API's
  18. // thus SPUTILSW.LIB can be used with SPUTILSA.LIB
  19. //
  20. #define pSetupDebugPrintEx pSetupDebugPrintExW
  21. #define pSetupStringTableInitialize pSetupStringTableInitializeW
  22. #define pSetupStringTableInitializeEx pSetupStringTableInitializeExW
  23. #define pSetupStringTableDestroy pSetupStringTableDestroyW
  24. #define pSetupStringTableAddString pSetupStringTableAddStringW
  25. #define pSetupStringTableAddStringEx pSetupStringTableAddStringExW
  26. #define pSetupStringTableLookUpString pSetupStringTableLookUpStringW
  27. #define pSetupStringTableLookUpStringEx pSetupStringTableLookUpStringExW
  28. #define pSetupStringTableGetExtraData pSetupStringTableGetExtraDataW
  29. #define pSetupStringTableSetExtraData pSetupStringTableSetExtraDataW
  30. #define PSTRTAB_ENUM_ROUTINE PSTRTAB_ENUM_ROUTINE_W
  31. #define pSetupStringTableEnum pSetupStringTableEnumW
  32. #define pSetupStringTableStringFromId pSetupStringTableStringFromIdW
  33. #define pSetupStringTableStringFromIdEx pSetupStringTableStringFromIdExW
  34. #define pSetupStringTableDuplicate pSetupStringTableDuplicateW
  35. //
  36. // fileutil.c
  37. //
  38. #define pSetupOpenAndMapFileForRead pSetupOpenAndMapFileForReadW
  39. #define pSetupFileExists pSetupFileExistsW
  40. #define pSetupMakeSurePathExists pSetupMakeSurePathExistsW
  41. #define pSetupDoesUserHavePrivilege pSetupDoesUserHavePrivilegeW
  42. #define pSetupEnablePrivilege pSetupEnablePrivilegeW
  43. #define pSetupRegistryDelnode pSetupRegistryDelnodeW
  44. #define pSetupRegistryDelnodeEx pSetupRegistryDelnodeExW
  45. //
  46. // miscutil.c
  47. //
  48. #define pSetupDuplicateString pSetupDuplicateStringW
  49. #define pSetupCaptureAndConvertAnsiArg pSetupCaptureAndConvertAnsiArgW
  50. #define pSetupConcatenatePaths pSetupConcatenatePathsW
  51. #define pSetupGetFileTitle pSetupGetFileTitleW
  52. #endif // SPUTILSW && UNICODE
  53. //
  54. //
  55. //
  56. // Initialization - must be called to use the tools (static version only)
  57. //
  58. BOOL
  59. pSetupInitializeUtils(
  60. VOID
  61. );
  62. BOOL
  63. pSetupUninitializeUtils(
  64. VOID
  65. );
  66. //
  67. // Memory allocation functions (also used by other functions below)
  68. //
  69. PVOID
  70. pSetupMalloc(
  71. IN DWORD Size
  72. );
  73. PVOID
  74. pSetupDebugMalloc(
  75. IN DWORD Size,
  76. IN PCSTR Filename,
  77. IN DWORD Line
  78. );
  79. PVOID
  80. pSetupDebugMallocWithTag(
  81. IN DWORD Size,
  82. IN PCSTR Filename,
  83. IN DWORD Line,
  84. IN DWORD Tag
  85. );
  86. PVOID
  87. pSetupRealloc(
  88. IN PVOID Block,
  89. IN DWORD NewSize
  90. );
  91. PVOID
  92. pSetupReallocWithTag(
  93. IN PVOID Block,
  94. IN DWORD NewSize,
  95. IN DWORD Tag
  96. );
  97. VOID
  98. pSetupFree(
  99. IN CONST VOID *Block
  100. );
  101. VOID
  102. pSetupFreeWithTag(
  103. IN CONST VOID *Block,
  104. IN DWORD Tag
  105. );
  106. VOID
  107. pSetupDebugPrintEx(
  108. DWORD Level,
  109. PCTSTR format,
  110. ... OPTIONAL
  111. );
  112. HANDLE
  113. pSetupGetHeap(
  114. VOID
  115. );
  116. #if DBG
  117. #define pSetupCheckedMalloc(Size) pSetupDebugMalloc(Size,__FILE__,__LINE__)
  118. #define pSetupMallocWithTag(Size,Tag) pSetupDebugMallocWithTag(Size,__FILE__,__LINE__,Tag)
  119. #else
  120. #define pSetupCheckedMalloc(Size) pSetupMalloc(Size)
  121. #define pSetupMallocWithTag(Size,Tag) pSetupMalloc(Size)
  122. #endif
  123. #if DBG
  124. #define pSetupCheckInternalHeap() pSetupHeapCheck()
  125. #else
  126. #define pSetupCheckInternalHeap()
  127. #endif
  128. //
  129. // String table functions
  130. //
  131. PVOID
  132. pSetupStringTableInitialize(
  133. VOID
  134. );
  135. PVOID
  136. pSetupStringTableInitializeEx(
  137. IN UINT ExtraDataSize, OPTIONAL
  138. IN UINT Reserved
  139. );
  140. VOID
  141. pSetupStringTableDestroy(
  142. IN PVOID StringTable
  143. );
  144. //
  145. // Flags to be used by pSetupStringTableAddString and pSetupStringTableLookUpString
  146. //
  147. #define STRTAB_CASE_INSENSITIVE 0x00000000
  148. #define STRTAB_CASE_SENSITIVE 0x00000001
  149. #define STRTAB_BUFFER_WRITEABLE 0x00000002
  150. #define STRTAB_NEW_EXTRADATA 0x00000004
  151. LONG
  152. pSetupStringTableAddString(
  153. IN PVOID StringTable,
  154. IN OUT PTSTR String,
  155. IN DWORD Flags
  156. );
  157. LONG
  158. pSetupStringTableAddStringEx(
  159. IN PVOID StringTable,
  160. IN PTSTR String,
  161. IN DWORD Flags,
  162. IN PVOID ExtraData, OPTIONAL
  163. IN UINT ExtraDataSize OPTIONAL
  164. );
  165. LONG
  166. pSetupStringTableLookUpString(
  167. IN PVOID StringTable,
  168. IN OUT PTSTR String,
  169. IN DWORD Flags
  170. );
  171. LONG
  172. pSetupStringTableLookUpStringEx(
  173. IN PVOID StringTable,
  174. IN OUT PTSTR String,
  175. IN DWORD Flags,
  176. OUT PVOID ExtraData, OPTIONAL
  177. IN UINT ExtraDataBufferSize OPTIONAL
  178. );
  179. BOOL
  180. pSetupStringTableGetExtraData(
  181. IN PVOID StringTable,
  182. IN LONG StringId,
  183. OUT PVOID ExtraData,
  184. IN UINT ExtraDataBufferSize
  185. );
  186. BOOL
  187. pSetupStringTableSetExtraData(
  188. IN PVOID StringTable,
  189. IN LONG StringId,
  190. IN PVOID ExtraData,
  191. IN UINT ExtraDataSize
  192. );
  193. //
  194. // Type for pSetupStringTableEnum
  195. //
  196. typedef
  197. BOOL
  198. (*PSTRTAB_ENUM_ROUTINE)(
  199. IN PVOID StringTable,
  200. IN LONG StringId,
  201. IN PCTSTR String,
  202. IN PVOID ExtraData,
  203. IN UINT ExtraDataSize,
  204. IN LPARAM lParam
  205. );
  206. BOOL
  207. pSetupStringTableEnum(
  208. IN PVOID StringTable,
  209. OUT PVOID ExtraDataBuffer, OPTIONAL
  210. IN UINT ExtraDataBufferSize, OPTIONAL
  211. IN PSTRTAB_ENUM_ROUTINE Callback,
  212. IN LPARAM lParam OPTIONAL
  213. );
  214. PTSTR
  215. pSetupStringTableStringFromId(
  216. IN PVOID StringTable,
  217. IN LONG StringId
  218. );
  219. BOOL
  220. pSetupStringTableStringFromIdEx(
  221. IN PVOID StringTable,
  222. IN LONG StringId,
  223. IN OUT PTSTR pBuffer,
  224. IN OUT PULONG pBufSize
  225. );
  226. PVOID
  227. pSetupStringTableDuplicate(
  228. IN PVOID StringTable
  229. );
  230. //
  231. // File functions in fileutil.c
  232. //
  233. DWORD
  234. pSetupOpenAndMapFileForRead(
  235. IN PCTSTR FileName,
  236. OUT PDWORD FileSize,
  237. OUT PHANDLE FileHandle,
  238. OUT PHANDLE MappingHandle,
  239. OUT PVOID *BaseAddress
  240. );
  241. DWORD
  242. pSetupMapFileForRead(
  243. IN HANDLE FileHandle,
  244. OUT PDWORD FileSize,
  245. OUT PHANDLE MappingHandle,
  246. OUT PVOID *BaseAddress
  247. );
  248. BOOL
  249. pSetupUnmapAndCloseFile(
  250. IN HANDLE FileHandle,
  251. IN HANDLE MappingHandle,
  252. IN PVOID BaseAddress
  253. );
  254. DWORD
  255. pSetupMakeSurePathExists(
  256. IN PCTSTR FullFilespec
  257. );
  258. BOOL
  259. pSetupFileExists(
  260. IN PCTSTR FileName,
  261. OUT PWIN32_FIND_DATA FindData OPTIONAL
  262. );
  263. //
  264. // Non-file-related security routines in security.c.
  265. //
  266. BOOL
  267. pSetupIsUserAdmin(
  268. VOID
  269. );
  270. BOOL
  271. pSetupDoesUserHavePrivilege(
  272. PCTSTR PrivilegeName
  273. );
  274. BOOL
  275. pSetupEnablePrivilege(
  276. IN PCTSTR PrivilegeName,
  277. IN BOOL Enable
  278. );
  279. //
  280. // Registry utility functions
  281. //
  282. DWORD
  283. pSetupRegistryDelnode(
  284. IN HKEY RootKey,
  285. IN PCTSTR SubKeyName
  286. );
  287. DWORD
  288. pSetupRegistryDelnodeEx(
  289. IN HKEY RootKey,
  290. IN PCTSTR SubKeyName,
  291. IN DWORD ExtraFlags
  292. );
  293. //
  294. // Miscellaneous utility functions
  295. //
  296. DWORD
  297. pSetupCaptureAndConvertAnsiArg(
  298. IN PCSTR AnsiString,
  299. OUT PCWSTR *UnicodeString
  300. );
  301. PTSTR
  302. pSetupDuplicateString(
  303. IN PCTSTR String
  304. );
  305. PSTR
  306. pSetupUnicodeToMultiByte(
  307. IN PCWSTR UnicodeString,
  308. IN UINT Codepage
  309. );
  310. PWSTR
  311. pSetupMultiByteToUnicode(
  312. IN PCSTR String,
  313. IN UINT Codepage
  314. );
  315. VOID
  316. pSetupCenterWindowRelativeToParent(
  317. HWND hwnd
  318. );
  319. #define pSetupUnicodeToAnsi(UnicodeString) pSetupUnicodeToMultiByte((UnicodeString),CP_ACP)
  320. #define pSetupUnicodeToOem(UnicodeString) pSetupUnicodeToMultiByte((UnicodeString),CP_OEMCP)
  321. #define pSetupAnsiToUnicode(AnsiString) pSetupMultiByteToUnicode((AnsiString),CP_ACP)
  322. #define pSetupOemToUnicode(OemString) pSetupMultiByteToUnicode((OemString),CP_OEMCP)
  323. BOOL
  324. pSetupConcatenatePaths(
  325. IN OUT PTSTR Target,
  326. IN PCTSTR Path,
  327. IN UINT TargetBufferSize,
  328. OUT PUINT RequiredSize
  329. );
  330. PCTSTR
  331. pSetupGetFileTitle(
  332. IN PCTSTR FilePath
  333. );