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.

591 lines
23 KiB

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