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.

741 lines
22 KiB

  1. /******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: wiaprivd.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 14 Jan, 2000
  10. *
  11. * DESCRIPTION:
  12. * Header file used to define private WIA classes, constants and globals.
  13. *
  14. ******************************************************************************/
  15. #pragma once
  16. #define LOCAL_DEVICE_STR L"local"
  17. //
  18. // Exception handling covers for mini-driver entry points. Defined in helpers
  19. //
  20. HRESULT _stdcall LockWiaDevice(IWiaItem*);
  21. HRESULT _stdcall UnLockWiaDevice(IWiaItem*);
  22. class CWiaDrvItem;
  23. class CWiaTree;
  24. class CWiaPropStg;
  25. class CWiaRemoteTransfer;
  26. void _stdcall CleanupRemoteTransfer(CWiaRemoteTransfer *p);
  27. //**************************************************************************
  28. // class CWiaItem
  29. //
  30. //
  31. //
  32. //
  33. // History:
  34. //
  35. // 11/6/1998 Original Version
  36. //
  37. //**************************************************************************
  38. #define CWIAITEM_SIG 0x49616957 // CWiaItem debug signature: "WiaI"
  39. #define DELETE_ITEM 0 // UpdateWiaItemTree flags
  40. #define ADD_ITEM 1
  41. //
  42. // Item internal flag values
  43. //
  44. #define ITEM_FLAG_DRV_UNINITIALIZE_THROWN 1
  45. class CWiaItem : public IWiaItem,
  46. public IWiaPropertyStorage,
  47. public IWiaDataTransfer,
  48. public IWiaItemExtras,
  49. public IWiaItemInternal
  50. {
  51. //
  52. // IUnknown methods
  53. //
  54. public:
  55. HRESULT _stdcall QueryInterface(const IID& iid, void** ppv);
  56. ULONG _stdcall AddRef(void);
  57. ULONG _stdcall Release(void);
  58. //
  59. // IWiaItem methods
  60. //
  61. virtual HRESULT _stdcall GetItemType(LONG*);
  62. HRESULT _stdcall EnumChildItems(IEnumWiaItem**);
  63. HRESULT _stdcall AnalyzeItem(LONG);
  64. HRESULT _stdcall DeleteItem(LONG);
  65. HRESULT _stdcall CreateChildItem(LONG, BSTR, BSTR, IWiaItem**);
  66. HRESULT _stdcall GetRootItem(IWiaItem**);
  67. HRESULT _stdcall DeviceCommand(LONG, const GUID*, IWiaItem**);
  68. HRESULT _stdcall DeviceDlg(HWND, LONG, LONG, LONG*, IWiaItem***);
  69. HRESULT _stdcall FindItemByName(LONG, BSTR, IWiaItem**);
  70. HRESULT _stdcall EnumRegisterEventInfo(LONG, const GUID *, IEnumWIA_DEV_CAPS**);
  71. HRESULT _stdcall EnumDeviceCapabilities(LONG, IEnumWIA_DEV_CAPS**);
  72. HRESULT _stdcall Diagnostic(ULONG, BYTE*);
  73. //
  74. // IWiaPropertyStorage methods
  75. //
  76. HRESULT _stdcall ReadMultiple(
  77. ULONG,
  78. const PROPSPEC[],
  79. PROPVARIANT[]);
  80. HRESULT _stdcall WriteMultiple(
  81. ULONG,
  82. const PROPSPEC[],
  83. const PROPVARIANT[],
  84. PROPID);
  85. HRESULT _stdcall ReadPropertyNames(
  86. ULONG,
  87. const PROPID[],
  88. LPOLESTR[]);
  89. HRESULT _stdcall WritePropertyNames(
  90. ULONG,
  91. const PROPID[],
  92. const LPOLESTR[]);
  93. HRESULT _stdcall Enum(IEnumSTATPROPSTG**);
  94. HRESULT _stdcall GetPropertyAttributes(
  95. ULONG,
  96. PROPSPEC[],
  97. ULONG[],
  98. PROPVARIANT[]);
  99. HRESULT _stdcall GetPropertyStream(
  100. GUID*,
  101. LPSTREAM*);
  102. HRESULT _stdcall SetPropertyStream(
  103. GUID*,
  104. LPSTREAM);
  105. HRESULT _stdcall GetCount(
  106. ULONG*);
  107. HRESULT _stdcall DeleteMultiple(
  108. ULONG cpspec,
  109. PROPSPEC const rgpspec[]);
  110. HRESULT _stdcall DeletePropertyNames(
  111. ULONG cpropid,
  112. PROPID const rgpropid[]);
  113. HRESULT _stdcall SetClass(
  114. REFCLSID clsid);
  115. HRESULT _stdcall Commit(
  116. DWORD grfCommitFlags);
  117. HRESULT _stdcall Revert();
  118. HRESULT _stdcall Stat(
  119. STATPROPSETSTG *pstatpsstg);
  120. HRESULT _stdcall SetTimes(
  121. FILETIME const * pctime,
  122. FILETIME const * patime,
  123. FILETIME const * pmtime);
  124. //
  125. // IBandedTransfer methods
  126. //
  127. HRESULT _stdcall idtGetBandedData(PWIA_DATA_TRANSFER_INFO, IWiaDataCallback *);
  128. HRESULT _stdcall idtGetData(LPSTGMEDIUM, IWiaDataCallback*);
  129. HRESULT _stdcall idtQueryGetData(WIA_FORMAT_INFO*);
  130. HRESULT _stdcall idtEnumWIA_FORMAT_INFO(IEnumWIA_FORMAT_INFO**);
  131. HRESULT _stdcall idtGetExtendedTransferInfo(PWIA_EXTENDED_TRANSFER_INFO);
  132. //
  133. // IWiaItemExtras methods
  134. //
  135. HRESULT _stdcall GetExtendedErrorInfo(BSTR *);
  136. HRESULT _stdcall Escape(DWORD, BYTE *, DWORD, BYTE *, DWORD, DWORD *);
  137. HRESULT _stdcall CancelPendingIO();
  138. //
  139. // IWiaItemInternal methods
  140. //
  141. HRESULT _stdcall SetCallbackBufferInfo(WIA_DATA_CB_BUF_INFO DataCBBufInfo);
  142. HRESULT _stdcall GetCallbackBufferInfo(WIA_DATA_CB_BUF_INFO *pDataCBBufInfo);
  143. HRESULT _stdcall idtStartRemoteDataTransfer(LPSTGMEDIUM pMedium);
  144. HRESULT _stdcall CWiaItem::idtRemoteDataTransfer(
  145. ULONG nNumberOfBytesToRead,
  146. ULONG *pNumberOfBytesRead,
  147. BYTE *pBuffer,
  148. LONG *pOffset,
  149. LONG *pMessage,
  150. LONG *pStatus,
  151. LONG *pPercentComplete);
  152. HRESULT _stdcall idtStopRemoteDataTransfer();
  153. HRESULT _stdcall idtCancelRemoteDataTransfer();
  154. // this was protected, but it is needed by remote transfer code
  155. HRESULT _stdcall SetMiniDrvItemProperties(PMINIDRV_TRANSFER_CONTEXT);
  156. //
  157. // Driver helpers, not part of any interface.
  158. //
  159. CWiaTree* _stdcall GetTreePtr(void);
  160. CWiaItem* _stdcall GetNextLinearItem(void);
  161. CWiaDrvItem* _stdcall GetDrvItemPtr(void);
  162. HRESULT _stdcall WriteItemPropNames(LONG, PROPID *, LPOLESTR *);
  163. HRESULT _stdcall GetItemPropStreams(IPropertyStorage **, IPropertyStorage **, IPropertyStorage **, IPropertyStorage **);
  164. HRESULT _stdcall UpdateWiaItemTree(LONG, CWiaDrvItem*);
  165. HRESULT _stdcall SendEndOfPage(LONG, PMINIDRV_TRANSFER_CONTEXT);
  166. protected:
  167. //
  168. // banded transfer private methods
  169. //
  170. HRESULT _stdcall idtFreeTransferBufferEx(void);
  171. HRESULT _stdcall idtAllocateTransferBuffer(PWIA_DATA_TRANSFER_INFO pWiaDataTransInfo);
  172. //
  173. // Private helper methods
  174. //
  175. HRESULT _stdcall UnlinkChildAppItemTree(LONG);
  176. HRESULT _stdcall UnlinkAppItemTree(LONG);
  177. HRESULT _stdcall BuildWiaItemTreeHelper(CWiaDrvItem*, CWiaTree*);
  178. HRESULT _stdcall BuildWiaItemTree(IWiaPropertyStorage*);
  179. HRESULT _stdcall InitWiaManagedItemProperties(IWiaPropertyStorage *pIWiaDevInfoProps);
  180. HRESULT _stdcall InitRootProperties(IWiaPropertyStorage*);
  181. HRESULT _stdcall SendDataHeader(LONG, PMINIDRV_TRANSFER_CONTEXT);
  182. HRESULT _stdcall SendOOBDataHeader(LONG, PMINIDRV_TRANSFER_CONTEXT);
  183. HRESULT _stdcall AcquireMiniDrvItemData(PMINIDRV_TRANSFER_CONTEXT);
  184. HRESULT _stdcall GetData(STGMEDIUM*, IWiaDataCallback*,PMINIDRV_TRANSFER_CONTEXT);
  185. HRESULT _stdcall GetDataBanded(PWIA_DATA_TRANSFER_INFO, IWiaDataCallback*, PMINIDRV_TRANSFER_CONTEXT);
  186. HRESULT _stdcall CommonGetData(STGMEDIUM*, PWIA_DATA_TRANSFER_INFO, IWiaDataCallback*);
  187. HRESULT _stdcall DumpItemData(BSTR*);
  188. HRESULT _stdcall DumpDrvItemData(BSTR*);
  189. HRESULT _stdcall DumpTreeItemData(BSTR*);
  190. HRESULT _stdcall InitLazyProps(BOOL = TRUE);
  191. HRESULT _stdcall AddVolumePropertiesToRoot(ACTIVE_DEVICE *pActiveDevice);
  192. //
  193. // Constructor, initialization and destructor methods.
  194. //
  195. public:
  196. CWiaItem();
  197. virtual HRESULT _stdcall Initialize(
  198. IWiaItem*,
  199. IWiaPropertyStorage*,
  200. ACTIVE_DEVICE*,
  201. CWiaDrvItem*,
  202. IUnknown* = NULL);
  203. ~CWiaItem();
  204. //
  205. // Misc. members
  206. //
  207. ULONG m_ulSig; // Object signature.
  208. CWiaTree *m_pCWiaTree; // Backing WIA tree item.
  209. BOOL m_bInitialized; // Needed for lazy initialization
  210. BYTE *m_pICMValues; // Cached ICM property values
  211. LONG m_lICMSize; // Size of ICM values
  212. ACTIVE_DEVICE *m_pActiveDevice; // ptr to Device object.
  213. LONG m_lLastDevErrVal; // Value of last device error
  214. LONG m_lInternalFlags; // Internal flag value
  215. protected:
  216. ULONG m_cRef; // Reference count for this object.
  217. ULONG m_cLocalRef; // Local reference count for this object.
  218. CWiaDrvItem *m_pWiaDrvItem; // device item object
  219. IUnknown *m_pIUnknownInner; // Inner unknown for blind aggregation.
  220. //
  221. // saved interface pointers
  222. //
  223. IWiaItem *m_pIWiaItemRoot; // owning device
  224. //
  225. // application properties
  226. //
  227. CWiaPropStg *m_pPropStg; // Wia Property Storage Class
  228. //
  229. // IWiaDataTransfer members
  230. //
  231. WIA_DATA_CB_BUF_INFO m_dcbInfo;
  232. HANDLE m_hBandSection;
  233. PBYTE m_pBandBuffer;
  234. LONG m_lBandBufferLength;
  235. LONG m_ClientBaseAddress;
  236. BOOL m_bMapSection;
  237. ULONG m_cwfiBandedTran; // Number of FORMATETCs in use for IBandedTransfer
  238. WIA_FORMAT_INFO *m_pwfiBandedTran; // Source of FORMATETCs for IBandedTransfer
  239. MINIDRV_TRANSFER_CONTEXT m_mdtc; // transfer context
  240. CWiaRemoteTransfer *m_pRemoteTransfer; // remote transfer support
  241. };
  242. //**************************************************************************
  243. // class CGenWiaItem
  244. //
  245. // This class implements the IWiaItem interface for generated items.
  246. //
  247. //
  248. // History:
  249. //
  250. // 14 Jan, 2000 - Original version
  251. //
  252. //**************************************************************************
  253. class CGenWiaItem : public CWiaItem
  254. {
  255. public:
  256. //
  257. // CWiaItem methods overridden for Generated items
  258. //
  259. HRESULT _stdcall Initialize(
  260. IWiaItem*,
  261. IWiaPropertyStorage*,
  262. ACTIVE_DEVICE*,
  263. CWiaDrvItem*,
  264. IUnknown* = NULL);
  265. HRESULT _stdcall GetItemType(LONG*);
  266. //
  267. // Helper methods
  268. //
  269. HRESULT _stdcall InitManagedItemProperties(
  270. LONG lFlags,
  271. BSTR bstrItemName,
  272. BSTR bstrFullItemName);
  273. protected:
  274. LONG m_lItemType; // Item type flags
  275. };
  276. //**************************************************************************
  277. //
  278. // CWiaMiniDrvCallBack
  279. //
  280. // This class is used by the driver services to callback to the client
  281. //
  282. //
  283. // History:
  284. //
  285. // 11/12/1998 Original Version
  286. //
  287. //**************************************************************************
  288. class CWiaMiniDrvCallBack : public IWiaMiniDrvCallBack
  289. {
  290. //
  291. // IUnknown methods
  292. //
  293. public:
  294. HRESULT _stdcall QueryInterface(const IID&,void**);
  295. ULONG _stdcall AddRef();
  296. ULONG _stdcall Release();
  297. //
  298. // IWiaMiniDrvCallBack methods
  299. //
  300. HRESULT _stdcall MiniDrvCallback(
  301. LONG,
  302. LONG,
  303. LONG,
  304. LONG,
  305. LONG,
  306. PMINIDRV_TRANSFER_CONTEXT,
  307. LONG);
  308. //
  309. // Constructor, initialization and destructor methods.
  310. //
  311. CWiaMiniDrvCallBack();
  312. HRESULT Initialize(PMINIDRV_TRANSFER_CONTEXT, IWiaDataCallback *);
  313. ~CWiaMiniDrvCallBack();
  314. //
  315. // Misc. members
  316. //
  317. private:
  318. ULONG m_cRef; // Object reference count.
  319. IWiaDataCallback* m_pIWiaDataCallback; // Client callback interface pointer
  320. MINIDRV_TRANSFER_CONTEXT m_mdtc; // transfer info
  321. HANDLE m_hThread; // callback thread
  322. DWORD m_dwThreadID; // callback thread ID
  323. WIA_DATA_THREAD_INFO m_ThreadInfo; // thread info
  324. };
  325. //**************************************************************************
  326. // APP_ITEM_LIST_EL
  327. //
  328. // Applictation item list element. Used by driver items to keep track
  329. // of their corresponding app items.
  330. //
  331. // History:
  332. //
  333. // 9/1/1998 - Initial Version
  334. //
  335. //**************************************************************************
  336. typedef struct _APP_ITEM_LIST_EL {
  337. LIST_ENTRY ListEntry; // Linked list management.
  338. CWiaItem *pCWiaItem; // Applictation item.
  339. } APP_ITEM_LIST_EL, *PAPP_ITEM_LIST_EL;
  340. //**************************************************************************
  341. //
  342. // Driver Item Object
  343. //
  344. //
  345. // Elements:
  346. //
  347. //
  348. // History:
  349. //
  350. // 9/1/1998 - Initial Version
  351. //
  352. //**************************************************************************
  353. #define CWIADRVITEM_SIG 0x44616957 // CWiaDrvItem debug signature: "WiaD"
  354. class CWiaDrvItem : public IWiaDrvItem
  355. {
  356. //
  357. // IUnknown methods
  358. //
  359. public:
  360. HRESULT _stdcall QueryInterface(const IID& iid, void** ppv);
  361. ULONG _stdcall AddRef(void);
  362. ULONG _stdcall Release(void);
  363. //
  364. // Object Constructor/Initialization/Destructor methods
  365. //
  366. CWiaDrvItem();
  367. HRESULT _stdcall Initialize(LONG,BSTR,BSTR,IWiaMiniDrv*,LONG,BYTE**);
  368. ~CWiaDrvItem();
  369. //
  370. // IWiaDrvItem interface, supports driver item list management.
  371. //
  372. HRESULT _stdcall GetItemFlags(LONG*);
  373. HRESULT _stdcall GetDeviceSpecContext(BYTE**);
  374. HRESULT _stdcall AddItemToFolder(IWiaDrvItem*);
  375. HRESULT _stdcall RemoveItemFromFolder(LONG);
  376. HRESULT _stdcall UnlinkItemTree(LONG);
  377. HRESULT _stdcall GetFullItemName(BSTR*);
  378. HRESULT _stdcall GetItemName(BSTR*);
  379. HRESULT _stdcall FindItemByName(LONG, BSTR, IWiaDrvItem**);
  380. HRESULT _stdcall FindChildItemByName(BSTR, IWiaDrvItem**);
  381. HRESULT _stdcall GetParentItem(IWiaDrvItem**);
  382. HRESULT _stdcall GetFirstChildItem(IWiaDrvItem**);
  383. HRESULT _stdcall GetNextSiblingItem(IWiaDrvItem**);
  384. HRESULT _stdcall DumpItemData(BSTR*);
  385. //
  386. // Class driver helpers, not part of any interface.
  387. //
  388. virtual HRESULT _stdcall LinkToDrvItem(CWiaItem*);
  389. virtual HRESULT _stdcall UnlinkFromDrvItem(CWiaItem*);
  390. HRESULT _stdcall CallDrvUninitializeForAppItems(ACTIVE_DEVICE *pActiveDevice);
  391. VOID SetActiveDevice(ACTIVE_DEVICE *pActiveDevice)
  392. {
  393. //
  394. // No need to AddRef here, since the ActiveDevice will always outlive
  395. // us...
  396. //
  397. m_pActiveDevice = pActiveDevice;
  398. }
  399. private:
  400. //
  401. // private helper functions
  402. //
  403. HRESULT _stdcall AllocDeviceSpecContext(LONG, PBYTE*);
  404. HRESULT _stdcall FreeDeviceSpecContext(void);
  405. //
  406. // member data
  407. //
  408. public:
  409. ULONG m_ulSig; // Object signature.
  410. BYTE *m_pbDrvItemContext; // ptr to device specific context.
  411. IWiaMiniDrv *m_pIWiaMiniDrv; // ptr to Device object.
  412. ACTIVE_DEVICE *m_pActiveDevice; // ptr to Active Device object.
  413. private:
  414. ULONG m_cRef; // Reference count for this object.
  415. CWiaTree *m_pCWiaTree; // Backing WIA tree item.
  416. LIST_ENTRY m_leAppItemListHead; // Head of corresponding app items list.
  417. };
  418. //**************************************************************************
  419. //
  420. // WIA Tree Object
  421. //
  422. //
  423. // Elements:
  424. //
  425. //
  426. // History:
  427. //
  428. // 4/27/1999 - Initial Version
  429. //
  430. //**************************************************************************
  431. typedef VOID (* PFN_UNLINK_CALLBACK)(VOID *pData);
  432. #define CWIATREE_SIG 0x44616954 // CWiaTree debug signature: "WiaT"
  433. class CWiaTree
  434. {
  435. public:
  436. CWiaTree();
  437. HRESULT _stdcall Initialize(LONG, BSTR, BSTR, void*);
  438. ~CWiaTree();
  439. HRESULT _stdcall AddItemToFolder(CWiaTree*);
  440. HRESULT _stdcall RemoveItemFromFolder(LONG);
  441. HRESULT _stdcall UnlinkItemTree(LONG, PFN_UNLINK_CALLBACK = NULL);
  442. HRESULT _stdcall GetFullItemName(BSTR*);
  443. HRESULT _stdcall GetItemName(BSTR*);
  444. HRESULT _stdcall FindItemByName(LONG, BSTR, CWiaTree**);
  445. HRESULT _stdcall FindChildItemByName(BSTR, CWiaTree**);
  446. HRESULT _stdcall GetParentItem(CWiaTree**);
  447. HRESULT _stdcall GetFirstChildItem(CWiaTree**);
  448. HRESULT _stdcall GetNextSiblingItem(CWiaTree**);
  449. HRESULT _stdcall DumpTreeData(BSTR*);
  450. //HRESULT _stdcall DumpAllTreeData();
  451. CWiaTree * _stdcall GetRootItem(void);
  452. CWiaItem * _stdcall GetNextLinearItem(void);
  453. inline HRESULT _stdcall CWiaTree::GetItemFlags(LONG *plFlags)
  454. {
  455. if (plFlags) {
  456. *plFlags = m_lFlags;
  457. return S_OK;
  458. }
  459. else {
  460. return E_POINTER;
  461. }
  462. }
  463. inline HRESULT _stdcall GetItemData(void **ppData)
  464. {
  465. if (ppData) {
  466. *ppData = m_pData;
  467. return S_OK;
  468. }
  469. else {
  470. return E_POINTER;
  471. }
  472. }
  473. inline HRESULT _stdcall SetItemData(void *pData)
  474. {
  475. m_pData = pData;
  476. return S_OK;
  477. }
  478. inline HRESULT _stdcall SetFolderFlags()
  479. {
  480. m_lFlags = (m_lFlags | WiaItemTypeFolder) & ~WiaItemTypeFile;
  481. return S_OK;
  482. }
  483. inline HRESULT _stdcall SetFileFlags()
  484. {
  485. m_lFlags = (m_lFlags | WiaItemTypeFile) & ~WiaItemTypeFolder;
  486. return S_OK;
  487. }
  488. private:
  489. //
  490. // private helper functions
  491. //
  492. HRESULT _stdcall UnlinkChildItemTree(LONG, PFN_UNLINK_CALLBACK = NULL);
  493. HRESULT _stdcall AddChildItem(CWiaTree*);
  494. HRESULT _stdcall AddItemToLinearList(CWiaTree*);
  495. HRESULT _stdcall RemoveItemFromLinearList(CWiaTree*);
  496. //
  497. // member data
  498. //
  499. public:
  500. ULONG m_ulSig; // Object signature.
  501. private:
  502. LONG m_lFlags; // item flags
  503. CWiaTree *m_pNext; // next item (sibling)
  504. CWiaTree *m_pPrev; // prev item (sibling)
  505. CWiaTree *m_pParent; // parent item
  506. CWiaTree *m_pChild; // child item
  507. CWiaTree *m_pLinearList; // single linked list of all items
  508. BSTR m_bstrItemName; // item name
  509. BSTR m_bstrFullItemName; // item name for searching
  510. void *m_pData; // pay load
  511. CRITICAL_SECTION m_CritSect; // Critical section
  512. BOOL m_bInitCritSect; // Critical section initialization flag
  513. };
  514. //
  515. // Helper classes
  516. //
  517. //
  518. // Helper class to lock/unlock WIA devices. Note that this helper class will
  519. // record the return code (in phr), but does not log any errors. Logging is
  520. // left up to the caller.
  521. //
  522. class LOCK_WIA_DEVICE
  523. {
  524. public:
  525. //
  526. // This constructor will lock the device
  527. //
  528. LOCK_WIA_DEVICE(CWiaItem *pItem,
  529. HRESULT *phr
  530. )
  531. {
  532. LONG lDevErrVal = 0;
  533. m_bDeviceIsLocked = FALSE;
  534. m_pItem = NULL;
  535. if (pItem) {
  536. if (pItem->m_pActiveDevice) {
  537. *phr = pItem->m_pActiveDevice->m_DrvWrapper.WIA_drvLockWiaDevice((BYTE*) pItem, 0, &lDevErrVal);
  538. if (SUCCEEDED(*phr)) {
  539. //
  540. // Mark that the device is locked, so we can unlock it in the destructor
  541. //
  542. m_bDeviceIsLocked = TRUE;
  543. m_pItem = pItem;
  544. } else {
  545. DBG_TRC(("LOCK_WIA_DEVICE, failed to lock device"));
  546. }
  547. } else {
  548. DBG_TRC(("LOCK_WIA_DEVICE, Item's ACTIVE_DEVICE is NULL"));
  549. }
  550. } else {
  551. DBG_TRC(("LOCK_WIA_DEVICE, Item is NULL"));
  552. }
  553. };
  554. //
  555. // Sometimes, we only want to lock the device if we are told at run-time e.g.
  556. // if the device is already locked, we don't need/want to lock it again.
  557. //
  558. LOCK_WIA_DEVICE(BOOL bLockDevice,
  559. CWiaItem *pItem,
  560. HRESULT *phr
  561. )
  562. {
  563. m_bDeviceIsLocked = FALSE;
  564. if (bLockDevice) {
  565. LONG lDevErrVal = 0;
  566. //
  567. // NOTE: There seems to be some sort of compiler error if we call the
  568. // other constructor from here. The code genereated messes up the
  569. // stack (almost like mismatched calling conventions). To get around
  570. // that, we simply duplicate the code.
  571. //
  572. m_pItem = NULL;
  573. if (pItem) {
  574. if (pItem->m_pActiveDevice) {
  575. *phr = pItem->m_pActiveDevice->m_DrvWrapper.WIA_drvLockWiaDevice((BYTE*) pItem, 0, &lDevErrVal);
  576. if (SUCCEEDED(*phr)) {
  577. //
  578. // Mark that the device is locked, so we can unlock it in the destructor
  579. //
  580. m_bDeviceIsLocked = TRUE;
  581. m_pItem = pItem;
  582. }
  583. }
  584. }
  585. }
  586. };
  587. //
  588. // The destructor will unlock the device if it has been locked
  589. //
  590. ~LOCK_WIA_DEVICE()
  591. {
  592. if (m_bDeviceIsLocked) {
  593. LONG lDevErrVal = 0;
  594. //
  595. // Notice that we don't care if we failed to unlock
  596. //
  597. m_pItem->m_pActiveDevice->m_DrvWrapper.WIA_drvUnLockWiaDevice((BYTE*) m_pItem, 0, &lDevErrVal);
  598. }
  599. };
  600. private:
  601. BOOL m_bDeviceIsLocked;
  602. CWiaItem *m_pItem;
  603. };