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.

616 lines
14 KiB

  1. //=================================================================
  2. //
  3. // WinSpoolApi.cpp
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <cominit.h>
  10. #include "DllWrapperBase.h"
  11. #include "WinSpoolApi.h"
  12. #include "DllWrapperCreatorReg.h"
  13. // {77609C22-CDAA-11d2-911E-0060081A46FD}
  14. static const GUID g_guidWinSpoolApi =
  15. { 0x3b8515f1, 0xefd, 0x11d3, { 0x91, 0xc, 0x0, 0x10, 0x5a, 0xa6, 0x30, 0xbe } };
  16. static const TCHAR g_tstrWinSpool[] = _T("WinSpool.Drv");
  17. /******************************************************************************
  18. * Register this class with the CResourceManager.
  19. *****************************************************************************/
  20. CDllApiWraprCreatrReg<CWinSpoolApi, &g_guidWinSpoolApi, g_tstrWinSpool> MyRegisteredWinSpoolWrapper;
  21. /******************************************************************************
  22. * Constructor
  23. *****************************************************************************/
  24. CWinSpoolApi::CWinSpoolApi(LPCTSTR a_tstrWrappedDllName)
  25. : CDllWrapperBase(a_tstrWrappedDllName),
  26. m_pfnClosePrinter (NULL),
  27. m_pfnDeviceCapabilities (NULL),
  28. m_pfnDocumentProperties (NULL),
  29. m_pfnEnumJobs (NULL),
  30. m_pfnEnumPrinterDrivers (NULL),
  31. m_pfnEnumPrinters (NULL),
  32. m_pfnEnumPorts (NULL),
  33. m_pfnGetJob (NULL),
  34. m_pfnGetPrinter (NULL),
  35. m_pfnGetPrinterDriver (NULL),
  36. m_pfnSetPrinter (NULL),
  37. m_pfnOpenPrinter (NULL),
  38. m_pfnGetDefaultPrinter(NULL),
  39. m_hPrintMutex(NULL),
  40. m_pfnSetJob (NULL),
  41. m_pfnDeletePrinter (NULL),
  42. m_pfnSetDefaultPrinter(NULL)
  43. #if NTONLY >= 5
  44. ,
  45. m_pfnXcvData(NULL),
  46. m_pfnAddPrinterConnection(NULL),
  47. m_pfnDeletePrinterConnection(NULL)
  48. #endif
  49. {
  50. #ifdef WIN9XONLY
  51. m_hPrintMutex = ::CreateMutex( NULL, FALSE, PRINTER_NAMED_MUTEX ) ;
  52. #endif
  53. }
  54. /******************************************************************************
  55. * Destructor
  56. *****************************************************************************/
  57. CWinSpoolApi::~CWinSpoolApi()
  58. {
  59. #ifdef WIN9XONLY
  60. if( m_hPrintMutex )
  61. {
  62. ReleaseMutex( m_hPrintMutex ) ;
  63. }
  64. #endif
  65. }
  66. /******************************************************************************
  67. * Initialization function to check that we obtained function addresses.
  68. ******************************************************************************/
  69. bool CWinSpoolApi::Init()
  70. {
  71. bool fRet = LoadLibrary();
  72. if(fRet)
  73. {
  74. #ifdef UNICODE
  75. m_pfnClosePrinter = ( PFN_WinSpool_ClosePrinter ) GetProcAddress ( "ClosePrinter" ) ;
  76. m_pfnDeviceCapabilities = ( PFN_WinSpool_DeviceCapabilities ) GetProcAddress ( "DeviceCapabilitiesW" ) ;
  77. m_pfnDocumentProperties = ( PFN_WinSpool_DocumentProperties ) GetProcAddress ( "DocumentPropertiesW" ) ;
  78. m_pfnEnumJobs = ( PFN_WinSpool_EnumJobs ) GetProcAddress ( "EnumJobsW" ) ;
  79. m_pfnEnumPrinterDrivers = ( PFN_WinSpool_EnumPrinterDrivers ) GetProcAddress ( "EnumPrinterDriversW" ) ;
  80. m_pfnEnumPrinters = ( PFN_WinSpool_EnumPrinters ) GetProcAddress ( "EnumPrintersW" ) ;
  81. m_pfnEnumPorts = ( PFN_WinSpool_EnumPorts ) GetProcAddress ( "EnumPortsW" ) ;
  82. m_pfnGetJob = ( PFN_WinSpool_GetJob ) GetProcAddress ( "GetJobW" ) ;
  83. m_pfnGetPrinter = ( PFN_WinSpool_GetPrinter ) GetProcAddress ( "GetPrinterW" ) ;
  84. m_pfnGetPrinterDriver = ( PFN_WinSpool_GetPrinterDriver ) GetProcAddress ( "GetPrinterDriverW" ) ;
  85. m_pfnSetPrinter = ( PFN_WinSpool_SetPrinter ) GetProcAddress ( "SetPrinterW" ) ;
  86. m_pfnOpenPrinter = ( PFN_WinSpool_OpenPrinter ) GetProcAddress ( "OpenPrinterW" ) ;
  87. m_pfnSetJob = ( PFN_WinSpool_SetJob ) GetProcAddress ( "SetJobW" );
  88. m_pfnDeletePrinter = ( PFN_WinSpool_DeletePrinter ) GetProcAddress ( "DeletePrinter" );
  89. #if NTONLY == 5
  90. m_pfnGetDefaultPrinter = ( PFN_WinSpool_GetDefaultPrinter ) GetProcAddress ( "GetDefaultPrinterW" ) ;
  91. m_pfnSetDefaultPrinter = ( PFN_WinSpool_SetDefaultPrinter ) GetProcAddress ( "SetDefaultPrinterW" ) ;
  92. m_pfnXcvData = ( PFN_WinSpool_XcvData ) GetProcAddress ( "XcvDataW" ) ;
  93. m_pfnAddPrinterConnection = ( PFN_WinSpool_AddPrinterConnection) GetProcAddress ( "AddPrinterConnectionW" );
  94. m_pfnDeletePrinterConnection = ( PFN_WinSpool_DeletePrinterConnection) GetProcAddress ( "DeletePrinterConnectionW" );
  95. #endif
  96. #else
  97. m_pfnClosePrinter = ( PFN_WinSpool_ClosePrinter ) GetProcAddress ( "ClosePrinter" ) ;
  98. m_pfnDeviceCapabilities = ( PFN_WinSpool_DeviceCapabilities ) GetProcAddress ( "DeviceCapabilitiesA" ) ;
  99. m_pfnDocumentProperties = ( PFN_WinSpool_DocumentProperties ) GetProcAddress ( "DocumentPropertiesA" ) ;
  100. m_pfnEnumJobs = ( PFN_WinSpool_EnumJobs ) GetProcAddress ( "EnumJobsA" ) ;
  101. m_pfnEnumPrinterDrivers = ( PFN_WinSpool_EnumPrinterDrivers ) GetProcAddress ( "EnumPrinterDriversA" ) ;
  102. m_pfnEnumPrinters = ( PFN_WinSpool_EnumPrinters ) GetProcAddress ( "EnumPrintersA" ) ;
  103. m_pfnEnumPorts = ( PFN_WinSpool_EnumPorts ) GetProcAddress ( "EnumPortsA" ) ;
  104. m_pfnGetJob = ( PFN_WinSpool_GetJob ) GetProcAddress ( "GetJobA" ) ;
  105. m_pfnGetPrinter = ( PFN_WinSpool_GetPrinter ) GetProcAddress ( "GetPrinterA" ) ;
  106. m_pfnGetPrinterDriver = ( PFN_WinSpool_GetPrinterDriver ) GetProcAddress ( "GetPrinterDriverA" ) ;
  107. m_pfnSetPrinter = ( PFN_WinSpool_SetPrinter ) GetProcAddress ( "SetPrinterA" ) ;
  108. m_pfnOpenPrinter = ( PFN_WinSpool_OpenPrinter ) GetProcAddress ( "OpenPrinterA" ) ;
  109. m_pfnSetJob = ( PFN_WinSpool_SetJob ) GetProcAddress ( "SetJobA" );
  110. m_pfnDeletePrinter = ( PFN_WinSpool_DeletePrinter ) GetProcAddress ( "DeletePrinter" );
  111. #endif
  112. }
  113. // We require these function for all versions of this dll.
  114. #if NTONLY == 5
  115. if ( m_pfnClosePrinter == NULL ||
  116. m_pfnDeviceCapabilities == NULL ||
  117. m_pfnDocumentProperties == NULL ||
  118. m_pfnEnumJobs == NULL ||
  119. m_pfnEnumPrinterDrivers == NULL ||
  120. m_pfnEnumPrinters == NULL ||
  121. m_pfnEnumPorts == NULL ||
  122. m_pfnGetJob == NULL ||
  123. m_pfnGetPrinter == NULL ||
  124. m_pfnGetPrinterDriver == NULL ||
  125. m_pfnSetPrinter == NULL ||
  126. m_pfnOpenPrinter == NULL ||
  127. m_pfnGetDefaultPrinter == NULL ||
  128. m_pfnSetJob == NULL ||
  129. m_pfnDeletePrinter == NULL ||
  130. m_pfnSetDefaultPrinter == NULL ||
  131. m_pfnXcvData == NULL ||
  132. m_pfnAddPrinterConnection == NULL||
  133. m_pfnDeletePrinterConnection == NULL )
  134. {
  135. fRet = false;
  136. LogErrorMessage(L"Failed find entrypoint in winspoolapi");
  137. }
  138. #else
  139. if ( m_pfnClosePrinter == NULL ||
  140. m_pfnDeviceCapabilities == NULL ||
  141. m_pfnDocumentProperties == NULL ||
  142. m_pfnEnumJobs == NULL ||
  143. m_pfnEnumPrinterDrivers == NULL ||
  144. m_pfnEnumPrinters == NULL ||
  145. m_pfnEnumPorts == NULL ||
  146. m_pfnGetJob == NULL ||
  147. m_pfnGetPrinter == NULL ||
  148. m_pfnGetPrinterDriver == NULL ||
  149. m_pfnSetPrinter == NULL ||
  150. m_pfnOpenPrinter == NULL ||
  151. m_pfnSetJob == NULL ||
  152. m_pfnDeletePrinter == NULL )
  153. {
  154. fRet = false;
  155. LogErrorMessage(L"Failed find entrypoint in winspoolapi");
  156. }
  157. #endif
  158. return fRet;
  159. }
  160. /******************************************************************************
  161. * Member functions wrapping WinSpool api functions. Add new functions here
  162. * as required.
  163. *****************************************************************************/
  164. BOOL CWinSpoolApi :: ClosePrinter (
  165. IN HANDLE hPrinter
  166. )
  167. {
  168. LOCK_WINSPOOL_9X ;
  169. return m_pfnClosePrinter ( hPrinter ) ;
  170. }
  171. #ifdef UNICODE
  172. int CWinSpoolApi :: DeviceCapabilities (
  173. IN LPCWSTR pDevice ,
  174. IN LPCWSTR pPort,
  175. IN WORD fwCapability ,
  176. OUT LPWSTR pOutput ,
  177. IN CONST DEVMODEW *pDevMode
  178. )
  179. #else
  180. int CWinSpoolApi :: DeviceCapabilities (
  181. IN LPCSTR pDevice ,
  182. IN LPCSTR pPort,
  183. IN WORD fwCapability ,
  184. OUT LPCSTR pOutput,
  185. IN CONST DEVMODEA *pDevMode
  186. )
  187. #endif
  188. {
  189. LOCK_WINSPOOL_9X ;
  190. return m_pfnDeviceCapabilities (
  191. pDevice ,
  192. pPort,
  193. fwCapability ,
  194. pOutput,
  195. pDevMode
  196. ) ;
  197. }
  198. #ifdef UNICODE
  199. LONG CWinSpoolApi :: DocumentProperties (
  200. IN HWND hWnd,
  201. IN HANDLE hPrinter,
  202. IN LPWSTR pDeviceName,
  203. OUT PDEVMODEW pDevModeOutput,
  204. IN PDEVMODEW pDevModeInput,
  205. IN DWORD fMode
  206. )
  207. #else
  208. LONG CWinSpoolApi :: DocumentProperties (
  209. IN HWND hWnd,
  210. IN HANDLE hPrinter,
  211. IN LPSTR pDeviceName,
  212. OUT PDEVMODEA pDevModeOutput,
  213. IN PDEVMODEA pDevModeInput,
  214. IN DWORD fMode
  215. )
  216. #endif
  217. {
  218. LOCK_WINSPOOL_9X ;
  219. return m_pfnDocumentProperties (
  220. hWnd,
  221. hPrinter,
  222. pDeviceName,
  223. pDevModeOutput,
  224. pDevModeInput,
  225. fMode
  226. ) ;
  227. }
  228. BOOL CWinSpoolApi :: EnumJobs (
  229. IN HANDLE hPrinter,
  230. IN DWORD FirstJob,
  231. IN DWORD NoJobs,
  232. IN DWORD Level,
  233. OUT LPBYTE pJob,
  234. IN DWORD cbBuf,
  235. OUT LPDWORD pcbNeeded,
  236. OUT LPDWORD pcReturned
  237. )
  238. {
  239. LOCK_WINSPOOL_9X ;
  240. return m_pfnEnumJobs (
  241. hPrinter,
  242. FirstJob,
  243. NoJobs,
  244. Level,
  245. pJob,
  246. cbBuf,
  247. pcbNeeded,
  248. pcReturned
  249. ) ;
  250. }
  251. #ifdef UNICODE
  252. BOOL CWinSpoolApi :: EnumPrinterDrivers (
  253. IN LPWSTR pName,
  254. IN LPWSTR pEnvironment,
  255. IN DWORD Level,
  256. OUT LPBYTE pDriverInfo,
  257. IN DWORD cbBuf,
  258. OUT LPDWORD pcbNeeded,
  259. OUT LPDWORD pcReturned
  260. )
  261. #else
  262. BOOL CWinSpoolApi :: EnumPrinterDrivers (
  263. IN LPSTR pName,
  264. IN LPSTR pEnvironment,
  265. IN DWORD Level,
  266. OUT LPBYTE pDriverInfo,
  267. IN DWORD cbBuf,
  268. OUT LPDWORD pcbNeeded,
  269. OUT LPDWORD pcReturned
  270. )
  271. #endif
  272. {
  273. LOCK_WINSPOOL_9X ;
  274. return m_pfnEnumPrinterDrivers (
  275. pName,
  276. pEnvironment,
  277. Level,
  278. pDriverInfo,
  279. cbBuf,
  280. pcbNeeded,
  281. pcReturned
  282. ) ;
  283. }
  284. #ifdef UNICODE
  285. BOOL CWinSpoolApi :: EnumPrinters (
  286. IN DWORD Flags,
  287. IN LPWSTR Name,
  288. IN DWORD Level,
  289. OUT LPBYTE pPrinterEnum,
  290. IN DWORD cbBuf,
  291. OUT LPDWORD pcbNeeded,
  292. OUT LPDWORD pcReturned
  293. )
  294. #else
  295. BOOL CWinSpoolApi :: EnumPrinters (
  296. IN DWORD Flags,
  297. IN LPSTR Name,
  298. IN DWORD Level,
  299. OUT LPBYTE pPrinterEnum,
  300. IN DWORD cbBuf,
  301. OUT LPDWORD pcbNeeded,
  302. OUT LPDWORD pcReturned
  303. )
  304. #endif
  305. {
  306. LOCK_WINSPOOL_9X ;
  307. return m_pfnEnumPrinters (
  308. Flags,
  309. Name,
  310. Level,
  311. pPrinterEnum,
  312. cbBuf,
  313. pcbNeeded,
  314. pcReturned
  315. ) ;
  316. }
  317. #ifdef UNICODE
  318. BOOL CWinSpoolApi :: EnumPorts (
  319. IN LPWSTR Name,
  320. IN DWORD Level,
  321. OUT LPBYTE pPortEnum,
  322. IN DWORD cbBuf,
  323. OUT LPDWORD pcbNeeded,
  324. OUT LPDWORD pcReturned
  325. )
  326. #else
  327. BOOL CWinSpoolApi :: EnumPorts (
  328. IN LPSTR Name,
  329. IN DWORD Level,
  330. OUT LPBYTE pPortEnum,
  331. IN DWORD cbBuf,
  332. OUT LPDWORD pcbNeeded,
  333. OUT LPDWORD pcReturned
  334. )
  335. #endif
  336. {
  337. LOCK_WINSPOOL_9X ;
  338. return m_pfnEnumPorts (
  339. Name,
  340. Level,
  341. pPortEnum,
  342. cbBuf,
  343. pcbNeeded,
  344. pcReturned
  345. ) ;
  346. }
  347. BOOL CWinSpoolApi :: GetJob (
  348. IN HANDLE hPrinter,
  349. IN DWORD JobId,
  350. IN DWORD Level,
  351. OUT LPBYTE pJob,
  352. IN DWORD cbBuf,
  353. OUT LPDWORD pcbNeeded
  354. )
  355. {
  356. LOCK_WINSPOOL_9X ;
  357. return m_pfnGetJob (
  358. hPrinter,
  359. JobId,
  360. Level,
  361. pJob,
  362. cbBuf,
  363. pcbNeeded
  364. ) ;
  365. }
  366. BOOL CWinSpoolApi :: SetJob (
  367. IN HANDLE hPrinter,
  368. IN DWORD JobId,
  369. IN DWORD Level,
  370. IN LPBYTE pJob,
  371. IN DWORD cbBuf
  372. )
  373. {
  374. LOCK_WINSPOOL_9X ;
  375. return m_pfnSetJob (
  376. hPrinter,
  377. JobId,
  378. Level,
  379. pJob,
  380. cbBuf
  381. ) ;
  382. }
  383. BOOL CWinSpoolApi :: GetPrinter (
  384. IN HANDLE hPrinter,
  385. IN DWORD Level,
  386. OUT LPBYTE pPrinter,
  387. IN DWORD cbBuf,
  388. OUT LPDWORD pcbNeeded
  389. )
  390. {
  391. LOCK_WINSPOOL_9X ;
  392. return m_pfnGetPrinter(
  393. hPrinter,
  394. Level,
  395. pPrinter,
  396. cbBuf,
  397. pcbNeeded
  398. ) ;
  399. }
  400. BOOL CWinSpoolApi :: GetPrinterDriver (
  401. IN HANDLE hPrinter,
  402. IN LPTSTR pEnvironment,
  403. IN DWORD Level,
  404. OUT LPBYTE pPrinter,
  405. IN DWORD cbBuf,
  406. OUT LPDWORD pcbNeeded
  407. )
  408. {
  409. LOCK_WINSPOOL_9X ;
  410. return m_pfnGetPrinterDriver(
  411. hPrinter,
  412. pEnvironment,
  413. Level,
  414. pPrinter,
  415. cbBuf,
  416. pcbNeeded
  417. ) ;
  418. }
  419. BOOL CWinSpoolApi :: SetPrinter (
  420. IN HANDLE hPrinter,
  421. IN DWORD Level,
  422. IN LPBYTE pPrinter,
  423. IN DWORD cbBuf
  424. )
  425. {
  426. LOCK_WINSPOOL_9X ;
  427. return m_pfnSetPrinter(
  428. hPrinter,
  429. Level,
  430. pPrinter,
  431. cbBuf
  432. ) ;
  433. }
  434. BOOL CWinSpoolApi :: DeletePrinter (
  435. IN HANDLE hPrinter
  436. )
  437. {
  438. LOCK_WINSPOOL_9X ;
  439. return m_pfnDeletePrinter(
  440. hPrinter
  441. ) ;
  442. }
  443. #ifdef UNICODE
  444. BOOL CWinSpoolApi :: OpenPrinter (
  445. IN LPWSTR pPrinterName,
  446. OUT LPHANDLE phPrinter,
  447. IN LPPRINTER_DEFAULTSW pDefault
  448. )
  449. #else
  450. BOOL CWinSpoolApi :: OpenPrinter (
  451. IN LPSTR pPrinterName,
  452. OUT LPHANDLE phPrinter,
  453. IN LPPRINTER_DEFAULTSA pDefault
  454. )
  455. #endif
  456. {
  457. LOCK_WINSPOOL_9X ;
  458. return m_pfnOpenPrinter(
  459. pPrinterName,
  460. phPrinter,
  461. pDefault
  462. ) ;
  463. }
  464. BOOL CWinSpoolApi :: GetDefaultPrinter (
  465. IN LPTSTR pszBuffer,
  466. IN LPDWORD pcchBuffer
  467. )
  468. {
  469. LOCK_WINSPOOL_9X ;
  470. return m_pfnGetDefaultPrinter(
  471. pszBuffer,
  472. pcchBuffer
  473. ) ;
  474. }
  475. BOOL CWinSpoolApi :: SetDefaultPrinter (
  476. IN LPTSTR pszBuffer
  477. )
  478. {
  479. LOCK_WINSPOOL_9X ;
  480. return m_pfnSetDefaultPrinter(
  481. pszBuffer
  482. ) ;
  483. }
  484. #if NTONLY >= 5
  485. BOOL CWinSpoolApi :: XcvData (
  486. IN HANDLE hXcv,
  487. IN PCWSTR pszDataName,
  488. IN PBYTE pInputData,
  489. IN DWORD cbInputData,
  490. OUT PBYTE pOutputData,
  491. IN DWORD cbOutputData,
  492. OUT PDWORD pcbOutputNeeded,
  493. OUT PDWORD pdwStatus
  494. )
  495. {
  496. return m_pfnXcvData(hXcv,
  497. pszDataName,
  498. pInputData,
  499. cbInputData,
  500. pOutputData,
  501. cbOutputData,
  502. pcbOutputNeeded,
  503. pdwStatus);
  504. }
  505. BOOL CWinSpoolApi :: AddPrinterConnection(
  506. IN LPWSTR pszBuffer
  507. )
  508. {
  509. return m_pfnAddPrinterConnection(pszBuffer);
  510. }
  511. BOOL CWinSpoolApi :: DeletePrinterConnection(
  512. IN LPWSTR pszBuffer
  513. )
  514. {
  515. return m_pfnDeletePrinterConnection(pszBuffer);
  516. }
  517. #endif