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.

98 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. PrinterJTDevmode.cpp
  5. Abstract:
  6. This is a shim that can be applied to those applications who
  7. assumed false upper-limit on the devmode size. With the support
  8. of job ticket, Longhorn+ inbox printer drivers' devmode could
  9. be over those upper-limits and therefore may cause those apps
  10. to crash. What this shim does is to set a private flag for the
  11. DocumentPropertiesA API. Our Longhorn inbox printer drivers
  12. recognize this flag and know not to add the job ticket expansion
  13. block in returned devmode.
  14. History:
  15. 10/29/2001 fengy Created
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(PrinterJTDevmode)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(DocumentPropertiesA)
  22. APIHOOK_ENUM_END
  23. #define DM_NOJTEXP_SHIM 0x80000000
  24. /*++
  25. This stub function intercepts all calls to DocumentPropertiesA
  26. and sets the private fMode flag DM_NOJTEXP_SHIM properly to
  27. retrieve non-JT-expanded devmode.
  28. --*/
  29. LONG
  30. APIHOOK(DocumentPropertiesA)(
  31. HWND hWnd,
  32. HANDLE hPrinter,
  33. LPSTR pDeviceName,
  34. PDEVMODEA pDevModeOutput,
  35. PDEVMODEA pDevModeInput,
  36. DWORD fMode
  37. )
  38. {
  39. DWORD fModeShim;
  40. LONG lRet;
  41. //
  42. // SDK says if fMode is zero, DocumentProperties returns
  43. // the number of bytes required by the printer driver's
  44. // DEVMODE data structure. So we shouldn't set the private
  45. // flag when fMode is zero (because drivers may check
  46. // for fMode == 0). When fMode is not zero, it contains
  47. // DM_xxx flags, then it's safe to set the private flag.
  48. //
  49. if (fMode == 0 || pDevModeOutput == NULL)
  50. {
  51. fModeShim = fMode;
  52. }
  53. else
  54. {
  55. fModeShim = fMode | DM_NOJTEXP_SHIM;
  56. DPFN(eDbgLevelInfo, "DocumentPropertiesA fModeShim=%X", fModeShim);
  57. }
  58. lRet = ORIGINAL_API(DocumentPropertiesA)(
  59. hWnd,
  60. hPrinter,
  61. pDeviceName,
  62. pDevModeOutput,
  63. pDevModeInput,
  64. fModeShim
  65. );
  66. return lRet;
  67. }
  68. /*++
  69. Register hooked functions
  70. --*/
  71. HOOK_BEGIN
  72. APIHOOK_ENTRY(WINSPOOL.DRV, DocumentPropertiesA);
  73. HOOK_END
  74. IMPLEMENT_SHIM_END