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.

448 lines
19 KiB

  1. /**************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2002
  4. *
  5. * TITLE: wiascanr.h
  6. *
  7. * VERSION: 1.1
  8. *
  9. * DATE: 05 March, 2002
  10. *
  11. * DESCRIPTION:
  12. *
  13. *
  14. ***************************************************************************/
  15. #include "pch.h"
  16. //
  17. // Base structure for supporting non-delegating IUnknown for contained objects
  18. //
  19. struct INonDelegatingUnknown
  20. {
  21. // IUnknown-like methods
  22. STDMETHOD(NonDelegatingQueryInterface)(THIS_
  23. REFIID riid,
  24. LPVOID *ppvObj) PURE;
  25. STDMETHOD_(ULONG,NonDelegatingAddRef)(THIS) PURE;
  26. STDMETHOD_(ULONG,NonDelegatingRelease)( THIS) PURE;
  27. };
  28. // WIA item specific context.
  29. typedef struct _MINIDRIVERITEMCONTEXT{
  30. LONG lSize;
  31. LONG lHeaderSize; // Transfer header size
  32. LONG lImageSize; // Image
  33. LONG lDepth; // image bit depth
  34. LONG lBytesPerScanLine; // bytes per scan line (scanned data)
  35. LONG lBytesPerScanLineRaw; // bytes per scan line RAW (scanned data)
  36. LONG lTotalRequested; // Total image bytes requested.
  37. LONG lTotalWritten; // Total image bytes written.
  38. } MINIDRIVERITEMCONTEXT, *PMINIDRIVERITEMCONTEXT;
  39. typedef struct _BASIC_PROP_INFO {
  40. LONG lNumValues;
  41. LONG *plValues;
  42. }BASIC_PROP_INFO,*PBASIC_PROP_INFO;
  43. typedef struct _BASIC_PROP_INIT_INFO {
  44. LONG lNumProps; // number of item properties
  45. LPOLESTR *pszPropNames; // item property names
  46. PROPID *piPropIDs; // item property ids
  47. PROPVARIANT *pvPropVars; // item property prop variants
  48. PROPSPEC *psPropSpec; // item property propspecs
  49. WIA_PROPERTY_INFO *pwpiPropInfo; // item property attributes
  50. }BASIC_PROP_INIT_INFO,*PBASIC_PROP_INIT_INFO;
  51. #define HKEY_WIASCANR_FAKE_EVENTS TEXT("Software\\Microsoft\\WIASCANR")
  52. #define WIASCANR_DWORD_FAKE_EVENT_CODE TEXT("EventCode")
  53. #define AVERAGE_FAKE_PAGE_HEIGHT_INCHES 11
  54. #define DEFAULT_LOCK_TIMEOUT 100
  55. #define WIA_DEVICE_ROOT_NAME L"Root" // THIS SHOULD NOT BE LOCALIZED
  56. #define WIA_DEVICE_FLATBED_NAME L"Flatbed" // THIS SHOULD NOT BE LOCALIZED
  57. #define WIA_DEVICE_FEEDER_NAME L"Feeder" // THIS SHOULD NOT BE LOCALIZED
  58. //
  59. // Class definition for WIA device object
  60. //
  61. class CWIADevice : public IStiUSD, // STI USD interface
  62. public IWiaMiniDrv, // WIA Minidriver interface
  63. public INonDelegatingUnknown // NonDelegatingUnknown
  64. {
  65. public:
  66. /////////////////////////////////////////////////////////////////////////
  67. // Construction/Destruction Section //
  68. /////////////////////////////////////////////////////////////////////////
  69. CWIADevice(LPUNKNOWN punkOuter);
  70. ~CWIADevice();
  71. HRESULT PrivateInitialize();
  72. private:
  73. // COM object data
  74. ULONG m_cRef; // Device object reference count.
  75. // STI information
  76. LPUNKNOWN m_punkOuter; // Pointer to outer unknown.
  77. DWORD m_dwLastOperationError; // Last error.
  78. DWORD m_dwLockTimeout; // Lock timeout for LockDevice() calls
  79. BOOL m_bDeviceLocked; // device locked/unlocked
  80. HANDLE m_hDeviceDataHandle; // Device communication handle
  81. // Event information
  82. OVERLAPPED m_EventOverlapped; // event overlapped IO structure
  83. BYTE m_EventData[32]; // event data
  84. BOOL m_bPolledEvent; // event polling flag
  85. HKEY m_hFakeEventKey; // event HKEY for simulating notifications
  86. GUID m_guidLastEvent; // Last event ID.
  87. // WIA information
  88. IWiaDrvItem *m_pIDrvItemRoot; // The root item.
  89. IStiDevice *m_pStiDevice; // Sti object.
  90. IWiaLog *m_pIWiaLog; // WIA logging object
  91. BOOL m_bADFEnabled; // ADF enabled flag
  92. BOOL m_bADFAttached; // ADF attached flag
  93. LONG m_lClientsConnected; // number of applications connected
  94. CFakeScanAPI *m_pScanAPI; // FakeScanner API object
  95. LONG m_NumSupportedFormats; // Number of supported formats
  96. WIA_FORMAT_INFO *m_pSupportedFormats; // supported formats
  97. LONG m_NumSupportedCommands; // Number of supported commands
  98. LONG m_NumSupportedEvents; // Number of supported events
  99. WIA_DEV_CAP_DRV *m_pCapabilities; // capabilities
  100. LONG m_NumInitialFormats; // Number of Initial formats
  101. GUID *m_pInitialFormats; // initial formats
  102. BASIC_PROP_INFO m_SupportedTYMED; // supported TYMED
  103. BASIC_PROP_INFO m_SupportedDataTypes; // supported data types
  104. BASIC_PROP_INFO m_SupportedIntents; // supported intents
  105. BASIC_PROP_INFO m_SupportedCompressionTypes; // supported compression types
  106. BASIC_PROP_INFO m_SupportedResolutions; // supported resolutions
  107. BASIC_PROP_INFO m_SupportedPreviewModes;// supported preview modes
  108. LONG m_NumRootItemProperties;// Number of Root item properties
  109. LONG m_NumItemProperties; // Number of item properties
  110. BASIC_PROP_INIT_INFO m_RootItemInitInfo;
  111. BASIC_PROP_INIT_INFO m_ChildItemInitInfo;
  112. public:
  113. /////////////////////////////////////////////////////////////////////////
  114. // Standard COM Section //
  115. /////////////////////////////////////////////////////////////////////////
  116. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  117. STDMETHODIMP_(ULONG) AddRef( void);
  118. STDMETHODIMP_(ULONG) Release( void);
  119. /////////////////////////////////////////////////////////////////////////
  120. // IStiUSD Interface Section (for all WIA drivers) //
  121. /////////////////////////////////////////////////////////////////////////
  122. //
  123. // Methods for implementing the IStiUSD interface.
  124. //
  125. STDMETHOD(Initialize)(THIS_
  126. PSTIDEVICECONTROL pHelDcb,
  127. DWORD dwStiVersion,
  128. HKEY hParametersKey);
  129. STDMETHOD(GetCapabilities)(THIS_
  130. PSTI_USD_CAPS pDevCaps);
  131. STDMETHOD(GetStatus)(THIS_
  132. PSTI_DEVICE_STATUS pDevStatus);
  133. STDMETHOD(DeviceReset)(THIS);
  134. STDMETHOD(Diagnostic)(THIS_
  135. LPDIAG pBuffer);
  136. STDMETHOD(Escape)(THIS_
  137. STI_RAW_CONTROL_CODE EscapeFunction,
  138. LPVOID lpInData,
  139. DWORD cbInDataSize,
  140. LPVOID pOutData,
  141. DWORD dwOutDataSize,
  142. LPDWORD pdwActualData);
  143. STDMETHOD(GetLastError)(THIS_
  144. LPDWORD pdwLastDeviceError);
  145. STDMETHOD(LockDevice)(THIS);
  146. STDMETHOD(UnLockDevice)(THIS);
  147. STDMETHOD(RawReadData)(THIS_
  148. LPVOID lpBuffer,
  149. LPDWORD lpdwNumberOfBytes,
  150. LPOVERLAPPED lpOverlapped);
  151. STDMETHOD(RawWriteData)(THIS_
  152. LPVOID lpBuffer,
  153. DWORD nNumberOfBytes,
  154. LPOVERLAPPED lpOverlapped);
  155. STDMETHOD(RawReadCommand)(THIS_
  156. LPVOID lpBuffer,
  157. LPDWORD lpdwNumberOfBytes,
  158. LPOVERLAPPED lpOverlapped);
  159. STDMETHOD(RawWriteCommand)(THIS_
  160. LPVOID lpBuffer,
  161. DWORD dwNumberOfBytes,
  162. LPOVERLAPPED lpOverlapped);
  163. STDMETHOD(SetNotificationHandle)(THIS_
  164. HANDLE hEvent);
  165. STDMETHOD(GetNotificationData)(THIS_
  166. LPSTINOTIFY lpNotify);
  167. STDMETHOD(GetLastErrorInfo)(THIS_
  168. STI_ERROR_INFO *pLastErrorInfo);
  169. /////////////////////////////////////////////////////////////////////////
  170. // IWiaMiniDrv Interface Section (for all WIA drivers) //
  171. /////////////////////////////////////////////////////////////////////////
  172. //
  173. // Methods for implementing WIA's Mini driver interface
  174. //
  175. STDMETHOD(drvInitializeWia)(THIS_
  176. BYTE *pWiasContext,
  177. LONG lFlags,
  178. BSTR bstrDeviceID,
  179. BSTR bstrRootFullItemName,
  180. IUnknown *pStiDevice,
  181. IUnknown *pIUnknownOuter,
  182. IWiaDrvItem **ppIDrvItemRoot,
  183. IUnknown **ppIUnknownInner,
  184. LONG *plDevErrVal);
  185. STDMETHOD(drvAcquireItemData)(THIS_
  186. BYTE *pWiasContext,
  187. LONG lFlags,
  188. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  189. LONG *plDevErrVal);
  190. STDMETHOD(drvInitItemProperties)(THIS_
  191. BYTE *pWiasContext,
  192. LONG lFlags,
  193. LONG *plDevErrVal);
  194. STDMETHOD(drvValidateItemProperties)(THIS_
  195. BYTE *pWiasContext,
  196. LONG lFlags,
  197. ULONG nPropSpec,
  198. const PROPSPEC *pPropSpec,
  199. LONG *plDevErrVal);
  200. STDMETHOD(drvWriteItemProperties)(THIS_
  201. BYTE *pWiasContext,
  202. LONG lFlags,
  203. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  204. LONG *plDevErrVal);
  205. STDMETHOD(drvReadItemProperties)(THIS_
  206. BYTE *pWiasContext,
  207. LONG lFlags,
  208. ULONG nPropSpec,
  209. const PROPSPEC *pPropSpec,
  210. LONG *plDevErrVal);
  211. STDMETHOD(drvLockWiaDevice)(THIS_
  212. BYTE *pWiasContext,
  213. LONG lFlags,
  214. LONG *plDevErrVal);
  215. STDMETHOD(drvUnLockWiaDevice)(THIS_
  216. BYTE *pWiasContext,
  217. LONG lFlags,
  218. LONG *plDevErrVal);
  219. STDMETHOD(drvAnalyzeItem)(THIS_
  220. BYTE *pWiasContext,
  221. LONG lFlags,
  222. LONG *plDevErrVal);
  223. STDMETHOD(drvGetDeviceErrorStr)(THIS_
  224. LONG lFlags,
  225. LONG lDevErrVal,
  226. LPOLESTR *ppszDevErrStr,
  227. LONG *plDevErr);
  228. STDMETHOD(drvDeviceCommand)(THIS_
  229. BYTE *pWiasContext,
  230. LONG lFlags,
  231. const GUID *plCommand,
  232. IWiaDrvItem **ppWiaDrvItem,
  233. LONG *plDevErrVal);
  234. STDMETHOD(drvGetCapabilities)(THIS_
  235. BYTE *pWiasContext,
  236. LONG ulFlags,
  237. LONG *pcelt,
  238. WIA_DEV_CAP_DRV **ppCapabilities,
  239. LONG *plDevErrVal);
  240. STDMETHOD(drvDeleteItem)(THIS_
  241. BYTE *pWiasContext,
  242. LONG lFlags,
  243. LONG *plDevErrVal);
  244. STDMETHOD(drvFreeDrvItemContext)(THIS_
  245. LONG lFlags,
  246. BYTE *pSpecContext,
  247. LONG *plDevErrVal);
  248. STDMETHOD(drvGetWiaFormatInfo)(THIS_
  249. BYTE *pWiasContext,
  250. LONG lFlags,
  251. LONG *pcelt,
  252. WIA_FORMAT_INFO **ppwfi,
  253. LONG *plDevErrVal);
  254. STDMETHOD(drvNotifyPnpEvent)(THIS_
  255. const GUID *pEventGUID,
  256. BSTR bstrDeviceID,
  257. ULONG ulReserved);
  258. STDMETHOD(drvUnInitializeWia)(THIS_
  259. BYTE *pWiasContext);
  260. /////////////////////////////////////////////////////////////////////////
  261. // INonDelegating Interface Section (for all WIA drivers) //
  262. /////////////////////////////////////////////////////////////////////////
  263. //
  264. // IUnknown-like methods. Needed in conjunction with normal IUnknown
  265. // methods to implement delegating components.
  266. //
  267. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  268. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  269. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  270. private:
  271. /////////////////////////////////////////////////////////////////////////
  272. // Private helper functions section (for your specific driver) //
  273. /////////////////////////////////////////////////////////////////////////
  274. // //
  275. // This section is for private helpers used for common WIA operations. //
  276. // These are custom to your driver. //
  277. // //
  278. // //
  279. // -- WIA Item Management Helpers //
  280. // DeleteItemTree() //
  281. // //
  282. // -- WIA Property Management Helpers //
  283. // BuildRootItemProperties() //
  284. // BuildTopItemProperties() //
  285. // //
  286. // -- WIA Capability Management Helpers //
  287. // BuildRootItemProperties() //
  288. // DeleteRootItemProperties() //
  289. // BuildTopItemProperties() //
  290. // DeleteTopItemProperties() //
  291. // BuildCapabilities() //
  292. // DeleteCapabilitiesArrayContents() //
  293. // BuildSupportedFormats() //
  294. // DeleteSupportedFormatsArrayContents() //
  295. // BuildSupportedDataTypes() //
  296. // DeleteSupportedDataTypesArrayContents() //
  297. // BuildSupportedIntents() //
  298. // DeleteSupportedIntentsArrayContents() //
  299. // BuildSupportedCompressions() //
  300. // DeleteSupportedCompressionsArrayContents() //
  301. // BuildSupportedPreviewModes() //
  302. // DeleteSupportedPreviewModesArrayContents() //
  303. // BuildSupportedTYMED() //
  304. // DeleteSupportedTYMEDArrayContents() //
  305. // BuildSupportedResolutions() //
  306. // DeleteSupportedResolutionsArrayContents() //
  307. // BuildInitialFormats() //
  308. // DeleteInitialFormatsArrayContents() //
  309. // //
  310. // -- WIA Validation Helpers //
  311. // CheckDataType() //
  312. // CheckIntent() //
  313. // CheckPreferredFormat() //
  314. // CheckADFStatus() //
  315. // CheckPreview() //
  316. // CheckXExtent() //
  317. // UpdateValidDepth() //
  318. // UpdateValidPages() //
  319. // ValidateDataTransferContext() //
  320. // //
  321. // -- WIA Resource file Helpers //
  322. // GetBSTRResourceString() //
  323. // GetOLESTRResourceString() //
  324. // //
  325. // -- WIA Data Helpers //
  326. // AlignInPlace() //
  327. // SwapBuffer24() //
  328. // GetPageCount() //
  329. // IsPreviewScan() //
  330. // SetItemSize() //
  331. // //
  332. /////////////////////////////////////////////////////////////////////////
  333. HRESULT DeleteItemTree();
  334. HRESULT BuildRootItemProperties();
  335. HRESULT DeleteRootItemProperties();
  336. HRESULT BuildChildItemProperties();
  337. HRESULT DeleteChildItemProperties();
  338. HRESULT BuildCapabilities();
  339. HRESULT DeleteCapabilitiesArrayContents();
  340. HRESULT BuildSupportedFormats();
  341. HRESULT DeleteSupportedFormatsArrayContents();
  342. HRESULT BuildSupportedDataTypes();
  343. HRESULT DeleteSupportedDataTypesArrayContents();
  344. HRESULT BuildSupportedIntents();
  345. HRESULT DeleteSupportedIntentsArrayContents();
  346. HRESULT BuildSupportedCompressions();
  347. HRESULT DeleteSupportedCompressionsArrayContents();
  348. HRESULT BuildSupportedPreviewModes();
  349. HRESULT DeleteSupportedPreviewModesArrayContents();
  350. HRESULT BuildSupportedTYMED();
  351. HRESULT DeleteSupportedTYMEDArrayContents();
  352. HRESULT BuildSupportedResolutions();
  353. HRESULT DeleteSupportedResolutionsArrayContents();
  354. HRESULT BuildInitialFormats();
  355. HRESULT DeleteInitialFormatsArrayContents();
  356. HRESULT CheckDataType(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  357. HRESULT CheckIntent(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  358. HRESULT CheckPreferredFormat(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  359. HRESULT CheckADFStatus(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  360. HRESULT CheckPreview(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  361. HRESULT CheckXExtent(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext,LONG lWidth);
  362. HRESULT UpdateValidDepth(BYTE *pWiasContext,LONG lDataType,LONG *lDepth);
  363. HRESULT UpdateValidPages(BYTE *pWiasContext,WIA_PROPERTY_CONTEXT *pContext);
  364. HRESULT ValidateDataTransferContext(PMINIDRV_TRANSFER_CONTEXT pDataTransferContext);
  365. HRESULT GetBSTRResourceString(LONG lLocalResourceID,BSTR *pBSTR,BOOL bLocal);
  366. HRESULT GetOLESTRResourceString(LONG lLocalResourceID,LPOLESTR *ppsz,BOOL bLocal);
  367. UINT AlignInPlace(PBYTE pBuffer,LONG cbWritten,LONG lBytesPerScanLine,LONG lBytesPerScanLineRaw);
  368. VOID SwapBuffer24(PBYTE pBuffer,LONG lByteCount);
  369. LONG GetPageCount(BYTE *pWiasContext);
  370. BOOL IsPreviewScan(BYTE *pWiasContext);
  371. HRESULT SetItemSize(BYTE *pWiasContext);
  372. };