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.

246 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. prndata.c
  5. Abstract:
  6. Functions for accessing printer property data in the registry
  7. Environment:
  8. Fax driver, user and kernel mode
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxlib.h"
  16. DWORD
  17. GetPrinterDataDWord(
  18. HANDLE hPrinter,
  19. LPTSTR pRegKey,
  20. DWORD defaultValue
  21. )
  22. /*++
  23. Routine Description:
  24. Retrieve a DWORD value under PrinterData registry key
  25. Arguments:
  26. hPrinter - Specifies the printer in question
  27. pRegKey - Specifies the name of registry value
  28. defaultValue - Specifies the default value to be used if no data exists in registry
  29. Return Value:
  30. Current value for the requested registry key
  31. --*/
  32. {
  33. DWORD dwValue = defaultValue ; // prevents returning invalid value even if GetPrinterData(...) fails to initialize it
  34. DWORD type; // the type of data retrieved
  35. DWORD cb; // the size, in bytes, of the configuration data
  36. if (GetPrinterData(hPrinter,
  37. pRegKey,
  38. &type,
  39. (PBYTE) &dwValue,
  40. sizeof(dwValue),
  41. &cb) == ERROR_SUCCESS)
  42. {
  43. return dwValue;
  44. }
  45. return defaultValue;
  46. }
  47. PVOID
  48. MyGetPrinter(
  49. HANDLE hPrinter,
  50. DWORD level
  51. )
  52. /*++
  53. Routine Description:
  54. Wrapper function for GetPrinter spooler API
  55. Arguments:
  56. hPrinter - Identifies the printer in question
  57. level - Specifies the level of PRINTER_INFO_x structure requested
  58. Return Value:
  59. Pointer to a PRINTER_INFO_x structure, NULL if there is an error
  60. --*/
  61. {
  62. PBYTE pPrinterInfo = NULL;
  63. DWORD cbNeeded;
  64. if (!GetPrinter(hPrinter, level, NULL, 0, &cbNeeded) &&
  65. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  66. (pPrinterInfo = MemAlloc(cbNeeded)) &&
  67. GetPrinter(hPrinter, level, pPrinterInfo, cbNeeded, &cbNeeded))
  68. {
  69. return pPrinterInfo;
  70. }
  71. Error(("GetPrinter failed: %d\n", GetLastError()));
  72. MemFree(pPrinterInfo);
  73. return NULL;
  74. }
  75. #ifndef KERNEL_MODE
  76. BOOL
  77. SetPrinterDataDWord(
  78. HANDLE hPrinter,
  79. LPTSTR pRegKey,
  80. DWORD value
  81. )
  82. /*++
  83. Routine Description:
  84. Save a DWORD value under PrinterData registry key
  85. Arguments:
  86. hPrinter - Specifies the printer in question
  87. pRegKey - Specifies the name of registry value
  88. value - Specifies the value to be saved
  89. Return Value:
  90. TRUE if successful, FALSE otherwise
  91. --*/
  92. {
  93. if (SetPrinterData(hPrinter,
  94. pRegKey,
  95. REG_DWORD,
  96. (PBYTE) &value,
  97. sizeof(value)) != ERROR_SUCCESS)
  98. {
  99. Error(("Couldn't save registry key %ws: %d\n", pRegKey, GetLastError()));
  100. return FALSE;
  101. }
  102. return TRUE;
  103. }
  104. PVOID
  105. MyGetPrinterDriver(
  106. HANDLE hPrinter,
  107. DWORD level
  108. )
  109. /*++
  110. Routine Description:
  111. Wrapper function for GetPrinterDriver spooler API
  112. Arguments:
  113. hPrinter - Identifies the printer in question
  114. level - Specifies the level of DRIVER_INFO_x structure requested
  115. Return Value:
  116. Pointer to a DRIVER_INFO_x structure, NULL if there is an error
  117. --*/
  118. {
  119. PBYTE pDriverInfo = NULL;
  120. DWORD cbNeeded;
  121. if (!GetPrinterDriver(hPrinter, NULL, level, NULL, 0, &cbNeeded) &&
  122. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  123. (pDriverInfo = MemAlloc(cbNeeded)) &&
  124. GetPrinterDriver(hPrinter, NULL, level, pDriverInfo, cbNeeded, &cbNeeded))
  125. {
  126. return pDriverInfo;
  127. }
  128. Error(("GetPrinterDriver failed: %d\n", GetLastError()));
  129. MemFree(pDriverInfo);
  130. return NULL;
  131. }
  132. LPTSTR
  133. MyGetPrinterDriverDirectory(
  134. LPTSTR pServerName,
  135. LPTSTR pEnvironment
  136. )
  137. /*++
  138. Routine Description:
  139. Wrapper function for GetPrinterDriverDirectory spooler API
  140. Arguments:
  141. pServerName - Specifies the name of the print server, NULL for local machine
  142. pEnvironment - Specifies the processor architecture
  143. Return Value:
  144. Pointer to the printer driver directory on the specified print server
  145. NULL if there is an error
  146. --*/
  147. {
  148. PVOID pDriverDir = NULL;
  149. DWORD cb;
  150. if (! GetPrinterDriverDirectory(pServerName, pEnvironment, 1, NULL, 0, &cb) &&
  151. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  152. (pDriverDir = MemAlloc(cb)) &&
  153. GetPrinterDriverDirectory(pServerName, pEnvironment, 1, pDriverDir, cb, &cb))
  154. {
  155. return pDriverDir;
  156. }
  157. Error(("GetPrinterDriverDirectory failed: %d\n", GetLastError()));
  158. MemFree(pDriverDir);
  159. return NULL;
  160. }
  161. #endif // !KERNEL_MODE