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.

291 lines
7.8 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. drvevnt.cxx
  6. Abstract:
  7. This file contains the implementation for the Driver
  8. Event class
  9. Author:
  10. Khaled Sedky (khaleds) 18 January 2000
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #ifndef __DRVEVNT_HPP__
  16. #include "drvevnt.hpp"
  17. #endif
  18. #ifndef __LDFUNCS_HPP__
  19. #include "ldfuncs.hpp"
  20. #endif
  21. #ifndef __LDMGR_HPP__
  22. #include "ldmgr.hpp"
  23. #endif
  24. /* -------------------------------------- */
  25. /* Implemetation of class PrinterEvnetMgr */
  26. /* -------------------------------------- */
  27. /*++
  28. Function Name:
  29. TPrinterEventMgr :: TPrinterEventMgr
  30. Description:
  31. Constructor of the Printer(Driver) Event object
  32. Parameters:
  33. TLoad64BitDllsMgr* : Pointer to the main loader object
  34. which manage the process
  35. Return Value:
  36. None
  37. --*/
  38. TPrinterEventMgr::
  39. TPrinterEventMgr(
  40. IN TLoad64BitDllsMgr *pIpLdrObj
  41. ) :
  42. m_pLdrObj(pIpLdrObj),
  43. TClassID("TPrinterEventMgr")
  44. {
  45. m_pLdrObj->AddRef();
  46. }
  47. /*++
  48. Function Name:
  49. TPrinterEventMgr :: ~TPrinterEventMgr
  50. Description:
  51. Destructor of the Printer(Driver) Event object
  52. Parameters:
  53. None
  54. Return Value:
  55. None
  56. --*/
  57. TPrinterEventMgr::
  58. ~TPrinterEventMgr(
  59. VOID
  60. )
  61. {
  62. m_pLdrObj->Release();
  63. }
  64. /*++
  65. Function Name:
  66. TPrinterEventMgr :: SpoolerPrinterEvent
  67. Description:
  68. Calls into the driver DrvPrinterEvent entry point
  69. Parameters:
  70. PrinterName : The name of the printer involved
  71. PrinterEvent : What happened
  72. Flags : Misc. flag bits
  73. lParam : Event specific parameters
  74. Return Value:
  75. BOOL : TRUE in case of success
  76. : FALSE in case of failure
  77. --*/
  78. BOOL
  79. TPrinterEventMgr ::
  80. SpoolerPrinterEvent(
  81. IN LPWSTR pszPrinterName,
  82. IN int PrinterEvent,
  83. IN DWORD Flags,
  84. IN LPARAM lParam,
  85. OUT PDWORD pErrorCode
  86. )
  87. {
  88. HANDLE hPrinter, hDriver;
  89. BOOL ReturnValue=FALSE;
  90. PFNDRVPRINTEREVENT pfn;
  91. RPC_STATUS RpcStatus;
  92. SPLASSERT(m_pLdrObj);
  93. if((RpcStatus = RpcImpersonateClient(0)) == RPC_S_OK)
  94. {
  95. m_pLdrObj->IncUIRefCnt();
  96. {
  97. if (OpenPrinter((LPWSTR)pszPrinterName, &hPrinter, NULL))
  98. {
  99. if(hDriver = LoadPrinterDriver(hPrinter))
  100. {
  101. if (pfn = (PFNDRVPRINTEREVENT)GetProcAddress(hDriver,
  102. "DrvPrinterEvent"))
  103. {
  104. __try
  105. {
  106. ReturnValue = (*pfn)( pszPrinterName, PrinterEvent, Flags, lParam );
  107. }
  108. __except(1)
  109. {
  110. *pErrorCode = GetExceptionCode();
  111. }
  112. }
  113. else
  114. {
  115. *pErrorCode = GetLastError();
  116. }
  117. FreeLibrary(hDriver);
  118. }
  119. else
  120. {
  121. *pErrorCode = GetLastError();
  122. }
  123. ClosePrinter(hPrinter);
  124. }
  125. else
  126. {
  127. *pErrorCode = GetLastError();
  128. }
  129. }
  130. m_pLdrObj->DecUIRefCnt();
  131. RpcStatus = RpcRevertToSelf();
  132. }
  133. else
  134. {
  135. *pErrorCode = RpcStatus;
  136. }
  137. return ReturnValue;
  138. }
  139. /*++
  140. Function Name:
  141. TPrinterEventMgr :: DocumentEvent
  142. Description:
  143. Calls into the driver DrvDocumentEvent entry point
  144. Parameters:
  145. PrinterName : The name of the printer involved
  146. InDC : The printer DC.
  147. EscapeCode : Why this function is called
  148. InSize, : Size of the input buffer
  149. InBuf, : Pointer to the input buffer
  150. OutSize, : Size of the output buffer
  151. OutBuf, : Pointer to the output buffer
  152. ErrorCode : output Last Error from operation
  153. Return Value:
  154. DOCUMENTEVENT_SUCCESS : success
  155. DOCUMENTEVENT_UNSUPPORTED : EscapeCode is not supported
  156. DOCUMENTEVENT_FAILURE : an error occured
  157. --*/
  158. int
  159. TPrinterEventMgr ::
  160. DocumentEvent(
  161. IN LPWSTR pszPrinterName,
  162. IN ULONG_PTR InDC,
  163. IN int EscapeCode,
  164. IN DWORD InSize,
  165. IN LPBYTE pInBuf,
  166. OUT PDWORD pOutSize,
  167. OUT LPBYTE *ppOutBuf,
  168. OUT PDWORD pErrorCode
  169. )
  170. {
  171. HANDLE hPrinter, hDriver;
  172. int ReturnValue=0;
  173. PFNDRVDOCUMENTEVENT pfn;
  174. HDC hDC = reinterpret_cast<HDC>(InDC);
  175. RPC_STATUS RpcStatus ;
  176. SPLASSERT(m_pLdrObj);
  177. if((RpcStatus = RpcImpersonateClient(0)) == RPC_S_OK)
  178. {
  179. m_pLdrObj->IncUIRefCnt();
  180. {
  181. if (OpenPrinter((LPWSTR)pszPrinterName, &hPrinter, NULL))
  182. {
  183. if(hDriver = LoadPrinterDriver(hPrinter))
  184. {
  185. if (pfn = (PFNDRVDOCUMENTEVENT)GetProcAddress(hDriver,
  186. "DrvDocumentEvent"))
  187. {
  188. __try
  189. {
  190. ULONG cbOut = sizeof(ULONG);
  191. PDEVMODEW pOut = NULL;
  192. ReturnValue = (*pfn)( hPrinter,
  193. (HDC)InDC,
  194. EscapeCode,
  195. (ULONG)InSize,
  196. (PVOID)pInBuf,
  197. cbOut,
  198. (PVOID)&pOut);
  199. if(ReturnValue != -1 &&
  200. pOut)
  201. {
  202. *pOutSize = pOut->dmSize + pOut->dmDriverExtra;
  203. if(*ppOutBuf = new BYTE[*pOutSize])
  204. {
  205. memcpy(*ppOutBuf,pOut,*pOutSize);
  206. }
  207. else
  208. {
  209. *pErrorCode = ERROR_OUTOFMEMORY;
  210. }
  211. //
  212. // Now what should I do about the memory allocated
  213. // for pOut ????
  214. //
  215. }
  216. }
  217. __except(1)
  218. {
  219. SetLastError(GetExceptionCode());
  220. }
  221. }
  222. FreeLibrary(hDriver);
  223. }
  224. else
  225. {
  226. *pErrorCode = GetLastError();
  227. }
  228. ClosePrinter(hPrinter);
  229. }
  230. else
  231. {
  232. *pErrorCode = GetLastError();
  233. }
  234. }
  235. m_pLdrObj->DecUIRefCnt();
  236. RpcStatus = RpcRevertToSelf();
  237. }
  238. else
  239. {
  240. *pErrorCode = RpcStatus;
  241. }
  242. return ReturnValue;
  243. }