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.

593 lines
23 KiB

  1. /**************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: wiafbdrv.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 18 July, 2000
  10. *
  11. * DESCRIPTION:
  12. *
  13. *
  14. ***************************************************************************/
  15. #include "pch.h"
  16. typedef GUID* PGUID;
  17. #if defined( _WIN32 ) && !defined( _NO_COM)
  18. //////////////////////////////////////////////////////////////////////////
  19. // GUID / CLSID definition section (for your specific device) //
  20. // //
  21. // IMPORTANT!! - REMEMBER TO CHANGE YOUR .INF FILE TO MATCH YOUR WIA //
  22. // DRIVER'S CLSID!! //
  23. // //
  24. // //
  25. //////////////////////////////////////////////////////////////////////////
  26. // BB6CF8E2-1511-40bd-91BA-80D43C53064E
  27. DEFINE_GUID(CLSID_FlatbedScannerUsd, 0xBB6CF8E2L, 0x1511, 0x40bd, 0x91, 0xBA, 0x80, 0xD4, 0x3C, 0x53, 0x06, 0x4E);
  28. // {48A89A69-C08C-482a-B3E5-CD50B50B5DFA}
  29. DEFINE_GUID(guidEventFirstLoaded,
  30. 0x48a89a69, 0xc08c, 0x482a, 0xb3, 0xe5, 0xcd, 0x50, 0xb5, 0xb, 0x5d, 0xfa);
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////
  33. // DLL #define Section //
  34. //////////////////////////////////////////////////////////////////////////
  35. #define DATASEG_PERINSTANCE ".instance"
  36. #define DATASEG_SHARED ".shared"
  37. #define DATASEG_READONLY ".code"
  38. #define DATASEG_DEFAULT DATASEG_SHARED
  39. #define ENTERCRITICAL DllEnterCrit(void);
  40. #define LEAVECRITICAL DllLeaveCrit(void);
  41. #pragma data_seg(DATASEG_PERINSTANCE)
  42. #pragma data_seg(DATASEG_DEFAULT)
  43. extern UINT g_cRefThisDll;
  44. extern UINT g_cLocks;
  45. extern BOOL DllInitializeCOM(void);
  46. extern BOOL DllUnInitializeCOM(void);
  47. extern void DllAddRef(void);
  48. extern void DllRelease(void);
  49. //
  50. // Base structure for supporting non-delegating IUnknown for contained objects
  51. //
  52. struct INonDelegatingUnknown
  53. {
  54. // IUnknown-like methods
  55. STDMETHOD(NonDelegatingQueryInterface)(THIS_
  56. REFIID riid,
  57. LPVOID *ppvObj) PURE;
  58. STDMETHOD_(ULONG,NonDelegatingAddRef)(THIS) PURE;
  59. STDMETHOD_(ULONG,NonDelegatingRelease)( THIS) PURE;
  60. };
  61. // This sample WIA scanner supports a single scanning context.
  62. #define NUM_DEVICE_ITEM 1
  63. // Device item specific context.
  64. typedef struct _MINIDRIVERITEMCONTEXT{
  65. LONG lSize;
  66. LONG lTotalWritten; // Total image bytes written.
  67. // Scan parameters:
  68. LONG lDepth; // image bit depth
  69. LONG lBytesPerScanLine; // bytes per scan line (scanned data)
  70. LONG lBytesPerScanLineRaw; // bytes per scan line RAW (scanned data)
  71. LONG lTotalRequested; // Total image bytes requested.
  72. } MINIDRIVERITEMCONTEXT, *PMINIDRIVERITEMCONTEXT;
  73. //
  74. // Definitions controlling COLOR/BW support
  75. //
  76. #define NUM_DATA_TYPES_NONLEGACY 3
  77. #define NUM_DATA_TYPES_LEGACY 2
  78. //
  79. // Class definition for sample WIA scanner object
  80. //
  81. class CWIAScannerDevice : public IStiUSD, // STI USD interface
  82. public IWiaMiniDrv, // WIA Minidriver interface
  83. public INonDelegatingUnknown // NonDelegatingUnknown
  84. {
  85. public:
  86. /////////////////////////////////////////////////////////////////////////
  87. // Construction/Destruction Section //
  88. /////////////////////////////////////////////////////////////////////////
  89. CWIAScannerDevice(LPUNKNOWN punkOuter);
  90. HRESULT PrivateInitialize();
  91. ~CWIAScannerDevice();
  92. private:
  93. // COM object data
  94. ULONG m_cRef; // Device object reference count.
  95. // STI information
  96. BOOL m_fValid; // Is object initialized?
  97. LPUNKNOWN m_punkOuter; // Pointer to outer unknown.
  98. PSTIDEVICECONTROL m_pIStiDevControl; // Device control interface.
  99. BOOLEAN m_bUsdLoadEvent; // Controls load event.
  100. DWORD m_dwLastOperationError; // Last error.
  101. DWORD m_dwLockTimeout; // Lock timeout for LockDevice() calls
  102. BOOL m_bDeviceLocked; // device locked/unlocked
  103. CHAR *m_pszDeviceNameA; // CreateFileName for default RawRead/RawWrite handle
  104. HANDLE m_DeviceDefaultDataHandle;//default RawRead/RawWrite handle
  105. // Event information
  106. CRITICAL_SECTION m_csShutdown; // Syncronizes shutdown.
  107. HANDLE m_hSignalEvent; // Signal event handle.
  108. HANDLE m_hShutdownEvent; // Shutdown event handle.
  109. HANDLE m_hEventNotifyThread; // Does event notification.
  110. GUID m_guidLastEvent; // Last event ID.
  111. // WIA information, one time initialization.
  112. BSTR m_bstrDeviceID; // WIA unique device ID.
  113. BSTR m_bstrRootFullItemName; // Device name for prop streams.
  114. IWiaEventCallback *m_pIWiaEventCallback; // WIA event sink.
  115. IWiaDrvItem *m_pIDrvItemRoot; // The root item.
  116. IStiDevice *m_pStiDevice; // Sti object.
  117. HINSTANCE m_hInstance; // Module's HINSTANCE
  118. IWiaLog *m_pIWiaLog; // WIA logging object
  119. LONG m_NumSupportedCommands; // Number of supported commands
  120. LONG m_NumSupportedEvents; // Number of supported events
  121. LONG m_NumSupportedFormats; // Number of supported formats
  122. LONG m_NumCapabilities; // Number of capabilities
  123. LONG m_NumSupportedTYMED; // Number of supported TYMED
  124. LONG m_NumInitialFormats; // Number of Initial formats
  125. LONG m_NumSupportedDataTypes;// Number of supported data types
  126. LONG m_NumSupportedIntents; // Number of supported intents
  127. LONG m_NumSupportedCompressionTypes; // Number of supported compression types
  128. LONG m_NumSupportedResolutions; // Number of supported resolutions
  129. LONG m_NumSupportedPreviewModes;// Number of supported preview modes
  130. WIA_FORMAT_INFO *m_pSupportedFormats; // supported formats
  131. WIA_DEV_CAP_DRV *m_pCapabilities; // capabilities
  132. LONG *m_pSupportedTYMED; // supported TYMED
  133. GUID *m_pInitialFormats; // initial formats
  134. LONG *m_pSupportedDataTypes; // supported data types
  135. LONG *m_pSupportedIntents; // supported intents
  136. LONG *m_pSupportedCompressionTypes; // supported compression types
  137. LONG *m_pSupportedResolutions;// supported resolutions
  138. LONG *m_pSupportedPreviewModes;// supported preview modes
  139. LONG m_NumRootItemProperties;// Number of Root item properties
  140. LONG m_NumItemProperties; // Number of item properties
  141. LPOLESTR *m_pszRootItemDefaults; // root item property names
  142. PROPID *m_piRootItemDefaults; // root item property ids
  143. PROPVARIANT *m_pvRootItemDefaults; // root item property prop variants
  144. PROPSPEC *m_psRootItemDefaults; // root item property propspecs
  145. WIA_PROPERTY_INFO *m_wpiRootItemDefaults; // root item property attributes
  146. LPOLESTR *m_pszItemDefaults; // item property names
  147. PROPID *m_piItemDefaults; // item property ids
  148. PROPVARIANT *m_pvItemDefaults; // item property prop variants
  149. PROPSPEC *m_psItemDefaults; // item property propspecs
  150. WIA_PROPERTY_INFO *m_wpiItemDefaults; // item property attributes
  151. BOOL m_bADFAttached; // ADF attached
  152. BOOL m_bTPAEnabled; // TPA enabled
  153. BOOL m_bTPAAttached; // TPA attached
  154. LONG m_MaxBufferSize; // Maximum buffer for device
  155. LONG m_MinBufferSize; // Minimum buffer for device
  156. CScanAPI *m_pScanAPI; // Scanner device API class, (micro and script-based)
  157. BOOL m_bLegacyBWRestriction; // flag to restrict devices to BW and Grayscale scanning only
  158. // inline member functions
  159. BOOL inline IsValid(VOID) {
  160. return m_fValid;
  161. }
  162. public:
  163. /////////////////////////////////////////////////////////////////////////
  164. // Standard COM Section //
  165. /////////////////////////////////////////////////////////////////////////
  166. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  167. STDMETHODIMP_(ULONG) AddRef( void);
  168. STDMETHODIMP_(ULONG) Release( void);
  169. /////////////////////////////////////////////////////////////////////////
  170. // IStiUSD Interface Section (for all WIA drivers) //
  171. /////////////////////////////////////////////////////////////////////////
  172. //
  173. // Methods for implementing the IStiUSD interface.
  174. //
  175. STDMETHOD(Initialize)(THIS_
  176. PSTIDEVICECONTROL pHelDcb,
  177. DWORD dwStiVersion,
  178. HKEY hParametersKey);
  179. STDMETHOD(GetCapabilities)(THIS_
  180. PSTI_USD_CAPS pDevCaps);
  181. STDMETHOD(GetStatus)(THIS_
  182. PSTI_DEVICE_STATUS pDevStatus);
  183. STDMETHOD(DeviceReset)(THIS);
  184. STDMETHOD(Diagnostic)(THIS_
  185. LPDIAG pBuffer);
  186. STDMETHOD(Escape)(THIS_
  187. STI_RAW_CONTROL_CODE EscapeFunction,
  188. LPVOID lpInData,
  189. DWORD cbInDataSize,
  190. LPVOID pOutData,
  191. DWORD dwOutDataSize,
  192. LPDWORD pdwActualData);
  193. STDMETHOD(GetLastError)(THIS_
  194. LPDWORD pdwLastDeviceError);
  195. STDMETHOD(LockDevice)(THIS);
  196. STDMETHOD(UnLockDevice)(THIS);
  197. STDMETHOD(RawReadData)(THIS_
  198. LPVOID lpBuffer,
  199. LPDWORD lpdwNumberOfBytes,
  200. LPOVERLAPPED lpOverlapped);
  201. STDMETHOD(RawWriteData)(THIS_
  202. LPVOID lpBuffer,
  203. DWORD nNumberOfBytes,
  204. LPOVERLAPPED lpOverlapped);
  205. STDMETHOD(RawReadCommand)(THIS_
  206. LPVOID lpBuffer,
  207. LPDWORD lpdwNumberOfBytes,
  208. LPOVERLAPPED lpOverlapped);
  209. STDMETHOD(RawWriteCommand)(THIS_
  210. LPVOID lpBuffer,
  211. DWORD nNumberOfBytes,
  212. LPOVERLAPPED lpOverlapped);
  213. STDMETHOD(SetNotificationHandle)(THIS_
  214. HANDLE hEvent);
  215. STDMETHOD(GetNotificationData)(THIS_
  216. LPSTINOTIFY lpNotify);
  217. STDMETHOD(GetLastErrorInfo)(THIS_
  218. STI_ERROR_INFO *pLastErrorInfo);
  219. /////////////////////////////////////////////////////////////////////////
  220. // IWiaMiniDrv Interface Section (for all WIA drivers) //
  221. /////////////////////////////////////////////////////////////////////////
  222. //
  223. // Methods for implementing WIA's Mini driver interface
  224. //
  225. STDMETHOD(drvInitializeWia)(THIS_
  226. BYTE *pWiasContext,
  227. LONG lFlags,
  228. BSTR bstrDeviceID,
  229. BSTR bstrRootFullItemName,
  230. IUnknown *pStiDevice,
  231. IUnknown *pIUnknownOuter,
  232. IWiaDrvItem **ppIDrvItemRoot,
  233. IUnknown **ppIUnknownInner,
  234. LONG *plDevErrVal);
  235. STDMETHOD(drvGetDeviceErrorStr)(THIS_
  236. LONG lFlags,
  237. LONG lDevErrVal,
  238. LPOLESTR *ppszDevErrStr,
  239. LONG *plDevErr);
  240. STDMETHOD(drvDeviceCommand)(THIS_
  241. BYTE *pWiasContext,
  242. LONG lFlags,
  243. const GUID *plCommand,
  244. IWiaDrvItem **ppWiaDrvItem,
  245. LONG *plDevErrVal);
  246. STDMETHOD(drvAcquireItemData)(THIS_
  247. BYTE *pWiasContext,
  248. LONG lFlags,
  249. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  250. LONG *plDevErrVal);
  251. STDMETHOD(drvInitItemProperties)(THIS_
  252. BYTE *pWiasContext,
  253. LONG lFlags,
  254. LONG *plDevErrVal);
  255. STDMETHOD(drvValidateItemProperties)(THIS_
  256. BYTE *pWiasContext,
  257. LONG lFlags,
  258. ULONG nPropSpec,
  259. const PROPSPEC *pPropSpec,
  260. LONG *plDevErrVal);
  261. STDMETHOD(drvWriteItemProperties)(THIS_
  262. BYTE *pWiasContext,
  263. LONG lFlags,
  264. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  265. LONG *plDevErrVal);
  266. STDMETHOD(drvReadItemProperties)(THIS_
  267. BYTE *pWiasContext,
  268. LONG lFlags,
  269. ULONG nPropSpec,
  270. const PROPSPEC *pPropSpec,
  271. LONG *plDevErrVal);
  272. STDMETHOD(drvLockWiaDevice)(THIS_
  273. BYTE *pWiasContext,
  274. LONG lFlags,
  275. LONG *plDevErrVal);
  276. STDMETHOD(drvUnLockWiaDevice)(THIS_
  277. BYTE *pWiasContext,
  278. LONG lFlags,
  279. LONG *plDevErrVal);
  280. STDMETHOD(drvAnalyzeItem)(THIS_
  281. BYTE *pWiasContext,
  282. LONG lFlags,
  283. LONG *plDevErrVal);
  284. STDMETHOD(drvDeleteItem)(THIS_
  285. BYTE *pWiasContext,
  286. LONG lFlags,
  287. LONG *plDevErrVal);
  288. STDMETHOD(drvFreeDrvItemContext)(THIS_
  289. LONG lFlags,
  290. BYTE *pSpecContext,
  291. LONG *plDevErrVal);
  292. STDMETHOD(drvGetCapabilities)(THIS_
  293. BYTE *pWiasContext,
  294. LONG ulFlags,
  295. LONG *pcelt,
  296. WIA_DEV_CAP_DRV **ppCapabilities,
  297. LONG *plDevErrVal);
  298. STDMETHOD(drvGetWiaFormatInfo)(THIS_
  299. BYTE *pWiasContext,
  300. LONG lFlags,
  301. LONG *pcelt,
  302. WIA_FORMAT_INFO **ppwfi,
  303. LONG *plDevErrVal);
  304. STDMETHOD(drvNotifyPnpEvent)(THIS_
  305. const GUID *pEventGUID,
  306. BSTR bstrDeviceID,
  307. ULONG ulReserved);
  308. STDMETHOD(drvUnInitializeWia)(THIS_
  309. BYTE *pWiasContext);
  310. /////////////////////////////////////////////////////////////////////////
  311. // INonDelegating Interface Section (for all WIA drivers) //
  312. /////////////////////////////////////////////////////////////////////////
  313. //
  314. // IUnknown-like methods. Needed in conjunction with normal IUnknown
  315. // methods to implement delegating components.
  316. //
  317. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  318. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  319. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  320. private:
  321. /////////////////////////////////////////////////////////////////////////
  322. // Private helper functions section (for your specific driver) //
  323. /////////////////////////////////////////////////////////////////////////
  324. // //
  325. // This section is for private helpers used for common WIA operations. //
  326. // These are custom to your driver. //
  327. // //
  328. // //
  329. // -- WIA Item Management Helpers //
  330. // BuildItemTree() //
  331. // DeleteItemTree() //
  332. // //
  333. // -- WIA Property Management Helpers //
  334. // BuildRootItemProperties() //
  335. // BuildTopItemProperties() //
  336. // //
  337. // -- WIA Capability Management Helpers //
  338. // BuildRootItemProperties() //
  339. // DeleteRootItemProperties() //
  340. // BuildTopItemProperties() //
  341. // DeleteTopItemProperties() //
  342. // BuildCapabilities() //
  343. // DeleteCapabilitiesArrayContents() //
  344. // BuildSupportedFormats() //
  345. // DeleteSupportedFormatsArrayContents() //
  346. // BuildSupportedDataTypes() //
  347. // DeleteSupportedDataTypesArrayContents() //
  348. // BuildSupportedIntents() //
  349. // DeleteSupportedIntentsArrayContents() //
  350. // BuildSupportedCompressions() //
  351. // DeleteSupportedCompressionsArrayContents() //
  352. // BuildSupportedTYMED() //
  353. // DeleteSupportedTYMEDArrayContents() //
  354. // BuildInitialFormats() //
  355. // DeleteInitialFormatsArrayContents() //
  356. // //
  357. // -- WIA Validation Helpers //
  358. // CheckDataType() //
  359. // CheckIntent() //
  360. // CheckPreferredFormat() //
  361. // SetItemSize() //
  362. // UpdateValidDepth() //
  363. // ValidateDataTransferContext() //
  364. // //
  365. // -- WIA Resource file Helpers //
  366. // GetBSTRResourceString() //
  367. // GetOLESTRResourceString() //
  368. // //
  369. // -- WIA Data acqusition Helpers //
  370. // ScanItem() //
  371. // ScanItemCB() //
  372. // SendBitmapHeader() //
  373. // //
  374. // //
  375. // //
  376. // //
  377. // //
  378. /////////////////////////////////////////////////////////////////////////
  379. HRESULT _stdcall BuildItemTree(void);
  380. HRESULT _stdcall DeleteItemTree(void);
  381. HRESULT BuildRootItemProperties();
  382. HRESULT DeleteRootItemProperties();
  383. HRESULT BuildTopItemProperties();
  384. HRESULT DeleteTopItemProperties();
  385. HRESULT BuildCapabilities();
  386. HRESULT DeleteCapabilitiesArrayContents();
  387. HRESULT BuildSupportedFormats();
  388. HRESULT DeleteSupportedFormatsArrayContents();
  389. HRESULT BuildSupportedDataTypes();
  390. HRESULT DeleteSupportedDataTypesArrayContents();
  391. HRESULT BuildSupportedIntents();
  392. HRESULT DeleteSupportedIntentsArrayContents();
  393. HRESULT BuildSupportedCompressions();
  394. HRESULT DeleteSupportedCompressionsArrayContents();
  395. HRESULT BuildSupportedPreviewModes();
  396. HRESULT DeleteSupportedPreviewModesArrayContents();
  397. HRESULT BuildSupportedTYMED();
  398. HRESULT DeleteSupportedTYMEDArrayContents();
  399. HRESULT BuildSupportedResolutions();
  400. HRESULT DeleteSupportedResolutionsArrayContents();
  401. HRESULT BuildInitialFormats();
  402. HRESULT DeleteInitialFormatsArrayContents();
  403. HRESULT CheckDataType(
  404. BYTE *pWiasContext,
  405. WIA_PROPERTY_CONTEXT *pContext);
  406. HRESULT CheckIntent(
  407. BYTE *pWiasContext,
  408. WIA_PROPERTY_CONTEXT *pContext);
  409. HRESULT CheckPreferredFormat(
  410. BYTE *pWiasContext,
  411. WIA_PROPERTY_CONTEXT *pContext);
  412. HRESULT CheckADFStatus(BYTE *pWiasContext,
  413. WIA_PROPERTY_CONTEXT *pContext);
  414. HRESULT CheckPreview(BYTE *pWiasContext,
  415. WIA_PROPERTY_CONTEXT *pContext);
  416. HRESULT UpdateValidDepth(
  417. BYTE *pWiasContext,
  418. LONG lDataType,
  419. LONG *lDepth);
  420. HRESULT ValidateDataTransferContext(
  421. PMINIDRV_TRANSFER_CONTEXT pDataTransferContext);
  422. HRESULT SetItemSize(
  423. BYTE *pWiasContext);
  424. HRESULT _stdcall ScanItem(
  425. PMINIDRIVERITEMCONTEXT,
  426. PMINIDRV_TRANSFER_CONTEXT,
  427. LONG*);
  428. HRESULT _stdcall ScanItemCB(
  429. PMINIDRIVERITEMCONTEXT,
  430. PMINIDRV_TRANSFER_CONTEXT,
  431. LONG*);
  432. HRESULT SendBitmapHeader(
  433. PMINIDRV_TRANSFER_CONTEXT pmdtc);
  434. HRESULT SendFilePreviewBitmapHeader(
  435. PMINIDRV_TRANSFER_CONTEXT pmdtc);
  436. HRESULT GetBSTRResourceString(
  437. LONG lLocalResourceID,
  438. BSTR *pBSTR,
  439. BOOL bLocal);
  440. HRESULT GetOLESTRResourceString(
  441. LONG lLocalResourceID,
  442. LPOLESTR *ppsz,
  443. BOOL bLocal);
  444. UINT AlignInPlace(
  445. PBYTE pBuffer,
  446. LONG cbWritten,
  447. LONG lBytesPerScanLine,
  448. LONG lBytesPerScanLineRaw);
  449. VOID VerticalFlip(
  450. PMINIDRIVERITEMCONTEXT pDrvItemContext,
  451. PMINIDRV_TRANSFER_CONTEXT pDataTransferContext);
  452. VOID SwapBuffer24(
  453. PBYTE pBuffer,
  454. LONG lByteCount);
  455. LONG GetPageCount(
  456. BYTE *pWiasContext);
  457. BOOL IsPreviewScan(
  458. BYTE *pWiasContext);
  459. BOOL IsADFEnabled(
  460. BYTE *pWiasContext);
  461. public:
  462. HRESULT DoEventProcessing();
  463. };
  464. typedef CWIAScannerDevice *PWIASCANNERDEVICE;