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.

531 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. PSetupRefreshDriverList(
  295. IN HDEVINFO h
  296. )
  297. {
  298. if( _pPSetup50 )
  299. return _pPSetup50->PSetupRefreshDriverList( h );
  300. return FALSE;
  301. }
  302. BOOL
  303. TPSetup::
  304. PSetupPreSelectDriver(
  305. IN HDEVINFO h,
  306. IN LPCTSTR pszManufacturer,
  307. IN LPCTSTR pszModel
  308. )
  309. {
  310. if( _pPSetup50 )
  311. return _pPSetup50->PSetupPreSelectDriver( h, pszManufacturer, pszModel );
  312. return FALSE;
  313. }
  314. HPROPSHEETPAGE
  315. TPSetup::
  316. PSetupCreateDrvSetupPage(
  317. IN HDEVINFO h,
  318. IN HWND hwnd
  319. )
  320. {
  321. if( _pPSetup50 )
  322. return _pPSetup50->PSetupCreateDrvSetupPage( h, hwnd );
  323. return NULL;
  324. }
  325. HANDLE
  326. TPSetup::
  327. PSetupCreateMonitorInfo(
  328. IN LPCTSTR pszServerName,
  329. IN HWND hwnd
  330. )
  331. {
  332. if( _pPSetup50 )
  333. return _pPSetup50->PSetupCreateMonitorInfo( hwnd, pszServerName);
  334. return NULL;
  335. }
  336. VOID
  337. TPSetup::
  338. PSetupDestroyMonitorInfo(
  339. IN OUT HANDLE h
  340. )
  341. {
  342. if( _pPSetup50 )
  343. _pPSetup50->PSetupDestroyMonitorInfo( h );
  344. }
  345. BOOL
  346. TPSetup::
  347. PSetupEnumMonitor(
  348. IN HANDLE h,
  349. IN DWORD dwIndex,
  350. OUT LPTSTR pMonitorName,
  351. IN OUT LPDWORD pdwSize
  352. )
  353. {
  354. if( _pPSetup50 )
  355. return _pPSetup50->PSetupEnumMonitor( h, dwIndex, pMonitorName, pdwSize );
  356. return FALSE;
  357. }
  358. BOOL
  359. TPSetup::
  360. PSetupInstallMonitor(
  361. IN HWND hwnd
  362. )
  363. {
  364. if( _pPSetup50 )
  365. return _pPSetup50->PSetupInstallMonitor( hwnd );
  366. return FALSE;
  367. }
  368. BOOL
  369. TPSetup::
  370. PSetupBuildDriversFromPath(
  371. IN HANDLE h,
  372. IN LPCTSTR pszDriverPath,
  373. IN BOOL bEnumSingleInf
  374. )
  375. {
  376. if( _pPSetup50 )
  377. return _pPSetup50->PSetupBuildDriversFromPath( h, pszDriverPath, bEnumSingleInf );
  378. return FALSE;
  379. }
  380. BOOL
  381. TPSetup::
  382. PSetupSetSelectDevTitleAndInstructions(
  383. IN HDEVINFO hDevInfo,
  384. IN LPCTSTR pszTitle,
  385. IN LPCTSTR pszSubTitle,
  386. IN LPCTSTR pszInstn
  387. )
  388. {
  389. if( _pPSetup50 )
  390. return _pPSetup50->PSetupSetSelectDevTitleAndInstructions( hDevInfo, pszTitle, pszSubTitle, pszInstn );
  391. return FALSE;
  392. }
  393. DWORD
  394. TPSetup::
  395. PSetupInstallPrinterDriverFromTheWeb(
  396. IN HDEVINFO hDevInfo,
  397. IN HANDLE pLocalData,
  398. IN PLATFORM platform,
  399. IN LPCTSTR pszServerName,
  400. IN LPOSVERSIONINFO pOsVersionInfo,
  401. IN HWND hwnd,
  402. IN LPCTSTR pszSource
  403. )
  404. {
  405. if( _pPSetup50 )
  406. return _pPSetup50->PSetupInstallPrinterDriverFromTheWeb( hDevInfo, (PPSETUP_LOCAL_DATA)pLocalData, platform, pszServerName, pOsVersionInfo, hwnd, pszSource );
  407. return ERROR_INVALID_FUNCTION;
  408. }
  409. BOOL
  410. TPSetup::
  411. PSetupIsOemDriver(
  412. IN HDEVINFO hDevInfo,
  413. IN HANDLE pLocalData,
  414. IN OUT PBOOL pbIsOemDriver
  415. ) const
  416. {
  417. if( _pPSetup50 )
  418. return _pPSetup50->PSetupIsOemDriver( hDevInfo, (PPSETUP_LOCAL_DATA)pLocalData, pbIsOemDriver );
  419. SetLastError( ERROR_INVALID_FUNCTION );
  420. return FALSE;
  421. }
  422. BOOL
  423. TPSetup::
  424. PSetupSetWebMode(
  425. IN HDEVINFO hDevInfo,
  426. IN BOOL bWebButtonOn
  427. )
  428. {
  429. DWORD dwFlagsSet = bWebButtonOn ? SELECT_DEVICE_FROMWEB : 0;
  430. DWORD dwFlagsClear = bWebButtonOn ? 0 : SELECT_DEVICE_FROMWEB;
  431. if( _pPSetup50 )
  432. return _pPSetup50->PSetupSelectDeviceButtons( hDevInfo, dwFlagsSet, dwFlagsClear );
  433. return FALSE;
  434. }
  435. BOOL
  436. TPSetup::
  437. PSetupShowOem(
  438. IN HDEVINFO hDevInfo,
  439. IN BOOL bShowOem
  440. )
  441. {
  442. DWORD dwFlagsSet = bShowOem ? SELECT_DEVICE_HAVEDISK : 0;
  443. DWORD dwFlagsClear = bShowOem ? 0 : SELECT_DEVICE_HAVEDISK;
  444. if( _pPSetup50 )
  445. return _pPSetup50->PSetupSelectDeviceButtons( hDevInfo, dwFlagsSet, dwFlagsClear );
  446. return FALSE;
  447. }