Source code of Windows XP (NT5)
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.

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