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.

515 lines
14 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. prntuifn.cxx
  6. Abstract:
  7. This file contains the implementation for the Print UI
  8. class
  9. Author:
  10. Khaled Sedky (khaleds) 31-Jan-2000
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #ifndef __PRNTUIFN_HPP__
  16. #include "prntuifn.hpp"
  17. #endif
  18. #ifndef __LDFUNCS_HPP__
  19. #include "ldfuncs.hpp"
  20. #endif
  21. #ifndef __LDMGR_HPP__
  22. #include "ldmgr.hpp"
  23. #endif
  24. /* --------------------------------- */
  25. /* Implemetation of class TPrintUIMgr */
  26. /* --------------------------------- */
  27. /*++
  28. Function Name:
  29. TPrintUIMgr :: TPrintUIMgr
  30. Description:
  31. Contructor of Print UI functions intstatiation
  32. object
  33. Parameters:
  34. None
  35. Return Value:
  36. None
  37. --*/
  38. TPrintUIMgr ::
  39. TPrintUIMgr(
  40. IN TLoad64BitDllsMgr* pIpLdrObj
  41. ) :
  42. m_pLdrObj(pIpLdrObj),
  43. TClassID("TPrintUIMgr")
  44. {
  45. m_pLdrObj->AddRef();
  46. }
  47. /*++
  48. Function Name:
  49. TPrintUIMgr :: ~TPrintUIMgr
  50. Description:
  51. Destructor of Print UI functions intstatiation
  52. object
  53. Parameters:
  54. None
  55. Return Value:
  56. None
  57. --*/
  58. TPrintUIMgr ::
  59. ~TPrintUIMgr()
  60. {
  61. m_pLdrObj->Release();
  62. }
  63. /*++
  64. Function Name:
  65. TPrintUIMgr :: QueueCreate
  66. Description:
  67. Creates a printer queue
  68. Parameters:
  69. hWnd : Parent hwnd.
  70. PrinterName : Printer name.
  71. CmdShow : Show command.
  72. lParam : currently unused.
  73. Return Value:
  74. DWORD : Error Code in case of Failure
  75. ERROR_SUCCESS in case of success
  76. --*/
  77. DWORD
  78. TPrintUIMgr ::
  79. QueueCreate(
  80. IN HWND hWnd,
  81. IN LPCWSTR pszPrinterName,
  82. IN INT CmdShow,
  83. IN LPARAM lParam
  84. )
  85. {
  86. return PrintUIMethod("vQueueCreate",
  87. hWnd,
  88. pszPrinterName,
  89. CmdShow,
  90. lParam,
  91. AsyncPrintUIMethod,
  92. TPrintUIMgr::KQueueCreateOp);
  93. }
  94. /*++
  95. Function Name:
  96. TPrintUIMgr :: PrinterPropPages
  97. Description:
  98. This function opens the property sheet of specified printer.
  99. Parameters:
  100. hWnd : Parent hwnd.
  101. PrinterName : Printer name.
  102. CmdShow : Show command.
  103. lParam : currently unused.
  104. Return Value:
  105. DWORD : Error Code in case of Failure
  106. ERROR_SUCCESS in case of success
  107. --*/
  108. DWORD
  109. TPrintUIMgr ::
  110. PrinterPropPages(
  111. IN HWND hWnd,
  112. IN LPCWSTR pszPrinterName,
  113. IN INT CmdShow,
  114. IN LPARAM lParam
  115. )
  116. {
  117. return PrintUIMethod("vPrinterPropPages",
  118. hWnd,
  119. pszPrinterName,
  120. CmdShow,
  121. lParam,
  122. AsyncPrintUIMethod,
  123. TPrintUIMgr::KPrinterPropPagesOp);
  124. }
  125. /*++
  126. Function Name:
  127. TPrintUIMgr :: DocumentDefaults
  128. Description:
  129. Bring up document defaults
  130. Parameters:
  131. hWnd : Parent hwnd.
  132. PrinterName : Printer name.
  133. CmdShow : Show command.
  134. lParam : currently unused.
  135. Return Value:
  136. DWORD : Error Code in case of Failure
  137. ERROR_SUCCESS in case of success
  138. --*/
  139. DWORD
  140. TPrintUIMgr ::
  141. DocumentDefaults(
  142. IN HWND hWnd,
  143. IN LPCWSTR pszPrinterName,
  144. IN INT CmdShow,
  145. IN LPARAM lParam
  146. )
  147. {
  148. return PrintUIMethod("vDocumentDefaults",
  149. hWnd,
  150. pszPrinterName,
  151. CmdShow,
  152. lParam,
  153. AsyncPrintUIMethod,
  154. TPrintUIMgr::KDocumentDefaultsOp);
  155. }
  156. /*++
  157. Function Name:
  158. TPrintUIMgr :: PrintUIMethod
  159. Description:
  160. Disptach the appropriate print UI method in
  161. a separate thread
  162. Parameters:
  163. Method : Name of Method to be instantiated
  164. hWnd : Parent hwnd.
  165. PrinterName : Printer name.
  166. CmdShow : Show command.
  167. lParam : currently unused.
  168. pThrdFn : Pointer to the Print UI method
  169. Op : requested Print UI operation
  170. Return Value:
  171. DWORD : Error Code in case of Failure
  172. ERROR_SUCCESS in case of success
  173. --*/
  174. DWORD
  175. TPrintUIMgr ::
  176. PrintUIMethod(
  177. IN LPCSTR Method,
  178. IN HWND hWnd,
  179. IN LPCWSTR pszName,
  180. IN INT CmdShow,
  181. IN LPARAM lParam,
  182. IN LPTHREAD_START_ROUTINE pThrdFn,
  183. IN TPrintUIMgr::EPrintUIOp Op
  184. )
  185. {
  186. DWORD ErrorCode = ERROR_SUCCESS;
  187. HANDLE hPrintUI = NULL;
  188. PFNPRINTUIMETHOD pfn;
  189. RPC_STATUS RpcStatus;
  190. SPLASSERT(m_pLdrObj);
  191. if((RpcStatus = RpcImpersonateClient(0)) == RPC_S_OK)
  192. {
  193. m_pLdrObj->RefreshLifeSpan();
  194. if(hPrintUI = LoadLibrary(L"printui.dll"))
  195. {
  196. if(pfn = reinterpret_cast<PFNPRINTUIMETHOD>(GetProcAddress(hPrintUI,Method)))
  197. {
  198. SPrintUIThreadData* pNewThrdData = new SPrintUIThreadData;
  199. if(pNewThrdData)
  200. {
  201. HANDLE hPrintUIMethodThrd;
  202. DWORD PrintUIThrdId;
  203. pNewThrdData->hWnd = hWnd;
  204. pNewThrdData->pszName = pszName;
  205. pNewThrdData->CmdShow = CmdShow;
  206. pNewThrdData->lParam = lParam;
  207. pNewThrdData->hLib = hPrintUI;
  208. pNewThrdData->pLdrObj = m_pLdrObj;
  209. pNewThrdData->pfn = pfn;
  210. pNewThrdData->Op = Op;
  211. if(hPrintUIMethodThrd = CreateThread(NULL,
  212. 0,
  213. pThrdFn,
  214. (PVOID)pNewThrdData,
  215. 0,
  216. &PrintUIThrdId))
  217. {
  218. CloseHandle(hPrintUIMethodThrd);
  219. }
  220. else
  221. {
  222. ErrorCode = GetLastError();
  223. delete pNewThrdData;
  224. }
  225. }
  226. else
  227. {
  228. ErrorCode = ERROR_OUTOFMEMORY;
  229. }
  230. }
  231. else
  232. {
  233. ErrorCode = GetLastError();
  234. }
  235. }
  236. else
  237. {
  238. ErrorCode = GetLastError();
  239. }
  240. RpcStatus = RpcRevertToSelf();
  241. }
  242. else
  243. {
  244. ErrorCode = RpcStatus;
  245. }
  246. return ErrorCode;
  247. }
  248. /*++
  249. Function Name:
  250. TPrintUIMgr :: AsyncPrintUIMethod
  251. Description:
  252. The PrintUI method running in a separate thread
  253. Parameters:
  254. hWnd : Parent hwnd.
  255. PrinterName : Printer name.
  256. CmdShow : Show command.
  257. lParam : currently unused.
  258. Return Value:
  259. Always 0
  260. --*/
  261. DWORD
  262. TPrintUIMgr ::
  263. AsyncPrintUIMethod(
  264. IN PVOID pInThrdData
  265. )
  266. {
  267. UINT msg;
  268. SPrintUIThreadData* pNewThreadData = reinterpret_cast<SPrintUIThreadData *>(pInThrdData);
  269. pNewThreadData->pLdrObj->IncUIRefCnt();
  270. {
  271. __try
  272. {
  273. pNewThreadData->pfn(pNewThreadData->hWnd,
  274. pNewThreadData->pszName,
  275. pNewThreadData->CmdShow,
  276. pNewThreadData->lParam);
  277. }
  278. __except(1)
  279. {
  280. DWORD ExcpVal = pNewThreadData->pLdrObj->TranslateExceptionCode(RpcExceptionCode());
  281. DBGMSG(DBG_WARN,
  282. ("TPrintUIMgr::AsyncPrintUIMethod failed in calling printui with an exception %u",ExcpVal));
  283. SetLastError(ExcpVal);
  284. }
  285. }
  286. pNewThreadData->pLdrObj->DecUIRefCnt();
  287. //
  288. // Here we should post a message to the caller client window to inform
  289. // it that the operation was completed and also whether it was succesful
  290. // or not
  291. //
  292. switch(pNewThreadData->Op)
  293. {
  294. case TPrintUIMgr::KQueueCreateOp:
  295. {
  296. msg = WM_ENDQUEUECREATE;
  297. break;
  298. }
  299. case TPrintUIMgr::KPrinterPropPagesOp:
  300. {
  301. msg = WM_ENDPRINTERPROPPAGES;
  302. break;
  303. }
  304. case TPrintUIMgr::KDocumentDefaultsOp:
  305. {
  306. msg = WM_ENDDOCUMENTDEFAULTS;
  307. break;
  308. }
  309. case TPrintUIMgr::KServerPropPagesOp:
  310. {
  311. msg = WM_ENDSERVERPROPPAGES;
  312. break;
  313. }
  314. }
  315. PostMessage(pNewThreadData->hWnd,msg,
  316. (WPARAM)0,
  317. (LPARAM)0);
  318. //
  319. // Cleanup code
  320. //
  321. FreeLibrary(pNewThreadData->hLib);
  322. delete pInThrdData;
  323. return 0;
  324. }
  325. /*++
  326. Function Name:
  327. TPrintUIMgr :: PrinterSetup
  328. Description:
  329. Brings up the install printer wizard.
  330. Parameters:
  331. hwnd - Parent window.
  332. uAction - Action requested (defined in windows\inc16\msprintx.h)
  333. cchPrinterName - Length of pszPrinterName buffer.
  334. pszPrinterName - Input setup printer name, Output pointer to new printer name
  335. pcchPrinterName - New length of pszPrinterName on return.
  336. pszServerName - Name of server that printer is on.
  337. Return Value:
  338. DWORD : Error Code in case of Failure
  339. ERROR_SUCCESS in case of success
  340. --*/
  341. DWORD
  342. TPrintUIMgr ::
  343. PrinterSetup(
  344. IN HWND hWnd,
  345. IN UINT uAction,
  346. IN UINT cchPrinterName,
  347. IN OUT LPWSTR pszPrinterName,
  348. OUT UINT* pcchPrinterName,
  349. IN LPCWSTR pszServerName
  350. )
  351. {
  352. DWORD ErrorCode = ERROR_SUCCESS;
  353. HANDLE hPrintUI = NULL;
  354. BOOL bRetVal = FALSE;
  355. PFNPRINTUIPRINTERSETUP pfn = NULL;
  356. UINT msg;
  357. SPLASSERT(m_pLdrObj);
  358. m_pLdrObj->RefreshLifeSpan();
  359. if(hPrintUI = LoadLibrary(L"printui.dll"))
  360. {
  361. if(pfn = reinterpret_cast<PFNPRINTUIPRINTERSETUP>(GetProcAddress(hPrintUI,"bPrinterSetup")))
  362. {
  363. m_pLdrObj->IncUIRefCnt();
  364. {
  365. __try
  366. {
  367. bRetVal = pfn(hWnd,
  368. uAction,
  369. cchPrinterName,
  370. pszPrinterName,
  371. pcchPrinterName,
  372. pszServerName);
  373. ErrorCode = GetLastError();
  374. }
  375. __except(1)
  376. {
  377. DWORD ExcpVal = m_pLdrObj->TranslateExceptionCode(RpcExceptionCode());
  378. DBGMSG(DBG_WARN,
  379. ("TPrintUIMgr::PrinterSetup failed in calling printui with an exception %u",ExcpVal));
  380. SetLastError(ExcpVal);
  381. ErrorCode = ExcpVal;
  382. }
  383. }
  384. m_pLdrObj->DecUIRefCnt();
  385. }
  386. else
  387. {
  388. ErrorCode = GetLastError();
  389. }
  390. FreeLibrary(hPrintUI);
  391. }
  392. else
  393. {
  394. ErrorCode = GetLastError();
  395. }
  396. //
  397. // Here we should post a message to the caller client window to inform
  398. // it that the operation was completed and also whether it was succesful
  399. // or not
  400. //
  401. PostMessage(hWnd,WM_ENDPRINTERSETUP,
  402. (WPARAM)bRetVal,
  403. (LPARAM)ErrorCode);
  404. return ErrorCode;
  405. }
  406. /*++
  407. Function Name:
  408. TPrintUIMgr :: ServerPropPages
  409. Description:
  410. This function opens the property sheet of specified server.
  411. Parameters:
  412. hWnd : Parent hwnd.
  413. PrinterName : Server name.
  414. CmdShow : Show command.
  415. lParam : currently unused.
  416. Return Value:
  417. DWORD : Error Code in case of Failure
  418. ERROR_SUCCESS in case of success
  419. --*/
  420. DWORD
  421. TPrintUIMgr ::
  422. ServerPropPages(
  423. IN HWND hWnd,
  424. IN LPCWSTR pszServerName,
  425. IN INT CmdShow,
  426. IN LPARAM lParam
  427. )
  428. {
  429. return PrintUIMethod("vServerPropPages",
  430. hWnd,
  431. pszServerName,
  432. CmdShow,
  433. lParam,
  434. AsyncPrintUIMethod,
  435. TPrintUIMgr::KServerPropPagesOp);
  436. }