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.

193 lines
6.1 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. prtcfg.cxx
  6. Abstract:
  7. This file contains the implementation for the Printer
  8. and Document Property class
  9. Author:
  10. Khaled Sedky (khaleds) 18-Feb-2000
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #ifndef __LDFUNCS_HPP__
  16. #include "ldfuncs.hpp"
  17. #endif
  18. #ifndef __LDMGR_HPP__
  19. #include "ldmgr.hpp"
  20. #endif
  21. /* ------------------------------------ */
  22. /* Implemetation of class TPrinterCfgMgr */
  23. /* ------------------------------------ */
  24. /*++
  25. Function Name:
  26. TPrintUIMgr :: TPrintUIMgr
  27. Description:
  28. Contructor of the Printer (Driver) configuration
  29. manager
  30. Parameters:
  31. None
  32. Return Value:
  33. None
  34. --*/
  35. TPrinterCfgMgr::
  36. TPrinterCfgMgr(
  37. TLoad64BitDllsMgr *pIpLdrObj
  38. ) :
  39. m_pLdrObj(pIpLdrObj),
  40. TClassID("TPrinterCfgMgr")
  41. {
  42. m_pLdrObj->AddRef();
  43. }
  44. /*++
  45. Function Name:
  46. TPrintUIMgr :: TPrintUIMgr
  47. Description:
  48. Destructor of the Printer (Driver) configuration
  49. manager
  50. Parameters:
  51. None
  52. Return Value:
  53. None
  54. --*/
  55. TPrinterCfgMgr::
  56. ~TPrinterCfgMgr(
  57. VOID
  58. )
  59. {
  60. m_pLdrObj->Release();
  61. }
  62. /*++
  63. Function Name:
  64. TPrintUIMgr :: PrinterProperties
  65. Description:
  66. Displays a Printer-properties property sheet
  67. for the specific printer
  68. Parameters:
  69. hWnd : Parent Window
  70. Printername : Printer Name
  71. Flag : Access permissions
  72. ErrorCode : Win32 error in case of failure
  73. Return Value:
  74. BOOL : FALSE for failure
  75. TRUE for success
  76. --*/
  77. BOOL
  78. TPrinterCfgMgr ::
  79. PrinterProperties(
  80. IN ULONG_PTR hWnd,
  81. IN LPCWSTR pszPrinterName,
  82. IN DWORD Flag,
  83. OUT PDWORD pErrorCode
  84. )
  85. {
  86. DEVICEPROPERTYHEADER DPHdr;
  87. DWORD Result;
  88. PFNDEVICEPROPSHEETS pfnDevicePropSheets;
  89. HANDLE hPrinter = NULL;
  90. HMODULE hWinSpool = NULL;
  91. BOOL RetVal = FALSE;
  92. RPC_STATUS RpcStatus;
  93. if((RpcStatus = RpcImpersonateClient(0)) == RPC_S_OK)
  94. {
  95. if(hWinSpool = LoadLibrary(L"winspool.drv"))
  96. {
  97. if(pfnDevicePropSheets = reinterpret_cast<PFNDEVICEPROPSHEETS>(GetProcAddress(hWinSpool,
  98. "DevicePropertySheets")))
  99. {
  100. if(OpenPrinter(const_cast<LPWSTR>(pszPrinterName),
  101. &hPrinter,NULL))
  102. {
  103. PFNCALLCOMMONPROPSHEETUI pfnCallCommonPropSheeUI = NULL;
  104. DPHdr.cbSize = sizeof(DPHdr);
  105. DPHdr.hPrinter = hPrinter;
  106. DPHdr.Flags = (WORD)Flag;
  107. DPHdr.pszPrinterName = const_cast<LPWSTR>(pszPrinterName);
  108. if(pfnCallCommonPropSheeUI= reinterpret_cast<PFNCALLCOMMONPROPSHEETUI>(GetProcAddress(hWinSpool,
  109. (LPCSTR) MAKELPARAM(218, 0))))
  110. {
  111. m_pLdrObj->IncUIRefCnt();
  112. {
  113. if(pfnCallCommonPropSheeUI(reinterpret_cast<HWND>(hWnd),
  114. pfnDevicePropSheets,
  115. (LPARAM)&DPHdr,
  116. (LPDWORD)&Result) < 0)
  117. {
  118. RetVal = FALSE;
  119. *pErrorCode = GetLastError();
  120. }
  121. else
  122. {
  123. RetVal = TRUE;
  124. }
  125. PostMessage(reinterpret_cast<HWND>(hWnd),
  126. WM_ENDPRINTERPROPERTIES,
  127. (WPARAM)RetVal,
  128. (LPARAM)*pErrorCode);
  129. }
  130. m_pLdrObj->DecUIRefCnt();
  131. }
  132. else
  133. {
  134. *pErrorCode = GetLastError();
  135. }
  136. CloseHandle(hPrinter);
  137. }
  138. else
  139. {
  140. *pErrorCode = GetLastError();
  141. }
  142. }
  143. else
  144. {
  145. *pErrorCode = GetLastError();
  146. }
  147. FreeLibrary(hWinSpool);
  148. }
  149. else
  150. {
  151. *pErrorCode = GetLastError();
  152. }
  153. RpcStatus = RpcRevertToSelf();
  154. }
  155. else
  156. {
  157. *pErrorCode = RpcStatus;
  158. }
  159. return RetVal;
  160. }