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.

504 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. #include "drvver.hxx"
  18. /********************************************************************
  19. Printer setup class.
  20. ********************************************************************/
  21. TPSetup::
  22. TPSetup(
  23. VOID
  24. ) : _bValid( FALSE ),
  25. _pPSetup50( NULL )
  26. {
  27. //
  28. // Attemp to load the 5.0 version.
  29. //
  30. _pPSetup50 = new TPSetup50();
  31. if( VALID_PTR( _pPSetup50 ) )
  32. {
  33. _bValid = TRUE;
  34. return;
  35. } else {
  36. delete _pPSetup50;
  37. _pPSetup50 = NULL;
  38. }
  39. }
  40. TPSetup::
  41. ~TPSetup(
  42. VOID
  43. )
  44. {
  45. delete _pPSetup50;
  46. }
  47. BOOL
  48. TPSetup::
  49. bValid(
  50. VOID
  51. )
  52. {
  53. return _bValid;
  54. }
  55. /********************************************************************
  56. Member functions, most of these functions are just a channing
  57. call to the valid verion of the setup library.
  58. ********************************************************************/
  59. HDEVINFO
  60. TPSetup::
  61. PSetupCreatePrinterDeviceInfoList(
  62. IN HWND hwnd
  63. )
  64. {
  65. if( _pPSetup50 )
  66. {
  67. return _pPSetup50->PSetupCreatePrinterDeviceInfoList( hwnd );
  68. }
  69. return INVALID_HANDLE_VALUE;
  70. }
  71. VOID
  72. TPSetup::
  73. PSetupDestroyPrinterDeviceInfoList(
  74. IN HDEVINFO h
  75. )
  76. {
  77. if( _pPSetup50 )
  78. {
  79. _pPSetup50->PSetupDestroyPrinterDeviceInfoList( h );
  80. }
  81. }
  82. BOOL
  83. TPSetup::
  84. PSetupProcessPrinterAdded(
  85. IN HDEVINFO hDevInfo,
  86. IN HANDLE hLocalData,
  87. IN LPCTSTR pszPrinterName,
  88. IN HWND hwnd
  89. )
  90. {
  91. if( _pPSetup50 )
  92. {
  93. return _pPSetup50->PSetupProcessPrinterAdded( hDevInfo, (PPSETUP_LOCAL_DATA)hLocalData, pszPrinterName, hwnd );
  94. }
  95. return FALSE;
  96. }
  97. BOOL
  98. TPSetup::
  99. bGetSelectedDriverName(
  100. IN HANDLE hLocalData,
  101. IN OUT TString &strDriverName,
  102. IN PLATFORM platform
  103. ) const
  104. {
  105. if( _pPSetup50 )
  106. {
  107. TStatusB bStatus;
  108. DRIVER_FIELD DrvField;
  109. DrvField.Index = DRIVER_NAME;
  110. bStatus DBGCHK = _pPSetup50->PSetupGetLocalDataField( (PPSETUP_LOCAL_DATA)hLocalData, platform, &DrvField );
  111. if( bStatus )
  112. {
  113. bStatus DBGCHK = strDriverName.bUpdate( DrvField.pszDriverName );
  114. _pPSetup50->PSetupFreeDrvField( &DrvField );
  115. }
  116. return bStatus;
  117. }
  118. return NULL;
  119. }
  120. BOOL
  121. TPSetup::
  122. bGetSelectedPrintProcessorName(
  123. IN HANDLE hLocalData,
  124. IN OUT TString &strPrintProcessor,
  125. IN PLATFORM platform
  126. ) const
  127. {
  128. //
  129. // This is only supported on NT5 version.
  130. //
  131. if( _pPSetup50 )
  132. {
  133. TStatusB bStatus;
  134. DRIVER_FIELD DrvField;
  135. DrvField.Index = PRINT_PROCESSOR_NAME;
  136. bStatus DBGCHK = _pPSetup50->PSetupGetLocalDataField( (PPSETUP_LOCAL_DATA)hLocalData, platform, &DrvField );
  137. if( bStatus )
  138. {
  139. bStatus DBGCHK = strPrintProcessor.bUpdate( DrvField.pszPrintProc );
  140. _pPSetup50->PSetupFreeDrvField( &DrvField );
  141. }
  142. return bStatus;
  143. }
  144. return NULL;
  145. }
  146. BOOL
  147. TPSetup::
  148. bGetSelectedInfName(
  149. IN HANDLE hLocalData,
  150. IN OUT TString &strInfName,
  151. IN PLATFORM platform
  152. ) const
  153. {
  154. if( _pPSetup50 )
  155. {
  156. TStatusB bStatus;
  157. DRIVER_FIELD DrvField;
  158. DrvField.Index = INF_NAME;
  159. bStatus DBGCHK = _pPSetup50->PSetupGetLocalDataField( (PPSETUP_LOCAL_DATA)hLocalData, platform, &DrvField );
  160. if( bStatus )
  161. {
  162. bStatus DBGCHK = strInfName.bUpdate( DrvField.pszInfName );
  163. _pPSetup50->PSetupFreeDrvField( &DrvField );
  164. }
  165. return bStatus;
  166. }
  167. return NULL;
  168. }
  169. DWORD
  170. TPSetup::
  171. PSetupInstallPrinterDriver(
  172. IN HDEVINFO h,
  173. IN HANDLE hLocalData,
  174. IN LPCTSTR pszDriverName,
  175. IN PLATFORM platform,
  176. IN DWORD dwVersion,
  177. IN LPCTSTR pszServerName,
  178. IN HWND hwnd,
  179. IN LPCTSTR pszPlatformName,
  180. IN LPCTSTR pszSourcePath,
  181. IN DWORD dwInstallFlags,
  182. IN DWORD dwAddDrvFlags,
  183. OUT TString *pstrNewDriverName,
  184. IN BOOL bOfferReplacement
  185. )
  186. {
  187. DWORD dwRet = ERROR_INVALID_FUNCTION;
  188. if (_pPSetup50)
  189. {
  190. LPTSTR pszNewDriverName = NULL;
  191. PPSETUP_LOCAL_DATA pLocalData = (PPSETUP_LOCAL_DATA)hLocalData;
  192. if (!bOfferReplacement)
  193. {
  194. // request from ntprint to suppress the driver replacement offering
  195. dwInstallFlags |= DRVINST_DONT_OFFER_REPLACEMENT;
  196. }
  197. // call ntprint.dll ....
  198. dwRet = _pPSetup50->PSetupInstallPrinterDriver(h, pLocalData, pszDriverName, platform, dwVersion,
  199. pszServerName, hwnd, pszPlatformName, pszSourcePath, dwInstallFlags, dwAddDrvFlags, &pszNewDriverName);
  200. // check to return the replacement driver name (if any)
  201. if (ERROR_SUCCESS == dwRet && pszNewDriverName && pszNewDriverName[0] && pstrNewDriverName)
  202. {
  203. if (!pstrNewDriverName->bUpdate(pszNewDriverName))
  204. {
  205. dwRet = ERROR_OUTOFMEMORY;
  206. }
  207. }
  208. if (pszNewDriverName)
  209. {
  210. // free up the memory allocated from ntprint
  211. _pPSetup50->PSetupFreeMem(pszNewDriverName);
  212. }
  213. }
  214. return dwRet;
  215. }
  216. HANDLE
  217. TPSetup::
  218. PSetupGetSelectedDriverInfo(
  219. IN HDEVINFO h
  220. )
  221. {
  222. HANDLE hHandle = NULL;
  223. if( _pPSetup50 )
  224. hHandle = _pPSetup50->PSetupGetSelectedDriverInfo( h );
  225. return hHandle == NULL ? INVALID_HANDLE_VALUE : hHandle ;
  226. }
  227. HANDLE
  228. TPSetup::
  229. PSetupDriverInfoFromName(
  230. IN HDEVINFO h,
  231. IN LPCTSTR pszModel
  232. )
  233. {
  234. HANDLE hHandle = NULL;
  235. if( _pPSetup50 )
  236. hHandle = _pPSetup50->PSetupDriverInfoFromName( h, pszModel );
  237. return hHandle == NULL ? INVALID_HANDLE_VALUE : hHandle ;
  238. }
  239. VOID
  240. TPSetup::
  241. PSetupDestroySelectedDriverInfo(
  242. IN HANDLE hLocalData
  243. )
  244. {
  245. if( _pPSetup50 )
  246. {
  247. _pPSetup50->PSetupDestroySelectedDriverInfo( (PPSETUP_LOCAL_DATA)hLocalData );
  248. }
  249. }
  250. BOOL
  251. TPSetup::
  252. PSetupIsDriverInstalled(
  253. IN LPCTSTR pszServerName,
  254. IN LPCTSTR pszDriverName,
  255. IN PLATFORM platform,
  256. IN DWORD dwMajorVersion
  257. ) const
  258. {
  259. if( _pPSetup50 )
  260. {
  261. return _pPSetup50->PSetupIsDriverInstalled( pszServerName, pszDriverName, platform, dwMajorVersion );
  262. }
  263. return FALSE;
  264. }
  265. INT
  266. TPSetup::
  267. PSetupIsTheDriverFoundInInfInstalled(
  268. IN LPCTSTR pszServerName,
  269. IN HANDLE hLocalData,
  270. IN PLATFORM platform,
  271. IN DWORD dwMajorVersion,
  272. IN DWORD dwMajorVersion2
  273. ) const
  274. {
  275. if( _pPSetup50 )
  276. {
  277. return _pPSetup50->PSetupIsTheDriverFoundInInfInstalled( pszServerName, (PPSETUP_LOCAL_DATA)hLocalData, platform, dwMajorVersion2 );
  278. }
  279. return DRIVER_MODEL_NOT_INSTALLED;
  280. }
  281. BOOL
  282. TPSetup::
  283. PSetupSelectDriver(
  284. IN HDEVINFO h,
  285. IN HWND hwnd
  286. )
  287. {
  288. if( _pPSetup50 )
  289. return _pPSetup50->PSetupSelectDriver( h );
  290. return FALSE;
  291. }
  292. BOOL
  293. TPSetup::
  294. PSetupPreSelectDriver(
  295. IN HDEVINFO h,
  296. IN LPCTSTR pszManufacturer,
  297. IN LPCTSTR pszModel
  298. )
  299. {
  300. if( _pPSetup50 )
  301. return _pPSetup50->PSetupPreSelectDriver( h, pszManufacturer, pszModel );
  302. return FALSE;
  303. }
  304. HPROPSHEETPAGE
  305. TPSetup::
  306. PSetupCreateDrvSetupPage(
  307. IN HDEVINFO h,
  308. IN HWND hwnd
  309. )
  310. {
  311. if( _pPSetup50 )
  312. return _pPSetup50->PSetupCreateDrvSetupPage( h, hwnd );
  313. return NULL;
  314. }
  315. HANDLE
  316. TPSetup::
  317. PSetupCreateMonitorInfo(
  318. IN LPCTSTR pszServerName,
  319. IN HWND hwnd
  320. )
  321. {
  322. if( _pPSetup50 )
  323. return _pPSetup50->PSetupCreateMonitorInfo( hwnd, pszServerName);
  324. return NULL;
  325. }
  326. VOID
  327. TPSetup::
  328. PSetupDestroyMonitorInfo(
  329. IN OUT HANDLE h
  330. )
  331. {
  332. if( _pPSetup50 )
  333. _pPSetup50->PSetupDestroyMonitorInfo( h );
  334. }
  335. BOOL
  336. TPSetup::
  337. PSetupEnumMonitor(
  338. IN HANDLE h,
  339. IN DWORD dwIndex,
  340. OUT LPTSTR pMonitorName,
  341. IN OUT LPDWORD pdwSize
  342. )
  343. {
  344. if( _pPSetup50 )
  345. return _pPSetup50->PSetupEnumMonitor( h, dwIndex, pMonitorName, pdwSize );
  346. return FALSE;
  347. }
  348. BOOL
  349. TPSetup::
  350. PSetupInstallMonitor(
  351. IN HWND hwnd
  352. )
  353. {
  354. if( _pPSetup50 )
  355. return _pPSetup50->PSetupInstallMonitor( hwnd );
  356. return FALSE;
  357. }
  358. BOOL
  359. TPSetup::
  360. PSetupBuildDriversFromPath(
  361. IN HANDLE h,
  362. IN LPCTSTR pszDriverPath,
  363. IN BOOL bEnumSingleInf
  364. )
  365. {
  366. if( _pPSetup50 )
  367. return _pPSetup50->PSetupBuildDriversFromPath( h, pszDriverPath, bEnumSingleInf );
  368. return FALSE;
  369. }
  370. BOOL
  371. TPSetup::
  372. PSetupSetSelectDevTitleAndInstructions(
  373. IN HDEVINFO hDevInfo,
  374. IN LPCTSTR pszTitle,
  375. IN LPCTSTR pszSubTitle,
  376. IN LPCTSTR pszInstn
  377. )
  378. {
  379. if( _pPSetup50 )
  380. return _pPSetup50->PSetupSetSelectDevTitleAndInstructions( hDevInfo, pszTitle, pszSubTitle, pszInstn );
  381. return FALSE;
  382. }
  383. DWORD
  384. TPSetup::
  385. PSetupInstallPrinterDriverFromTheWeb(
  386. IN HDEVINFO hDevInfo,
  387. IN HANDLE pLocalData,
  388. IN PLATFORM platform,
  389. IN LPCTSTR pszServerName,
  390. IN LPOSVERSIONINFO pOsVersionInfo,
  391. IN HWND hwnd,
  392. IN LPCTSTR pszSource
  393. )
  394. {
  395. if( _pPSetup50 )
  396. return _pPSetup50->PSetupInstallPrinterDriverFromTheWeb( hDevInfo, (PPSETUP_LOCAL_DATA)pLocalData, platform, pszServerName, pOsVersionInfo, hwnd, pszSource );
  397. return ERROR_INVALID_FUNCTION;
  398. }
  399. BOOL
  400. TPSetup::
  401. PSetupSetWebMode(
  402. IN HDEVINFO hDevInfo,
  403. IN BOOL bWebButtonOn
  404. )
  405. {
  406. DWORD dwFlagsSet = bWebButtonOn ? SELECT_DEVICE_FROMWEB : 0;
  407. DWORD dwFlagsClear = bWebButtonOn ? 0 : SELECT_DEVICE_FROMWEB;
  408. if( _pPSetup50 )
  409. return _pPSetup50->PSetupSelectDeviceButtons( hDevInfo, dwFlagsSet, dwFlagsClear );
  410. return FALSE;
  411. }
  412. BOOL
  413. TPSetup::
  414. PSetupShowOem(
  415. IN HDEVINFO hDevInfo,
  416. IN BOOL bShowOem
  417. )
  418. {
  419. DWORD dwFlagsSet = bShowOem ? SELECT_DEVICE_HAVEDISK : 0;
  420. DWORD dwFlagsClear = bShowOem ? 0 : SELECT_DEVICE_HAVEDISK;
  421. if( _pPSetup50 )
  422. return _pPSetup50->PSetupSelectDeviceButtons( hDevInfo, dwFlagsSet, dwFlagsClear );
  423. return FALSE;
  424. }