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.

116 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All Rights Reserved
  4. // @@BEGIN_DDKSPLIT
  5. Module Name:
  6. windows\spooler\prtprocs\winprint\support.c
  7. // @@END_DDKSPLIT
  8. Abstract:
  9. Support routines for WinPrint.
  10. // @@BEGIN_DDKSPLIT
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. /*++
  15. *******************************************************************
  16. G e t P r i n t e r I n f o
  17. Routine Description:
  18. This routine allocates the required memory for a
  19. PRINTER_INFO_? structure and retrieves the information
  20. from NT. This returns a pointer to the structure, which
  21. must be freed by the calling routine.
  22. Arguments:
  23. hPrinter HANDLE to the printer the job is in
  24. StructLevel The structure level to get
  25. pErrorCode => field to place error, if one
  26. Return Value:
  27. PUCHAR => buffer where devmode info is if okay
  28. NULL if error - pErrorCode returns error
  29. *******************************************************************
  30. --*/
  31. #include "local.h"
  32. PUCHAR
  33. GetPrinterInfo(IN HANDLE hPrinter,
  34. IN ULONG StructLevel,
  35. OUT PULONG pErrorCode)
  36. {
  37. ULONG reqbytes, alloc_size;
  38. PUCHAR ptr_info;
  39. USHORT retry = 2;
  40. alloc_size = BASE_PRINTER_BUFFER_SIZE;
  41. /** Allocate a buffer. **/
  42. ptr_info = AllocSplMem(alloc_size);
  43. /** If the buffer isn't big enough, try once more **/
  44. while (retry--) {
  45. /** If the alloc / realloc failed, return error **/
  46. if (!ptr_info) {
  47. *pErrorCode = ERROR_NOT_ENOUGH_MEMORY;
  48. return NULL;
  49. }
  50. /** Go get the printer information **/
  51. if (GetPrinter(
  52. hPrinter,
  53. StructLevel,
  54. (PUCHAR)ptr_info,
  55. alloc_size,
  56. &reqbytes) == TRUE) {
  57. /** Got the info - return it **/
  58. *pErrorCode = 0;
  59. return (PUCHAR)ptr_info;
  60. }
  61. /**
  62. GetPrinter failed - if not because of insufficient buffer, fail
  63. the call. Otherwise, up our hint, re-allocate and try again.
  64. **/
  65. *pErrorCode = GetLastError();
  66. if (*pErrorCode != ERROR_INSUFFICIENT_BUFFER) {
  67. FreeSplMem(ptr_info);
  68. return NULL;
  69. }
  70. /**
  71. Reallocate the buffer and re-try (note that, because we
  72. allocated the buffer as LMEM_FIXED, the LMEM_MOVABLE does
  73. not return a movable allocation, it just allows realloc
  74. to return a different pointer.
  75. **/
  76. alloc_size = reqbytes + 10;
  77. ptr_info = ReallocSplMem(ptr_info, alloc_size, 0);
  78. } /* While re-trying */
  79. if (ptr_info) {
  80. FreeSplMem(ptr_info);
  81. }
  82. *pErrorCode = ERROR_NOT_ENOUGH_MEMORY;
  83. return NULL;
  84. }