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.

610 lines
12 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Client.h
  6. Abstract:
  7. Holds common winspool.drv header info
  8. Author:
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. --*/
  13. #include <splcom.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. extern HINSTANCE hInst;
  18. extern BOOL bLoadedBySpooler;
  19. extern CRITICAL_SECTION ClientSection;
  20. extern CRITICAL_SECTION ListAccessSem;
  21. extern LPWSTR InterfaceAddress;
  22. extern LPWSTR szEnvironment;
  23. extern CRITICAL_SECTION ProcessHndlCS;
  24. extern HANDLE hSurrogateProcess;
  25. extern DWORD (*fpYReadPrinter)(HANDLE, LPBYTE, DWORD, LPDWORD, BOOL);
  26. extern DWORD (*fpYSplReadPrinter)(HANDLE, LPBYTE *, DWORD, BOOL);
  27. extern DWORD (*fpYWritePrinter)(HANDLE, LPBYTE, DWORD, LPDWORD, BOOL);
  28. extern DWORD (*fpYSeekPrinter)(HANDLE, LARGE_INTEGER, PLARGE_INTEGER, DWORD, BOOL, BOOL);
  29. extern DWORD (*fpYGetPrinterDriver2)(HANDLE, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, DWORD, DWORD, PDWORD, PDWORD, BOOL);
  30. extern DWORD (*fpYGetPrinterDriverDirectory)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, BOOL);
  31. extern VOID (*fpYDriverUnloadComplete)(LPWSTR);
  32. extern DWORD (*fpYFlushPrinter)(HANDLE,LPVOID,DWORD,LPDWORD,DWORD,BOOL);
  33. extern DWORD (*fpYEndDocPrinter)(HANDLE,BOOL);
  34. extern DWORD (*fpYSetPort)(LPWSTR, LPWSTR, LPPORT_CONTAINER, BOOL);
  35. extern DWORD (*fpYSetJob)(HANDLE, DWORD, LPJOB_CONTAINER, DWORD, BOOL);
  36. #define vEnterSem() EnterCriticalSection(&ClientSection)
  37. #define vLeaveSem() LeaveCriticalSection(&ClientSection)
  38. typedef int (FAR WINAPI *INT_FARPROC)();
  39. typedef struct _GENERIC_CONTAINER {
  40. DWORD Level;
  41. LPBYTE pData;
  42. } GENERIC_CONTAINER, *PGENERIC_CONTAINER, *LPGENERIC_CONTAINER ;
  43. typedef struct _SPOOL *PSPOOL;
  44. typedef struct _NOTIFY *PNOTIFY;
  45. typedef struct _NOTIFY {
  46. PNOTIFY pNext;
  47. HANDLE hEvent; // event to trigger on notification
  48. DWORD fdwFlags; // flags to watch for
  49. DWORD fdwOptions; // PRINTER_NOTIFY_*
  50. DWORD dwReturn; // used by WPC when simulating FFPCN
  51. PSPOOL pSpool;
  52. BOOL bHandleInvalid;
  53. } NOTIFY;
  54. typedef struct _SPOOL {
  55. DWORD signature;
  56. HANDLE hPrinter;
  57. HANDLE hFile;
  58. DWORD JobId;
  59. LPBYTE pBuffer;
  60. DWORD cbBuffer;
  61. DWORD Status;
  62. DWORD fdwFlags;
  63. DWORD cCacheWrite;
  64. DWORD cWritePrinters;
  65. DWORD cFlushBuffers;
  66. DWORD dwTickCount;
  67. DWORD dwCheckJobInterval;
  68. PNOTIFY pNotify;
  69. LPTSTR pszPrinter;
  70. PRINTER_DEFAULTS Default;
  71. HANDLE hSplPrinter;
  72. DWORD cActive;
  73. HANDLE hSpoolFile;
  74. DWORD dwSpoolFileAttributes;
  75. DWORD cbFlushPending;
  76. DWORD cOKFlushBuffers;
  77. DWORD Flushed;
  78. PDOCEVENT_FILTER pDoceventFilter;
  79. #ifdef DBG_TRACE_HANDLE
  80. PSPOOL pNext;
  81. PVOID apvBackTrace[32];
  82. #endif
  83. } SPOOL;
  84. #define WIN2000_SPOOLER_VERSION 3
  85. // cActive: There is a non-close call currently active on the handle.
  86. // Any ClosePrinter call should just mark SPOOL_STATUS_PENDING_DELETION
  87. // so that the handle will be closed when the other thread is one.
  88. #define BUFFER_SIZE 0x10000
  89. #define SP_SIGNATURE 0x6767
  90. #define SPOOL_STATUS_STARTDOC 0x00000001
  91. #define SPOOL_STATUS_ADDJOB 0x00000002
  92. #define SPOOL_STATUS_ANSI 0x00000004
  93. #define SPOOL_STATUS_DOCUMENTEVENT_ENABLED 0x00000008
  94. #define SPOOL_STATUS_TRAYICON_NOTIFIED 0x00000010
  95. #define SPOOL_STATUS_NO_COLORPROFILE_HOOK 0x00000020
  96. //
  97. // CLOSE: There is a close call occuring. Everything else should fail.
  98. // PENDING_DELETION: The handle should be closed as soon as any call completes.
  99. // This occurs when ClosePrinter is called but another thread is executing
  100. // a non-close call. In this case, the ClosePrinter doesn't do anything;
  101. // it just marks PENDING_DELETION and returns.
  102. //
  103. #define SPOOL_STATUS_CLOSE 0x00000040
  104. #define SPOOL_STATUS_PENDING_DELETION 0x00000080
  105. #define MAX_STATIC_ALLOC 1024
  106. #define SPOOL_FLAG_FFPCN_FAILED 0x1
  107. #define SPOOL_FLAG_LAZY_CLOSE 0x2
  108. #define NULL_TERMINATED 0
  109. //
  110. // This is the resource id that is used to locate the activation context
  111. // for an image that has funsion version information.
  112. //
  113. #define ACTIVATION_CONTEXT_RESOURCE_ID 123
  114. //
  115. // SPOOL_FILE_INFO_1 trades handles in what amount to a 32 bit interface. The
  116. // central assumption here is that kernel mode handles are 32 bit values (i.e.
  117. // an offset into a table.) This isn't great, but since a 64 bit spooler will
  118. // communicate with a 32 bit client GDI, this assumption is implicite anyway.
  119. //
  120. #define SPOOL_INVALID_HANDLE_VALUE_32BIT ((HANDLE)(ULONG_PTR)0xffffffff)
  121. // Struct for storing loaded driver config file handles
  122. typedef struct _DRVLIBNODE {
  123. struct _DRVLIBNODE *pNext;
  124. LPWSTR pConfigFile;
  125. DWORD dwNumHandles;
  126. HANDLE hLib;
  127. DWORD dwVersion;
  128. BOOL bArtificialIncrement;
  129. } DRVLIBNODE, *PDRVLIBNODE;
  130. //
  131. // Struct for DocumentProperties UI monitoring
  132. //
  133. typedef struct _PUMPTHRDDATA
  134. {
  135. ULONG_PTR hWnd;
  136. LPWSTR PrinterName;
  137. PDWORD TouchedDevModeSize;
  138. PDWORD ClonedDevModeOutSize;
  139. byte** ClonedDevModeOut;
  140. DWORD DevModeInSize;
  141. byte* pDevModeInput;
  142. DWORD fMode;
  143. DWORD fExclusionFlags;
  144. PDWORD dwRet;
  145. PLONG Result;
  146. BOOL ClonedDevModeFill;
  147. } PumpThrdData;
  148. typedef struct _PRTPROPSDATA
  149. {
  150. ULONG_PTR hWnd;
  151. PDWORD dwRet;
  152. LPWSTR PrinterName;
  153. DWORD Flag;
  154. } PrtPropsData;
  155. typedef struct _PRINTERSETUPDATA
  156. {
  157. ULONG_PTR hWnd;
  158. UINT uAction;
  159. UINT cchPrinterName;
  160. UINT PrinterNameSize;
  161. LPWSTR pszPrinterName;
  162. UINT *pcchPrinterName;
  163. LPCWSTR pszServerName;
  164. }PrinterSetupData;
  165. typedef struct _KEYDATA {
  166. DWORD cb;
  167. DWORD cTokens;
  168. LPWSTR pTokens[1];
  169. } KEYDATA, *PKEYDATA;
  170. typedef enum {
  171. kProtectHandleSuccess = 0,
  172. kProtectHandleInvalid = 1,
  173. kProtectHandlePendingDeletion = 2
  174. } EProtectResult;
  175. typedef enum{
  176. RUN32BINVER = 4,
  177. RUN64BINVER = 8
  178. }ClientVersion;
  179. typedef enum{
  180. NATIVEVERSION = 0,
  181. THUNKVERSION = 1
  182. }ServerVersion;
  183. struct SJOBCANCELINFO
  184. {
  185. PSPOOL pSpool;
  186. LPBYTE pInitialBuf;
  187. PDWORD pcbWritten;
  188. PDWORD pcTotalWritten;
  189. DWORD NumOfCmpltWrts;
  190. DWORD cbFlushed;
  191. DWORD ReqTotalDataSize;
  192. DWORD FlushPendingDataSize;
  193. DWORD ReqToWriteDataSize;
  194. BOOL ReturnValue;
  195. };
  196. typedef struct SJOBCANCELINFO SJobCancelInfo, *PSJobCancelInfo;
  197. //
  198. // The list used to maintain created windows waiting on
  199. // end messages from the surrogate process
  200. //
  201. struct WNDHNDLNODE
  202. {
  203. struct WNDHNDLNODE *PrevNode;
  204. struct WNDHNDLNODE *NextNode;
  205. HWND hWnd;
  206. };
  207. typedef struct WNDHNDLNODE WndHndlNode,*LPWndHndlNode;
  208. struct WNDHNDLLIST
  209. {
  210. struct WNDHNDLNODE *Head;
  211. struct WNDHNDLNODE *Tail;
  212. DWORD NumOfHndls;
  213. };
  214. typedef struct WNDHNDLLIST WndHndlList,*LPWndHndlList;
  215. struct MONITORINGTHRDDATA
  216. {
  217. HANDLE* hProcess;
  218. HANDLE hEvent;
  219. };
  220. typedef struct MONITORINGTHRDDATA MonitorThrdData,*LPMonitorThrdData;
  221. typedef struct _MONITORUIDATA
  222. {
  223. HINSTANCE hLibrary;
  224. HANDLE hActCtx;
  225. ULONG_PTR lActCtx;
  226. PWSTR pszMonitorName;
  227. BOOL bDidActivate;
  228. } MONITORUIDATA, *PMONITORUIDATA;
  229. DWORD
  230. TranslateExceptionCode(
  231. DWORD ExceptionCode
  232. );
  233. BOOL
  234. WPCInit(
  235. VOID
  236. );
  237. VOID
  238. WPCDone(
  239. VOID
  240. );
  241. PNOTIFY
  242. WPCWaitFind(
  243. HANDLE hFind
  244. );
  245. BOOL
  246. FlushBuffer(
  247. PSPOOL pSpool,
  248. PDWORD pcbWritten
  249. );
  250. PSECURITY_DESCRIPTOR
  251. BuildInputSD(
  252. PSECURITY_DESCRIPTOR pPrinterSD,
  253. PDWORD pSizeSD
  254. );
  255. PKEYDATA
  256. CreateTokenList(
  257. LPWSTR pKeyData
  258. );
  259. LPWSTR
  260. GetPrinterPortList(
  261. HANDLE hPrinter
  262. );
  263. LPWSTR
  264. FreeUnicodeString(
  265. LPWSTR pUnicodeString
  266. );
  267. LPWSTR
  268. AllocateUnicodeString(
  269. LPSTR pPrinterName
  270. );
  271. LPWSTR
  272. StartDocDlgW(
  273. HANDLE hPrinter,
  274. DOCINFO *pDocInfo
  275. );
  276. LPSTR
  277. StartDocDlgA(
  278. HANDLE hPrinter,
  279. DOCINFOA *pDocInfo
  280. );
  281. HANDLE
  282. LoadPrinterDriver(
  283. HANDLE hPrinter
  284. );
  285. HANDLE
  286. RefCntLoadDriver(
  287. LPTSTR pConfigFile,
  288. DWORD dwFlags,
  289. DWORD dwVersion,
  290. BOOL bUseVersion
  291. );
  292. BOOL
  293. RefCntUnloadDriver(
  294. HANDLE hLib,
  295. BOOL bNotifySpooler
  296. );
  297. BOOL
  298. ForceUnloadDriver(
  299. LPTSTR pConfigFile
  300. );
  301. BOOL
  302. WriteCurDevModeToRegistry(
  303. LPWSTR pPrinterName,
  304. LPDEVMODEW pDevMode
  305. );
  306. BOOL
  307. DeleteCurDevModeFromRegistry(
  308. PWSTR pPrinterName
  309. );
  310. BOOL
  311. bValidDevModeW(
  312. const DEVMODEW *pDevModeW
  313. );
  314. BOOL
  315. bValidDevModeA(
  316. const DEVMODEA *pDevModeA
  317. );
  318. DWORD
  319. FindClosePrinterChangeNotificationWorker(
  320. IN PNOTIFY pNotify,
  321. IN HANDLE hPrinterRPC,
  322. IN BOOL bRevalidate
  323. );
  324. BOOL
  325. ScheduleJobWorker(
  326. PSPOOL pSpool,
  327. DWORD JobId
  328. );
  329. PSPOOL
  330. AllocSpool(
  331. VOID
  332. );
  333. VOID
  334. FreeSpool(
  335. PSPOOL pSpool
  336. );
  337. VOID
  338. CloseSpoolFileHandles(
  339. PSPOOL pSpool
  340. );
  341. EProtectResult
  342. eProtectHandle(
  343. IN HANDLE hPrinter,
  344. IN BOOL bClose
  345. );
  346. VOID
  347. vUnprotectHandle(
  348. IN HANDLE hPrinter
  349. );
  350. BOOL
  351. UpdatePrinterDefaults(
  352. IN OUT PSPOOL pSpool,
  353. IN LPCTSTR pszPrinter, OPTIONAL
  354. IN PPRINTER_DEFAULTS pDefault OPTIONAL
  355. );
  356. BOOL
  357. RevalidateHandle(
  358. PSPOOL pSpool
  359. );
  360. BOOL
  361. UpdateString(
  362. IN LPCTSTR pszString, OPTIONAL
  363. OUT LPTSTR* ppszOut
  364. );
  365. INT
  366. Message(
  367. HWND hwnd,
  368. DWORD Type,
  369. INT CaptionID,
  370. INT TextID,
  371. ...
  372. );
  373. DWORD
  374. ReportFailure(
  375. HWND hwndParent,
  376. DWORD idTitle,
  377. DWORD idDefaultError
  378. );
  379. BOOL
  380. InCSRProcess(
  381. VOID
  382. );
  383. INT
  384. UnicodeToAnsiString(
  385. LPWSTR pUnicode,
  386. LPSTR pAnsi,
  387. DWORD StringLength
  388. );
  389. BOOL
  390. RunInWOW64(
  391. VOID
  392. );
  393. DWORD
  394. AddHandleToList(
  395. HWND hWnd
  396. );
  397. BOOL
  398. DelHandleFromList(
  399. HWND hWnd
  400. );
  401. HRESULT
  402. GetCurrentThreadLastPopup(
  403. OUT HWND *phwnd
  404. );
  405. LPCWSTR
  406. FindFileName(
  407. IN LPCWSTR pPathName
  408. );
  409. VOID
  410. ReleaseAndCleanupWndList(
  411. VOID
  412. );
  413. LONG_PTR
  414. DocumentPropertySheets(
  415. PPROPSHEETUI_INFO pCPSUIInfo,
  416. LPARAM lParam
  417. );
  418. LONG_PTR
  419. DevicePropertySheets(
  420. PPROPSHEETUI_INFO pCPSUIInfo,
  421. LPARAM lParam
  422. );
  423. VOID
  424. vUpdateTrayIcon(
  425. IN HANDLE hPrinter,
  426. IN DWORD JobId
  427. );
  428. LPWSTR
  429. SelectFormNameFromDevMode(
  430. HANDLE hPrinter,
  431. PDEVMODEW pDevModeW,
  432. LPWSTR pFormName
  433. );
  434. LPWSTR
  435. IsaFileName(
  436. LPWSTR pOutputFile,
  437. LPWSTR FullPathName,
  438. DWORD cchFullPathName
  439. );
  440. PWSTR
  441. ConstructXcvName(
  442. PCWSTR pServerName,
  443. PCWSTR pObjectName,
  444. PCWSTR pObjectType
  445. );
  446. DWORD
  447. GetMonitorUI(
  448. IN PCWSTR pszMachineName,
  449. IN PCWSTR pszObjectName,
  450. IN PCWSTR pszObjectType,
  451. OUT PMONITORUI *ppMonitorUI,
  452. OUT PMONITORUIDATA *ppMonitorUIData
  453. );
  454. HRESULT
  455. CreateMonitorUIData(
  456. OUT MONITORUIDATA **ppMonitorUIData
  457. );
  458. VOID
  459. FreeMonitorUI(
  460. IN PMONITORUIDATA pMonitorUIData
  461. );
  462. HRESULT
  463. GetMonitorUIActivationContext(
  464. IN PCWSTR pszMonitorName,
  465. IN PMONITORUIDATA pMonitorUIData
  466. );
  467. HRESULT
  468. GetMonitorUIFullName(
  469. IN PCWSTR pszMonitorName,
  470. IN PWSTR *ppszMonitorName
  471. );
  472. DWORD
  473. ConnectToLd64In32ServerWorker(
  474. HANDLE *hProcess
  475. );
  476. DWORD
  477. ConnectToLd64In32Server(
  478. HANDLE *hProcess
  479. );
  480. DWORD
  481. GetMonitorUIDll(
  482. PCWSTR pszMachineName,
  483. PCWSTR pszObjectName,
  484. PCWSTR pszObjectType,
  485. PWSTR *pMonitorUIDll
  486. );
  487. HWND
  488. GetForeGroundWindow(
  489. VOID
  490. );
  491. BOOL
  492. JobCanceled(
  493. PSJobCancelInfo
  494. );
  495. BOOL
  496. BuildSpoolerObjectPath(
  497. IN PCWSTR pszPath,
  498. IN PCWSTR pszName,
  499. IN PCWSTR pszEnvironment,
  500. IN DWORD Level,
  501. IN PBYTE pDriverDirectory,
  502. IN DWORD cbBuf,
  503. IN PDWORD pcbNeeded
  504. );
  505. #ifdef __cplusplus
  506. }
  507. #endif