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.

505 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1996 - 1999 Microsoft Corporation
  3. Module Name:
  4. lib.h
  5. Abstract:
  6. Common header file shared by all NT printer drivers
  7. Environment:
  8. Windows NT printer drivers
  9. Revision History:
  10. 08/30/96 -davidx-
  11. Coding style changes after code review.
  12. 08/13/96 -davidx-
  13. Add memory debug function declarations.
  14. 07/31/96 -davidx-
  15. Created it.
  16. --*/
  17. #ifndef _PRNLIB_H_
  18. #define _PRNLIB_H_
  19. #include <stddef.h>
  20. #include <stdlib.h>
  21. #ifdef OEMCOM
  22. #include <objbase.h>
  23. #endif
  24. #include <stdarg.h>
  25. #include <windef.h>
  26. #include <winerror.h>
  27. #include <winbase.h>
  28. #include <wingdi.h>
  29. #if _WIN32_WINNT < 0x0500
  30. typedef unsigned long DESIGNVECTOR;
  31. #endif
  32. #include <winddi.h>
  33. #include <tchar.h>
  34. #include <excpt.h>
  35. #if defined(KERNEL_MODE) && !defined(USERMODE_DRIVER)
  36. #include "winsplkm.h"
  37. #else
  38. #include <windows.h>
  39. #include <winspool.h>
  40. #ifndef KERNEL_MODE
  41. #include <stdio.h>
  42. #endif
  43. #endif
  44. #ifdef WINNT_40
  45. #include "p64_nt4.h"
  46. #endif // WINNT_40
  47. //
  48. //
  49. // Driver version numbers: This variable must be defined in each driver's DLL
  50. //
  51. #define PSDRIVER_VERSION 0x502
  52. #define UNIDRIVER_VERSION 0x500
  53. extern CONST WORD gwDriverVersion;
  54. //
  55. // Kernel-mode memory pool tag:
  56. // Define and initialize this variable in each driver's kernel mode DLL
  57. //
  58. extern DWORD gdwDrvMemPoolTag;
  59. //
  60. // Maximum value for signed and unsigned integers
  61. //
  62. #ifndef MAX_LONG
  63. #define MAX_LONG 0x7fffffff
  64. #endif
  65. #ifndef MAX_DWORD
  66. #define MAX_DWORD 0xffffffff
  67. #endif
  68. #ifndef MAX_SHORT
  69. #define MAX_SHORT 0x7fff
  70. #endif
  71. #ifndef MAX_WORD
  72. #define MAX_WORD 0xffff
  73. #endif
  74. #ifndef MAX_BYTE
  75. #define MAX_BYTE 0xff
  76. #endif
  77. //
  78. // Number of bytes in 1KB
  79. //
  80. #define KBYTES 1024
  81. //
  82. // Directory seperator character
  83. //
  84. #define PATH_SEPARATOR '\\'
  85. //
  86. // Declarations for 24.8 format precision fixed-point number
  87. //
  88. typedef LONG FIX_24_8;
  89. #define FIX_24_8_SHIFT 8
  90. #define FIX_24_8_SCALE (1 << FIX_24_8_SHIFT)
  91. #define MAX_DISPLAY_NAME 128 // max length for feature/option display names
  92. //
  93. // Include other header files here
  94. //
  95. #include "debug.h"
  96. #include "parser.h"
  97. #include "devmode.h"
  98. #include "regdata.h"
  99. #include "helper.h"
  100. //
  101. // Deal with the difference between user and kernel mode functions
  102. //
  103. #if defined(KERNEL_MODE) && !defined(USERMODE_DRIVER)
  104. #define WritePrinter EngWritePrinter
  105. #define GetPrinterDriver EngGetPrinterDriver
  106. #define GetPrinterData EngGetPrinterData
  107. #define SetPrinterData EngSetPrinterData
  108. #define EnumForms EngEnumForms
  109. #define GetPrinter EngGetPrinter
  110. #define GetForm EngGetForm
  111. #define SetLastError EngSetLastError
  112. #define GetLastError EngGetLastError
  113. #define MulDiv EngMulDiv
  114. #undef LoadLibrary
  115. #define LoadLibrary EngLoadImage
  116. #define FreeLibrary EngUnloadImage
  117. #define GetProcAddress EngFindImageProcAddress
  118. #if DBG && defined(MEMDEBUG)
  119. #define MemAlloc(size) MemDebugAlloc(0, size, gdwDrvMemPoolTag, __FILE__, __LINE__)
  120. #define MemAllocZ(size) MemDebugAlloc(FL_ZERO_MEMORY, size, gdwDrvMemPoolTag, __FILE__, __LINE__)
  121. #define MemFree(p) MemDebugFree(p)
  122. //
  123. // Perform necessary initialization when memory debug option is enabled
  124. //
  125. VOID
  126. MemDebugInit(
  127. VOID
  128. );
  129. //
  130. // Perform necessary memory checks when memory debug option is enabled
  131. //
  132. VOID
  133. MemDebugCheck(
  134. VOID
  135. );
  136. //
  137. // Perform necessary cleanup when memory debug option is enabled
  138. //
  139. VOID
  140. MemDebugCleanup(
  141. VOID
  142. );
  143. //
  144. // Allocate a memory block of the specified size, and
  145. // save necessary information for debugging purposes
  146. //
  147. PVOID
  148. MemDebugAlloc(
  149. IN DWORD dwFlags,
  150. IN DWORD dwSize,
  151. IN DWORD dwTag,
  152. IN PCSTR pstrFilename,
  153. IN INT iLineNumber
  154. );
  155. //
  156. // Free a memory block previously allocated using MemDebugAlloc
  157. //
  158. VOID
  159. MemDebugFree(
  160. IN PVOID pv
  161. );
  162. #else // !MEMDEBUG
  163. #define MemAlloc(size) EngAllocMem(0, size, gdwDrvMemPoolTag)
  164. #define MemAllocZ(size) EngAllocMem(FL_ZERO_MEMORY, size, gdwDrvMemPoolTag)
  165. #define MemFree(p) { if (p) EngFreeMem(p); }
  166. #define MemDebugInit()
  167. #define MemDebugCheck()
  168. #define MemDebugCleanup()
  169. #endif // !MEMDEBUG
  170. #else // !KERNEL_MODE
  171. #define MemAlloc(size) ((PVOID) LocalAlloc(LMEM_FIXED, (size)))
  172. #define MemAllocZ(size) ((PVOID) LocalAlloc(LPTR, (size)))
  173. #define MemFree(p) { if (p) LocalFree((HLOCAL) (p)); }
  174. #define MemDebugInit()
  175. #define MemDebugCheck()
  176. #define MemDebugCleanup()
  177. //
  178. // Change the size of a specified memory block. The size can increase
  179. // or decrease.
  180. //
  181. // We are not using LocalReAlloc() since our LocalAlloc uses LMEM_FIXED.
  182. //
  183. PVOID
  184. MemRealloc(
  185. IN PVOID pvOldMem,
  186. IN DWORD cbOld,
  187. IN DWORD cbNew
  188. );
  189. //
  190. // DLL instance handle - You must initialize this variable when the driver DLL
  191. // is attached to a process.
  192. //
  193. extern HINSTANCE ghInstance;
  194. #endif // !KERNEL_MODE
  195. //
  196. // Macros and constants for working with character strings
  197. //
  198. #define NUL 0
  199. #define EQUAL_STRING 0
  200. #define IS_EMPTY_STRING(p) ((p)[0] == NUL)
  201. #define SIZE_OF_STRING(p) ((_tcslen(p) + 1) * sizeof(TCHAR))
  202. #define IS_NUL_CHAR(ch) ((ch) == NUL)
  203. //
  204. // String copy function similar to _tcsncpy but it gurantees
  205. // the destination string is always nul terminated
  206. //
  207. VOID
  208. CopyStringW(
  209. OUT PWSTR pwstrDest,
  210. IN PCWSTR pwstrSrc,
  211. IN INT iDestSize
  212. );
  213. VOID
  214. CopyStringA(
  215. OUT PSTR pstrDest,
  216. IN PCSTR pstrSrc,
  217. IN INT iDestSize
  218. );
  219. #ifdef UNICODE
  220. #define CopyString CopyStringW
  221. #else
  222. #define CopyString CopyStringA
  223. #endif
  224. //
  225. // Convert index to keyword
  226. //
  227. PSTR
  228. PstrConvertIndexToKeyword(
  229. IN HANDLE hPrinter,
  230. IN POPTSELECT pOptions,
  231. IN PDWORD pdwKeywordSize,
  232. IN PUIINFO pUIInfo,
  233. IN POPTSELECT pCombineOptions,
  234. IN DWORD dwFeatureCount
  235. );
  236. VOID
  237. VConvertKeywordToIndex(
  238. IN HANDLE hPrinter,
  239. IN PSTR pstrKeyword,
  240. IN DWORD dwKeywordSize,
  241. OUT POPTSELECT pOptions,
  242. IN PRAWBINARYDATA pRawData,
  243. IN PUIINFO pUIInfo,
  244. IN POPTSELECT pCombineOptions,
  245. IN DWORD dwFeatureCount
  246. );
  247. //
  248. // Make a duplicate of the specified character string
  249. //
  250. PTSTR
  251. DuplicateString(
  252. IN LPCTSTR ptstrSrc
  253. );
  254. //
  255. // Macros for converting binary data to hex digits
  256. //
  257. extern const CHAR gstrDigitString[];
  258. #define HexDigit(n) gstrDigitString[(n) & 0xf]
  259. //
  260. // Determine wheter the system is running in a metric country
  261. // NOTE: Avaiable in user-mode only
  262. //
  263. BOOL
  264. IsMetricCountry(
  265. VOID
  266. );
  267. //
  268. // Map a data file into memory
  269. //
  270. typedef PVOID HFILEMAP;
  271. HFILEMAP
  272. MapFileIntoMemory(
  273. IN LPCTSTR ptstrFilename,
  274. OUT PVOID *ppvData,
  275. OUT PDWORD pdwSize
  276. );
  277. //
  278. // Unmapp a file from memory
  279. //
  280. VOID
  281. UnmapFileFromMemory(
  282. IN HFILEMAP hFileMap
  283. );
  284. //
  285. // Map a data file into memory for write
  286. //
  287. HANDLE
  288. MapFileIntoMemoryForWrite(
  289. IN LPCTSTR ptstrFilename,
  290. IN DWORD dwDesiredSize,
  291. OUT PVOID *ppvData,
  292. OUT PDWORD pdwSize
  293. );
  294. //
  295. // Generate a temporary file name in kernel mode
  296. //
  297. PTSTR
  298. GenerateTempFileName(
  299. IN LPCTSTR lpszPath,
  300. IN DWORD dwSeed
  301. );
  302. //
  303. // Wrapper function for spooler APIs:
  304. // GetPrinter
  305. // GetPrinterDriver
  306. // GetPrinterDriverDirectory
  307. // EnumForms
  308. //
  309. PVOID
  310. MyGetPrinter(
  311. IN HANDLE hPrinter,
  312. IN DWORD dwLevel
  313. );
  314. PVOID
  315. MyGetPrinterDriver(
  316. IN HANDLE hPrinter,
  317. IN HDEV hDev,
  318. IN DWORD dwLevel
  319. );
  320. PVOID
  321. MyEnumForms(
  322. IN HANDLE hPrinter,
  323. IN DWORD dwLevel,
  324. OUT PDWORD pdwFormsReturned
  325. );
  326. PVOID
  327. MyGetForm(
  328. IN HANDLE hPrinter,
  329. IN PTSTR ptstrFormName,
  330. IN DWORD dwLevel
  331. );
  332. //
  333. // Figure out what EMF features (such as N-up and reverse-order printing)
  334. // the spooler can support
  335. //
  336. VOID
  337. VGetSpoolerEmfCaps(
  338. IN HANDLE hPrinter,
  339. OUT PBOOL pbNupOption,
  340. OUT PBOOL pbReversePrint,
  341. IN DWORD cbOut,
  342. OUT PVOID pSplCaps
  343. );
  344. //
  345. // Generate a hash value for the given string.
  346. //
  347. DWORD
  348. HashKeyword(
  349. LPCSTR pKeywordStr
  350. );
  351. //
  352. // DBCS CharSet handling macros
  353. //
  354. // 128: SHIFTJIS_CHARSET
  355. // 129: HANGEUL_CHARSET
  356. // 130: JOHAB_CHARSET (defined if WINVER >= 0x0400)
  357. // 134: GB2312_CHARSET
  358. // 136: CHINESEBIG5_CHARSET
  359. #define IS_DBCSCHARSET(j) \
  360. (((j) == SHIFTJIS_CHARSET) || \
  361. ((j) == HANGEUL_CHARSET) || \
  362. ((j) == JOHAB_CHARSET) || \
  363. ((j) == GB2312_CHARSET) || \
  364. ((j) == CHINESEBIG5_CHARSET))
  365. // 932: Japan
  366. // 936: Chinese (PRC, Singapore)
  367. // 949: Korean
  368. // 950: Chinese (Taiwan, Hong Kong SAR)
  369. // 1361: Korean (Johab)
  370. #define IS_DBCSCODEPAGE(j) \
  371. (((j) == 932) || \
  372. ((j) == 936) || \
  373. ((j) == 949) || \
  374. ((j) == 950) || \
  375. ((j) == 1361))
  376. UINT PrdGetACP(VOID);
  377. BOOL PrdTranslateCharsetInfo(
  378. IN UINT dwSrc,
  379. OUT LPCHARSETINFO lpCs,
  380. IN DWORD dwFlags);
  381. //
  382. // Macros for working with array of bit flags
  383. //
  384. #define BITTST(p, i) (((PBYTE) (p))[(i) >> 3] & (1 << ((i) & 7)))
  385. #define BITSET(p, i) (((PBYTE) (p))[(i) >> 3] |= (1 << ((i) & 7)))
  386. #define BITCLR(p, i) (((PBYTE) (p))[(i) >> 3] &= ~(1 << ((i) & 7)))
  387. #endif // !_PRNLIB_H_