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.

235 lines
7.0 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. basecls.cxx
  6. Abstract:
  7. This file contains the implementation of the base classes
  8. used out by most of the loader and interfaces of the
  9. surrogate process. Although these base classes don't contain
  10. pure virtual functions , they should not be instantiated on
  11. their own. Their usage is utilized through inheritance mainly.
  12. Author:
  13. Khaled Sedky (khaleds) 18-Jan-2000
  14. Revision History:
  15. --*/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #ifndef __BASECLS_HPP__
  19. #include "basecls.hpp"
  20. #endif
  21. /* ------------------------------------ */
  22. /* Implemetation of class TPrinterDriver */
  23. /* ------------------------------------ */
  24. /*++
  25. Function Name:
  26. TPrinterDriver :: TPrinterDriver
  27. Description:
  28. Constructor of base printer driver object.
  29. Parameters:
  30. None
  31. Return Value:
  32. None
  33. --*/
  34. TPrinterDriver ::
  35. TPrinterDriver(
  36. VOID
  37. )
  38. {}
  39. /*++
  40. Function Name:
  41. TPrinterDriver :: ~TPrinterDriver
  42. Description:
  43. Destructor of base printer driver object.
  44. Parameters:
  45. None
  46. Return Value:
  47. None
  48. --*/
  49. TPrinterDriver ::
  50. ~TPrinterDriver(
  51. VOID
  52. )
  53. {}
  54. /*++
  55. Function Name:
  56. TPrinterDriver :: LoadPritnerDriver
  57. Description:
  58. Queries the Printer for the suitable driver and loads
  59. it
  60. Parameters:
  61. HANLDE hPrinter : Handle of Printer to laod driver for
  62. Return Value:
  63. HMODULE hDriver : In case of success Handle to driver dll
  64. In case of failure NULL
  65. --*/
  66. HMODULE
  67. TPrinterDriver ::
  68. LoadPrinterDriver(
  69. IN HANDLE hPrinter
  70. )
  71. {
  72. PDRIVER_INFO_5 pDriverInfo;
  73. DWORD DriverInfoSize, DriverVersion;
  74. HANDLE hDriver = NULL;
  75. BYTE Buffer[MAX_STATIC_ALLOC];
  76. BOOL bAllocBuffer = FALSE, bReturn;
  77. pDriverInfo = reinterpret_cast<PDRIVER_INFO_5>(Buffer);
  78. bReturn = GetPrinterDriverW(hPrinter,
  79. NULL,
  80. 5,
  81. (LPBYTE)pDriverInfo,
  82. MAX_STATIC_ALLOC,
  83. &DriverInfoSize);
  84. if (!bReturn &&
  85. (GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
  86. (pDriverInfo = (PDRIVER_INFO_5)new byte[DriverInfoSize]))
  87. {
  88. bAllocBuffer = TRUE;
  89. bReturn = GetPrinterDriverW(hPrinter,
  90. NULL,
  91. 5,
  92. (LPBYTE)pDriverInfo,
  93. DriverInfoSize,
  94. &DriverInfoSize);
  95. }
  96. if (bReturn)
  97. {
  98. hDriver = LoadLibraryEx(pDriverInfo->pConfigFile,
  99. NULL,
  100. LOAD_WITH_ALTERED_SEARCH_PATH);
  101. }
  102. if (bAllocBuffer)
  103. {
  104. delete [] pDriverInfo;
  105. }
  106. return hDriver;
  107. }
  108. /* ----------------------------- */
  109. /* Implemetation of class RefCnt */
  110. /* ----------------------------- */
  111. /*++
  112. Function Name:
  113. TRefCntMgr :: TRefCntMgr
  114. Description:
  115. Constructor of base refrence count object. This
  116. object keeps track of the number of clients using
  117. the object;
  118. Parameters:
  119. None
  120. Return Value:
  121. None
  122. --*/
  123. TRefCntMgr ::
  124. TRefCntMgr(
  125. VOID
  126. ) :
  127. m_cRefCnt(0)
  128. {}
  129. /*++
  130. Function Name:
  131. TRefCntMgr :: ~TRefCntMgr
  132. Description:
  133. Destructor of base refrence count object.
  134. Parameters:
  135. None
  136. Return Value:
  137. None
  138. --*/
  139. TRefCntMgr ::
  140. ~TRefCntMgr(
  141. VOID
  142. )
  143. {}
  144. /*++
  145. Function Name:
  146. TRefCntMgr :: AddRef
  147. Description:
  148. Increments the ref count on the object
  149. Parameters:
  150. None
  151. Return Value:
  152. DWORD : New Ref Count
  153. --*/
  154. DWORD
  155. TRefCntMgr ::
  156. AddRef(
  157. VOID
  158. )
  159. {
  160. return InterlockedIncrement(&m_cRefCnt);
  161. }
  162. /*++
  163. Function Name:
  164. TRefCntMgr :: Release
  165. Description:
  166. Decrements the ref count on the object
  167. and deletes the object , if this is the
  168. last attached client
  169. Parameters:
  170. None
  171. Return Value:
  172. DWORD : New Ref Count
  173. 0 if object deleted
  174. --*/
  175. DWORD
  176. TRefCntMgr ::
  177. Release(
  178. VOID
  179. )
  180. {
  181. LONG cRef = InterlockedDecrement(&m_cRefCnt);
  182. if (cRef == 0)
  183. {
  184. delete this;
  185. }
  186. return cRef;
  187. }