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.

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