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.

256 lines
11 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1998
  3. All rights reserved.
  4. Module Name:
  5. PSetup.cxx
  6. Abstract:
  7. Printer setup class to gain access to the ntprint.dll
  8. setup code.
  9. Author:
  10. Steve Kiraly (SteveKi) 19-Jan-1996
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include "psetup.hxx"
  16. #include "psetup5.hxx"
  17. /********************************************************************
  18. Printer setup class. Verison 5.0
  19. ********************************************************************/
  20. UINT TPSetup50::_uRefCount = 0;
  21. TLibrary *TPSetup50::_pLibrary = NULL;
  22. pfPSetupCreatePrinterDeviceInfoList TPSetup50::PSetupCreatePrinterDeviceInfoList = 0;
  23. pfPSetupDestroyPrinterDeviceInfoList TPSetup50::PSetupDestroyPrinterDeviceInfoList = 0;
  24. pfPSetupSelectDriver TPSetup50::PSetupSelectDriver = 0;
  25. pfPSetupCreateDrvSetupPage TPSetup50::PSetupCreateDrvSetupPage = 0;
  26. pfPSetupGetSelectedDriverInfo TPSetup50::PSetupGetSelectedDriverInfo = 0;
  27. pfPSetupDestroySelectedDriverInfo TPSetup50::PSetupDestroySelectedDriverInfo = 0;
  28. pfPSetupInstallPrinterDriver TPSetup50::PSetupInstallPrinterDriver = 0;
  29. pfPSetupIsDriverInstalled TPSetup50::PSetupIsDriverInstalled = 0;
  30. pfPSetupThisPlatform TPSetup50::PSetupThisPlatform = 0;
  31. pfPSetupDriverInfoFromName TPSetup50::PSetupDriverInfoFromName = 0;
  32. pfPSetupPreSelectDriver TPSetup50::PSetupPreSelectDriver = 0;
  33. pfPSetupCreateMonitorInfo TPSetup50::PSetupCreateMonitorInfo = 0;
  34. pfPSetupDestroyMonitorInfo TPSetup50::PSetupDestroyMonitorInfo = 0;
  35. pfPSetupEnumMonitor TPSetup50::PSetupEnumMonitor = 0;
  36. pfPSetupInstallMonitor TPSetup50::PSetupInstallMonitor = 0;
  37. pfPSetupProcessPrinterAdded TPSetup50::PSetupProcessPrinterAdded = 0;
  38. pfPSetupBuildDriversFromPath TPSetup50::PSetupBuildDriversFromPath = 0;
  39. pfPSetupIsTheDriverFoundInInfInstalled TPSetup50::PSetupIsTheDriverFoundInInfInstalled = 0;
  40. pfPSetupSetSelectDevTitleAndInstructions TPSetup50::PSetupSetSelectDevTitleAndInstructions = 0;
  41. pfPSetupInstallPrinterDriverFromTheWeb TPSetup50::PSetupInstallPrinterDriverFromTheWeb = 0;
  42. pfPSetupGetLocalDataField TPSetup50::PSetupGetLocalDataField = 0;
  43. pfPSetupFreeDrvField TPSetup50::PSetupFreeDrvField = 0;
  44. pfPSetupSelectDeviceButtons TPSetup50::PSetupSelectDeviceButtons = 0;
  45. pfPSetupFreeMem TPSetup50::PSetupFreeMem = 0;
  46. //
  47. // Setup class constructor.
  48. //
  49. TPSetup50::
  50. TPSetup50(
  51. VOID
  52. ) : _bValid( FALSE )
  53. {
  54. DBGMSG( DBG_TRACE, ( "TPSetup50::ctor refcount = %d.\n", _uRefCount ) );
  55. //
  56. // Hold a critical section while we load the library.
  57. //
  58. {
  59. CCSLock::Locker CSL( *gpCritSec );
  60. //
  61. // If this is the first load.
  62. //
  63. if( !_uRefCount ){
  64. //
  65. // Load the library, if success update the reference count
  66. // and indicate we have a valid object.
  67. //
  68. if( bLoad() ){
  69. _uRefCount++;
  70. _bValid = TRUE;
  71. } else {
  72. vUnLoad();
  73. }
  74. //
  75. // Update the reference count and indicate a valid object.
  76. //
  77. } else {
  78. _uRefCount++;
  79. _bValid = TRUE;
  80. }
  81. }
  82. }
  83. //
  84. // Setup class destructor
  85. //
  86. TPSetup50::
  87. ~TPSetup50(
  88. VOID
  89. )
  90. {
  91. DBGMSG( DBG_TRACE, ( "TPSetup50::dtor.\n" ) );
  92. //
  93. // If the object is not valid just exit.
  94. //
  95. if( !_bValid )
  96. return;
  97. //
  98. // Hold a critical section while we unload the dll.
  99. //
  100. {
  101. CCSLock::Locker CSL( *gpCritSec );
  102. //
  103. // Check the reference count and unload if it's the
  104. // last reference.
  105. //
  106. if( !--_uRefCount ){
  107. vUnLoad();
  108. }
  109. }
  110. }
  111. //
  112. // Indicates if the class is valid.
  113. //
  114. TPSetup50::
  115. bValid(
  116. VOID
  117. )
  118. {
  119. DBGMSG( DBG_TRACE, ( "TPSetup50::bValid.\n" ) );
  120. //
  121. // Check if we have a valid library pointer.
  122. //
  123. if( _pLibrary )
  124. return _pLibrary->bValid() && _bValid;
  125. return FALSE;
  126. }
  127. /********************************************************************
  128. private member functions.
  129. ********************************************************************/
  130. //
  131. // Load the library and inialize all the function addresses.
  132. //
  133. BOOL
  134. TPSetup50::
  135. bLoad(
  136. VOID
  137. )
  138. {
  139. DBGMSG( DBG_TRACE, ( "TPSetup50::vLoad.\n" ) );
  140. //
  141. // Load the library
  142. //
  143. _pLibrary = new TLibrary( TEXT( "ntprint.dll" ) );
  144. //
  145. // Check if the library was loaded ok.
  146. //
  147. if( VALID_PTR( _pLibrary ) ){
  148. PSetupCreatePrinterDeviceInfoList = (pfPSetupCreatePrinterDeviceInfoList) _pLibrary->pfnGetProc("PSetupCreatePrinterDeviceInfoList");
  149. PSetupDestroyPrinterDeviceInfoList = (pfPSetupDestroyPrinterDeviceInfoList) _pLibrary->pfnGetProc("PSetupDestroyPrinterDeviceInfoList");
  150. PSetupSelectDriver = (pfPSetupSelectDriver) _pLibrary->pfnGetProc("PSetupSelectDriver");
  151. PSetupCreateDrvSetupPage = (pfPSetupCreateDrvSetupPage) _pLibrary->pfnGetProc("PSetupCreateDrvSetupPage");
  152. PSetupGetSelectedDriverInfo = (pfPSetupGetSelectedDriverInfo) _pLibrary->pfnGetProc("PSetupGetSelectedDriverInfo");
  153. PSetupDestroySelectedDriverInfo = (pfPSetupDestroySelectedDriverInfo) _pLibrary->pfnGetProc("PSetupDestroySelectedDriverInfo");
  154. PSetupInstallPrinterDriver = (pfPSetupInstallPrinterDriver) _pLibrary->pfnGetProc("PSetupInstallPrinterDriver");
  155. PSetupIsDriverInstalled = (pfPSetupIsDriverInstalled) _pLibrary->pfnGetProc("PSetupIsDriverInstalled");
  156. PSetupThisPlatform = (pfPSetupThisPlatform) _pLibrary->pfnGetProc("PSetupThisPlatform");
  157. PSetupDriverInfoFromName = (pfPSetupDriverInfoFromName) _pLibrary->pfnGetProc("PSetupDriverInfoFromName");
  158. PSetupPreSelectDriver = (pfPSetupPreSelectDriver) _pLibrary->pfnGetProc("PSetupPreSelectDriver");
  159. PSetupCreateMonitorInfo = (pfPSetupCreateMonitorInfo) _pLibrary->pfnGetProc("PSetupCreateMonitorInfo");
  160. PSetupDestroyMonitorInfo = (pfPSetupDestroyMonitorInfo) _pLibrary->pfnGetProc("PSetupDestroyMonitorInfo");
  161. PSetupEnumMonitor = (pfPSetupEnumMonitor) _pLibrary->pfnGetProc("PSetupEnumMonitor");
  162. PSetupInstallMonitor = (pfPSetupInstallMonitor) _pLibrary->pfnGetProc("PSetupInstallMonitor");
  163. PSetupProcessPrinterAdded = (pfPSetupProcessPrinterAdded) _pLibrary->pfnGetProc("PSetupProcessPrinterAdded");
  164. PSetupBuildDriversFromPath = (pfPSetupBuildDriversFromPath) _pLibrary->pfnGetProc("PSetupBuildDriversFromPath");
  165. PSetupIsTheDriverFoundInInfInstalled = (pfPSetupIsTheDriverFoundInInfInstalled) _pLibrary->pfnGetProc("PSetupIsTheDriverFoundInInfInstalled");
  166. PSetupSetSelectDevTitleAndInstructions = (pfPSetupSetSelectDevTitleAndInstructions) _pLibrary->pfnGetProc("PSetupSetSelectDevTitleAndInstructions");
  167. PSetupInstallPrinterDriverFromTheWeb = (pfPSetupInstallPrinterDriverFromTheWeb) _pLibrary->pfnGetProc("PSetupInstallPrinterDriverFromTheWeb");
  168. PSetupGetLocalDataField = (pfPSetupGetLocalDataField) _pLibrary->pfnGetProc("PSetupGetLocalDataField");
  169. PSetupFreeDrvField = (pfPSetupFreeDrvField) _pLibrary->pfnGetProc("PSetupFreeDrvField");
  170. PSetupSelectDeviceButtons = (pfPSetupSelectDeviceButtons) _pLibrary->pfnGetProc("PSetupSelectDeviceButtons");
  171. PSetupFreeMem = (pfPSetupFreeMem) _pLibrary->pfnGetProc("PSetupFreeMem");
  172. if( PSetupCreatePrinterDeviceInfoList &&
  173. PSetupDestroyPrinterDeviceInfoList &&
  174. PSetupSelectDriver &&
  175. PSetupCreateDrvSetupPage &&
  176. PSetupGetSelectedDriverInfo &&
  177. PSetupDestroySelectedDriverInfo &&
  178. PSetupInstallPrinterDriver &&
  179. PSetupIsDriverInstalled &&
  180. PSetupThisPlatform &&
  181. PSetupDriverInfoFromName &&
  182. PSetupPreSelectDriver &&
  183. PSetupCreateMonitorInfo &&
  184. PSetupDestroyMonitorInfo &&
  185. PSetupEnumMonitor &&
  186. PSetupInstallMonitor &&
  187. PSetupProcessPrinterAdded &&
  188. PSetupIsTheDriverFoundInInfInstalled &&
  189. PSetupSetSelectDevTitleAndInstructions &&
  190. PSetupInstallPrinterDriverFromTheWeb &&
  191. PSetupGetLocalDataField &&
  192. PSetupFreeDrvField &&
  193. PSetupSelectDeviceButtons &&
  194. PSetupBuildDriversFromPath &&
  195. PSetupFreeMem ){
  196. return TRUE;
  197. } else {
  198. return FALSE;
  199. }
  200. }
  201. return TRUE;
  202. }
  203. //
  204. // Unload the library and reset static lib pointer.
  205. //
  206. VOID
  207. TPSetup50::
  208. vUnLoad(
  209. VOID
  210. )
  211. {
  212. DBGMSG( DBG_TRACE, ( "TPSetup50::vUnLoad.\n" ) );
  213. delete _pLibrary;
  214. _pLibrary = NULL;
  215. }