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.

5160 lines
194 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2002
  4. *
  5. * TITLE: IWiaMiniDrv.cpp
  6. *
  7. * VERSION: 1.1
  8. *
  9. * DATE: 05 March, 2002
  10. *
  11. * DESCRIPTION:
  12. * Implementation of the WIA sample scanner IWiaMiniDrv methods.
  13. *
  14. *******************************************************************************/
  15. #include "pch.h"
  16. #include <stdio.h>
  17. extern HINSTANCE g_hInst; // used for WIAS_LOGPROC macro
  18. /**************************************************************************\
  19. * CWIADevice::drvInitializeWia
  20. *
  21. * drvInitializeWia is called by the WIA service in response to a WIA
  22. * application's call to IWiaDevMgr::CreateDevice (described in the
  23. * Platform SDK documentation), which means that this method is
  24. * called once for each new client connection.
  25. *
  26. * This method should initialize any private structures and create the
  27. * driver item tree. The driver item tree shows the layout of all WIA
  28. * items supported by this WIA device. This method is for creating the
  29. * initial tree structure only, NOT the contents (WIA properties). WIA properties for
  30. * these WIA driver items will be populated individually by multiple calls by
  31. * the WIA service to IWiaMiniDrv::drvInitItemProperties().
  32. *
  33. * All WIA devices have a ROOT item. This item is the parent to all
  34. * WIA device items. To create a WIA device item the WIA driver should call
  35. * the WIA service helper function. wiasCreateDrvItem().
  36. *
  37. * Example:
  38. *
  39. * Creating a WIA device ROOT item might look like the following:
  40. *
  41. * LONG lItemFlags = WiaItemTypeFolder|WiaItemTypeDevice|WiaItemTypeRoot;
  42. *
  43. * IWiaDrvItem *pIWiaDrvRootItem = NULL;
  44. *
  45. * HRESULT hr = wiasCreateDrvItem(lItemFlags, // item flags
  46. * bstrRootItemName, // item name ("Root")
  47. * bstrRootFullItemName, // item full name ("0000\Root")
  48. * (IWiaMiniDrv *)this, // this WIA driver object
  49. * sizeof(MINIDRIVERITEMCONTEXT), // size of context
  50. * NULL, // context
  51. * &pIWiaDrvRootItem); // created ROOT item
  52. * // (IWiaDrvItem interface)
  53. *
  54. * if(S_OK == hr){
  55. *
  56. * //
  57. * // ROOT item was created successfully
  58. * //
  59. *
  60. * }
  61. *
  62. * Example:
  63. *
  64. * Creating a WIA child item, located directly under the ROOT item we created in the
  65. * above sample might look like the following:
  66. *
  67. * NOTE: notice the calling of IWiaDrvItem::AddItemToFolder() method to add the
  68. * newly created chld item to the ROOT item.
  69. *
  70. * LONG lItemFlags = WiaItemTypeFile|WiaItemTypeDevice|WiaItemTypeImage;
  71. *
  72. * PMINIDRIVERITEMCONTEXT pItemContext = NULL;
  73. * IWiaDrvItem *pIWiaDrvNewItem = NULL;
  74. *
  75. * HRESULT hr = wiasCreateDrvItem(lItemFlags, // item flags
  76. * bstrItemName, // item name ("Flatbed")
  77. * bstrFullItemName, // item full name ("0000\Root\Flatbed")
  78. * (IWiaMiniDrv *)this, // this WIA driver object
  79. * sizeof(MINIDRIVERITEMCONTEXT), // size of context
  80. * (PBYTE)&pItemContext, // context
  81. * &pIWiaDrvNewItem); // created child item
  82. * // (IWiaDrvItem interface)
  83. *
  84. * if(S_OK == hr){
  85. *
  86. * //
  87. * // A New WIA driver item was created successfully
  88. * //
  89. *
  90. * hr = pIWiaDrvNewItem->AddItemToFolder(pIWiaDrvRootItem); // add the new item to the ROOT
  91. * if(S_OK == hr){
  92. *
  93. * //
  94. * // successfully created and added a new WIA driver item to the WIA driver item
  95. * // tree.
  96. * //
  97. *
  98. * }
  99. * pNewItem->Release();
  100. * pNewItem = NULL;
  101. * }
  102. *
  103. *
  104. * See the DDK documentation on the proper flags for describing a WIA driver item.
  105. *
  106. *
  107. * Arguments:
  108. *
  109. * pWiasContext - Pointer to the WIA item, unused.
  110. * lFlags - Operation flags, unused.
  111. * bstrDeviceID - Device ID.
  112. * bstrRootFullItemName - Full item name.
  113. * pIPropStg - Device info. properties.
  114. * pStiDevice - STI device interface.
  115. * pIUnknownOuter - Outer unknown interface.
  116. * ppIDrvItemRoot - Pointer to returned root item.
  117. * ppIUnknownInner - Pointer to returned inner unknown.
  118. * plDevErrVal - Pointer to the device error value.
  119. *
  120. * Return Value:
  121. *
  122. * S_OK - if the operation was successful
  123. * E_xxx - Error Code if the operation failed
  124. *
  125. * Sample Notes:
  126. * This WIA sample driver calls an internal helper function called BuildItemTree().
  127. * This function follows the instructions outlined in the comments for
  128. * creating WIA driver items.
  129. * This WIA sample driver also breaks the initialization of some internal
  130. * structures (i.e. BuildCapabilities()) into separate helper functions.
  131. * When this driver's drvInitializeWia() method is called, it takes a moment
  132. * to create the necessary data for WIA property initialization (which happens
  133. * at the drvInitItemProperties)
  134. *
  135. * History:
  136. *
  137. * 03/05/2002 Original Version
  138. *
  139. \**************************************************************************/
  140. HRESULT _stdcall CWIADevice::drvInitializeWia(
  141. BYTE *pWiasContext,
  142. LONG lFlags,
  143. BSTR bstrDeviceID,
  144. BSTR bstrRootFullItemName,
  145. IUnknown *pStiDevice,
  146. IUnknown *pIUnknownOuter,
  147. IWiaDrvItem **ppIDrvItemRoot,
  148. IUnknown **ppIUnknownInner,
  149. LONG *plDevErrVal)
  150. {
  151. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  152. WIALOG_NO_RESOURCE_ID,
  153. WIALOG_LEVEL1,
  154. "CWIADevice::drvInitializeWia");
  155. //
  156. // If the caller did not pass in the correct parameters, then fail the
  157. // call with E_INVALIDARG.
  158. //
  159. if (!pWiasContext) {
  160. return E_INVALIDARG;
  161. }
  162. if (!plDevErrVal) {
  163. return E_INVALIDARG;
  164. }
  165. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitializeWia, bstrDeviceID = %ws", bstrDeviceID));
  166. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitializeWia, bstrRootFullItemName = %ws",bstrRootFullItemName));
  167. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitializeWia, lFlags = %d",lFlags));
  168. HRESULT hr = S_OK;
  169. *plDevErrVal = 0;
  170. *ppIDrvItemRoot = NULL;
  171. *ppIUnknownInner = NULL;
  172. //
  173. // Need to init names and STI pointer?
  174. //
  175. if (m_pStiDevice == NULL) {
  176. //
  177. // save STI device interface for locking
  178. //
  179. m_pStiDevice = (IStiDevice *)pStiDevice;
  180. }
  181. //
  182. // Initialize Capabilities array
  183. //
  184. hr = BuildCapabilities();
  185. if (FAILED(hr)) {
  186. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildCapabilities failed"));
  187. WIAS_LHRESULT(m_pIWiaLog, hr);
  188. return hr;
  189. }
  190. //
  191. // Initialize SupportedFormats array
  192. //
  193. hr = BuildSupportedFormats();
  194. if (FAILED(hr)) {
  195. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedFormats failed"));
  196. WIAS_LHRESULT(m_pIWiaLog, hr);
  197. return hr;
  198. }
  199. //
  200. // Initialize Supported Data Type array
  201. //
  202. hr = BuildSupportedDataTypes();
  203. if (FAILED(hr)) {
  204. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedDataTypes failed"));
  205. WIAS_LHRESULT(m_pIWiaLog, hr);
  206. return hr;
  207. }
  208. //
  209. // Initialize Supported Intents array
  210. //
  211. hr = BuildSupportedIntents();
  212. if (FAILED(hr)) {
  213. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedIntents failed"));
  214. WIAS_LHRESULT(m_pIWiaLog, hr);
  215. return hr;
  216. }
  217. //
  218. // Initialize Supported TYMED array
  219. //
  220. hr = BuildSupportedTYMED();
  221. if (FAILED(hr)) {
  222. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSuportedTYMED failed"));
  223. WIAS_LHRESULT(m_pIWiaLog, hr);
  224. return hr;
  225. }
  226. //
  227. // Initialize Supported compression types array
  228. //
  229. hr = BuildSupportedCompressions();
  230. if (FAILED(hr)) {
  231. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedCompressions"));
  232. WIAS_LHRESULT(m_pIWiaLog, hr);
  233. return hr;
  234. }
  235. //
  236. // Initialize Supported Preview modes array
  237. //
  238. hr = BuildSupportedPreviewModes();
  239. if (FAILED(hr)) {
  240. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedPreviewModes"));
  241. WIAS_LHRESULT(m_pIWiaLog, hr);
  242. return hr;
  243. }
  244. //
  245. // Initialize initial formats array
  246. //
  247. hr = BuildInitialFormats();
  248. if (FAILED(hr)) {
  249. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildInitialFormats failed"));
  250. WIAS_LHRESULT(m_pIWiaLog, hr);
  251. return hr;
  252. }
  253. //
  254. // Initialize supported resolutions array
  255. //
  256. hr = BuildSupportedResolutions();
  257. if (FAILED(hr)) {
  258. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitializeWia, BuildSupportedResolutions failed"));
  259. WIAS_LHRESULT(m_pIWiaLog, hr);
  260. return hr;
  261. }
  262. //
  263. // build WIA item tree
  264. //
  265. LONG lItemFlags = WiaItemTypeFolder|WiaItemTypeDevice|WiaItemTypeRoot;
  266. IWiaDrvItem *pIWiaDrvRootItem = NULL;
  267. //
  268. // create the ROOT item of the WIA device. This name should NOT be localized
  269. // in different languages. "Root" is used by WIA drivers.
  270. //
  271. BSTR bstrRootItemName = SysAllocString(WIA_DEVICE_ROOT_NAME);
  272. if(!bstrRootItemName) {
  273. return E_OUTOFMEMORY;
  274. }
  275. hr = wiasCreateDrvItem(lItemFlags, // item flags
  276. bstrRootItemName, // item name ("Root")
  277. bstrRootFullItemName, // item full name ("0000\Root")
  278. (IWiaMiniDrv *)this, // this WIA driver object
  279. sizeof(MINIDRIVERITEMCONTEXT), // size of context
  280. NULL, // context
  281. &pIWiaDrvRootItem); // created ROOT item
  282. // (IWiaDrvItem interface)
  283. if (S_OK == hr) {
  284. //
  285. // ROOT item was created successfully, save the newly created Root item
  286. // in the pointer given by the WIA service (ppIDrvItemRoot).
  287. //
  288. *ppIDrvItemRoot = pIWiaDrvRootItem;
  289. //
  290. // Create a child item directly under the Root WIA item
  291. //
  292. lItemFlags = WiaItemTypeFile|WiaItemTypeDevice|WiaItemTypeImage;
  293. PMINIDRIVERITEMCONTEXT pItemContext = NULL;
  294. IWiaDrvItem *pIWiaDrvNewItem = NULL;
  295. //
  296. // create a name for the WIA child item. "Flatbed" is used by WIA drivers that
  297. // support a flatbed scanner.
  298. //
  299. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  300. BSTR bstrItemName = SysAllocString(WIA_DEVICE_FEEDER_NAME);
  301. #else
  302. BSTR bstrItemName = SysAllocString(WIA_DEVICE_FLATBED_NAME);
  303. #endif
  304. if (bstrItemName) {
  305. WCHAR wszFullItemName[MAX_PATH + 1] = {0};
  306. _snwprintf(wszFullItemName,(sizeof(wszFullItemName) / sizeof(WCHAR)) - 1,L"%ls\\%ls",
  307. bstrRootFullItemName,bstrItemName);
  308. BSTR bstrFullItemName = SysAllocString(wszFullItemName);
  309. if (bstrFullItemName) {
  310. hr = wiasCreateDrvItem(lItemFlags, // item flags
  311. bstrItemName, // item name ("Flatbed")
  312. bstrFullItemName, // item full name ("0000\Root\Flatbed")
  313. (IWiaMiniDrv *)this, // this WIA driver object
  314. sizeof(MINIDRIVERITEMCONTEXT), // size of context
  315. (BYTE**)&pItemContext, // context
  316. &pIWiaDrvNewItem); // created child item
  317. // (IWiaDrvItem interface)
  318. if (S_OK == hr) {
  319. //
  320. // A New WIA driver item was created successfully
  321. //
  322. hr = pIWiaDrvNewItem->AddItemToFolder(pIWiaDrvRootItem); // add the new item to the ROOT
  323. if (S_OK == hr) {
  324. //
  325. // successfully created and added a new WIA driver item to the WIA driver item
  326. // tree.
  327. //
  328. }
  329. //
  330. // The new item is no longer needed, because it has been passed to the WIA
  331. // service.
  332. //
  333. pIWiaDrvNewItem->Release();
  334. pIWiaDrvNewItem = NULL;
  335. }
  336. SysFreeString(bstrFullItemName);
  337. bstrFullItemName = NULL;
  338. } else {
  339. hr = E_OUTOFMEMORY;
  340. }
  341. SysFreeString(bstrItemName);
  342. bstrItemName = NULL;
  343. } else {
  344. hr = E_OUTOFMEMORY;
  345. }
  346. }
  347. //
  348. // increment application connection count
  349. //
  350. if(S_OK == hr){
  351. InterlockedIncrement(&m_lClientsConnected);
  352. }
  353. return hr;
  354. }
  355. /**************************************************************************\
  356. * CWIADevice::drvAcquireItemData
  357. *
  358. * drvAcquireItemData is called by the WIA service when data it being
  359. * requested from a WIA item. The WIA driver should determine what type of
  360. * transfer the application is attempting by looking at the following
  361. * members of the MINIDRV_TRANSFER_CONTEXT:
  362. *
  363. * pmdtc->tymed - TYMED set by the application.
  364. * TYMED_FILE - transfer for file.
  365. * TYMED_MULTIPAGE_FILE - transfer to a multipage file format
  366. * TYMED_CALLBACK - transfer to memory
  367. * TYMED_MULTIPAGE_CALLBACK - transfer to memory (multiple pages)
  368. *
  369. * The different TYMED settings xxx_CALLBACK and xxx_FILE change the usage of
  370. * calling the application's callback interface.
  371. *
  372. * xxx_CALLBACK:
  373. * call: pmdtc->pIWiaMiniDrvCallBack->MiniDrvCallback()
  374. *
  375. * IT_MSG_DATA - we are transferring data.
  376. * IT_STATUS_TRANSFER_TO_CLIENT - data transfer message
  377. * PercentComplete - percent complete of the entire transfer
  378. * pmdtc->cbOffset - should be updated on the current location
  379. * that the application should write the next
  380. * data chunk.
  381. * BytesReceived - number of bytes in the data chunk being sent to the
  382. * application.
  383. * pmdtc - MINIDRV_TRANSFER_CONTEXT context
  384. *
  385. * xxx_FILE:
  386. * call: pmdtc->pIWiaMiniDrvCallBack->MiniDrvCallback()
  387. *
  388. * IT_MSG_STATUS - we are only sending status (NO DATA!!!)
  389. * IT_STATUS_TRANSFER_TO_CLIENT - data transfer message
  390. * PercentComplete - percent complete of the entire transfer
  391. *
  392. * Arguments:
  393. *
  394. * pWiasContext - Pointer to the WIA item, Item used for transfer
  395. * lFlags - Operation flags, unused.
  396. * pmdtc - Pointer to mini driver context.
  397. * plDevErrVal - Pointer to the device error value.
  398. *
  399. * Return Value:
  400. *
  401. * S_OK - if the operation was successful
  402. * E_xxx - Error Code if the operation failed
  403. *
  404. * Sample Notes:
  405. * This WIA sample driver transfers data from two different sources.
  406. * 1. flatbed
  407. * 2. document feeder
  408. * a. standard feeder type
  409. * b. unknown page length feeder type
  410. * (when the UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER is used to build the
  411. * driver)
  412. *
  413. * Notice the percent complete calculations for the unknown page length
  414. * scanner. This sample knows that it can receive any page length from
  415. * the user. It also knows that the average page used in this device is
  416. * AVERAGE_FAKE_PAGE_HEIGHT_INCHES in height. Taking this into account
  417. * it calculates a rough percentage, so it an return percent complete to
  418. * the application. When it receives data larger than the average page
  419. * length, it halts the percent complete to 95%, allowing the scan to
  420. * complete. There are better ways to do this, and this is the one this
  421. * sample chooses to use.
  422. *
  423. * Scanning from a feeder:
  424. *
  425. * This WIA sample driver performs a few checks before continuing with a
  426. * feeder scan.
  427. *
  428. * 1. check if we are in FEEDER mode.
  429. * - This is done by looking at the m_bADFEnabled flag. This flag is
  430. * set to TRUE when an application writes the WIA_DPS_DOCUMENT_HANDLING_SELECT
  431. * property to FEEDER.
  432. * 2. checks the requested page count.
  433. * - This is done by looking at the WIA_DPS_PAGES property, set by the
  434. * application.
  435. * zero ( 0) = scan all pages in the feeder
  436. * greater than (>0) = scan up to the requested amount.
  437. * 3. unfeeds a previous page.
  438. * - This could be a jammed page, or the last page in the feeder scanned.
  439. * Only do this if your device requires the ADF to be cleared before
  440. * use.
  441. * 4. checks for paper in the feeder.
  442. * - Always check for paper in the feeder before attempting to scan.
  443. * If you are about to scan the FIRST page, and no paper is detected
  444. * return a WIA_ERROR_PAPER_EMPTY error code.
  445. * If you are scanning the SECOND + pages, and no paper is detected
  446. * return a WIA_ERROR_PAPER_EMPTY error code or WIA_STATUS_END_OF_MEDIA
  447. * success code.
  448. * 5. feed a page into the feeder.
  449. * - Only do this if your device requires the page to be prefed before
  450. * scanning. Some document feeders auto-feed a page while scanning.
  451. * if your document feeder does this...you can skip this step.
  452. * 6. check the feeder's status.
  453. * - make sure the feeder is in "GO" mode. Everything checks out, and you
  454. * are ready to scan. This will help catch paper jams, or other feeder
  455. * related problems that can occur before scanning.
  456. * 7. scan
  457. * 8. repeat steps 1 - 7 until all requested pages have been scanned, or
  458. * until the document feeder is out of paper.
  459. *
  460. *
  461. * Why is my ITEM SIZE set to ZERO (0)???
  462. *
  463. * This WIA sample driver sets the WIA item size to zero (0). This indicates to
  464. * the application that the WIA driver does not know the resulting image size.
  465. * This indicates to the WIA service, that the WIA driver wants to allocate it's
  466. * own data buffers.
  467. *
  468. * This WIA driver reads the WIA_IPA_BUFFER_SIZE property and allocates a chunk
  469. * for a single band of data. The WIA driver can allocate any amount of memory
  470. * it needs here, but it is recommended to keep allocation small.
  471. *
  472. * How do I know if the WIA service allocated memory for me??
  473. *
  474. * check the pmdtc->bClassDrvAllocBuf flag. If it is TRUE, then the WIA
  475. * service was kind enough to allocate memory for you. To find out how
  476. * much memory that was, check the pmdtc->lBufferSize member.
  477. *
  478. * If I allocate my own memory, how do I let the WIA service know?
  479. *
  480. * Allocate memory using CoTaskMemAlloc(), and use the pointer located in
  481. * pmdtc->pTransferBuffer. (REMEMBER THAT YOU ALLOCATED THIS..SO YOU FREE IT!!)
  482. * Set the pmdtc->lBufferSize to equal the size you allocated.
  483. * As stated above, this WIA sample driver allocates it's WIA_IPA_BUFFER_SIZE
  484. * and uses that memory.
  485. *
  486. * Read the comments located in the code below for more details on data
  487. * transfers.
  488. *
  489. * History:
  490. *
  491. * 03/05/2002 Original Version
  492. *
  493. \**************************************************************************/
  494. HRESULT _stdcall CWIADevice::drvAcquireItemData(
  495. BYTE *pWiasContext,
  496. LONG lFlags,
  497. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  498. LONG *plDevErrVal)
  499. {
  500. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  501. WIALOG_NO_RESOURCE_ID,
  502. WIALOG_LEVEL1,
  503. "CWIADevice::drvAcquireItemData");
  504. //
  505. // If the caller did not pass in the correct parameters, then fail the
  506. // call with E_INVALIDARG.
  507. //
  508. if (!pWiasContext) {
  509. return E_INVALIDARG;
  510. }
  511. if (!pmdtc) {
  512. return E_INVALIDARG;
  513. }
  514. if (!plDevErrVal) {
  515. return E_INVALIDARG;
  516. }
  517. *plDevErrVal = 0;
  518. HRESULT hr = E_FAIL;
  519. LONG lBytesTransferredToApplication = 0;
  520. //
  521. // Check if we are in Preview Mode and take any special actions required for performing that type
  522. // of scan.
  523. //
  524. if (IsPreviewScan(pWiasContext)) {
  525. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvAcquireItemData, Preview Property is SET"));
  526. } else {
  527. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvAcquireItemData, Preview Property is NOT SET"));
  528. }
  529. //
  530. // Get number of pages requested, for ADF scanning loop
  531. //
  532. // (1-n) = number of pages to scan, or util FEEDER is empty and can not fulfill the request
  533. // (0) = scan all pages until FEEDER is empty
  534. //
  535. // NOTE: The driver should return an error in two cases only:
  536. // 1. fails to scan the first page (with paper empty, or other error)
  537. // 2. fails duing an ADF scan, and the error is unrecoverable (data loss is involved.)
  538. //
  539. // In case #2, the driver should return a WIA_STATUS_END_OF_MEDIA code when the ADF runs
  540. // out of paper, before completing the (1-n) scans requested. This will allow the application
  541. // to properly handle the transfer. (no data loss was involved, just could not complete the full
  542. // request. Some pages did transfer, and the application is holding on to the images.)
  543. //
  544. //
  545. // assume that we are scanning 1 page, (from a feeder or a flatbed), and we are not
  546. // going to empty the ADF.
  547. //
  548. BOOL bEmptyTheADF = FALSE;
  549. LONG lPagesRequested = 1;
  550. LONG lPagesScanned = 0;
  551. //
  552. // only ask for page count, if the feeder has been enabled. If it has not, then assume
  553. // we are using the flatbed.
  554. //
  555. if (m_bADFEnabled) {
  556. lPagesRequested = GetPageCount(pWiasContext);
  557. if (lPagesRequested == 0) {
  558. bEmptyTheADF = TRUE;
  559. lPagesRequested = 1;// set to 1 so we can enter our loop
  560. // WIA_ERROR_PAPER_EMPTY will terminate
  561. // the loop...or an error, or a cancel..
  562. //
  563. }
  564. }
  565. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvAcquireItemData, Pages to Scan = %d",lPagesRequested));
  566. //
  567. // scan until requested page count = 0
  568. //
  569. //
  570. // This is the start of scanning a single page. The while loop will continue for all pages.
  571. //
  572. while (lPagesRequested > 0) {
  573. //
  574. // If the FEEDER is enabled, then we need to perform some feeder operations to get
  575. // the device started. Some operations, you may want to do here are:
  576. // check the feeder's status, check paper, feed a page, or even eject a jammed or
  577. // previous page.
  578. //
  579. if (m_bADFEnabled) {
  580. //
  581. // clear an potential paper that may be blocking the scan pathway.
  582. //
  583. hr = m_pScanAPI->FakeScanner_ADFUnFeedPage();
  584. if (FAILED(hr)) {
  585. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ADFUnFeedPage (begin transfer) Failed"));
  586. WIAS_LHRESULT(m_pIWiaLog, hr);
  587. return hr;
  588. }
  589. //
  590. // check feeder for paper
  591. //
  592. hr = m_pScanAPI->FakeScanner_ADFHasPaper();
  593. if (FAILED(hr)) {
  594. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ADFHasPaper Failed"));
  595. WIAS_LHRESULT(m_pIWiaLog, hr);
  596. return hr;
  597. } else if (hr == S_FALSE) {
  598. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ADF Reports Paper Empty"));
  599. if (lPagesScanned == 0) {
  600. return WIA_ERROR_PAPER_EMPTY;
  601. } else {
  602. return WIA_STATUS_END_OF_MEDIA;
  603. }
  604. }
  605. //
  606. // attempt to load a page (only if needed)
  607. //
  608. hr = m_pScanAPI->FakeScanner_ADFFeedPage();
  609. if (FAILED(hr)) {
  610. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ADFFeedPage Failed"));
  611. WIAS_LHRESULT(m_pIWiaLog, hr);
  612. return hr;
  613. }
  614. //
  615. // Check feeder's status
  616. //
  617. hr = m_pScanAPI->FakeScanner_ADFStatus();
  618. if (FAILED(hr)) {
  619. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ADFStatus Failed"));
  620. WIAS_LHRESULT(m_pIWiaLog, hr);
  621. return hr;
  622. }
  623. }
  624. LONG lScanPhase = SCAN_START;
  625. LONG lClassDrvAllocSize = 0;
  626. //
  627. // (1) Memory allocation
  628. //
  629. if (pmdtc->bClassDrvAllocBuf) {
  630. //
  631. // WIA allocated the buffer for data transfers
  632. //
  633. lClassDrvAllocSize = pmdtc->lBufferSize;
  634. hr = S_OK;
  635. } else {
  636. //
  637. // Driver allocated the buffer for data transfers
  638. //
  639. hr = wiasReadPropLong(pWiasContext, WIA_IPA_BUFFER_SIZE, &lClassDrvAllocSize,NULL,TRUE);
  640. if (FAILED(hr)) {
  641. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasReadPropLong Failed to read WIA_IPA_BUFFER_SIZE"));
  642. WIAS_LHRESULT(m_pIWiaLog, hr);
  643. return hr;
  644. }
  645. pmdtc->pTransferBuffer = (PBYTE) CoTaskMemAlloc(lClassDrvAllocSize);
  646. if (!pmdtc->pTransferBuffer) {
  647. return E_OUTOFMEMORY;
  648. }
  649. pmdtc->lBufferSize = lClassDrvAllocSize;
  650. }
  651. //
  652. // (2) Gather all information about data transfer settings and
  653. // calculate the total data amount to transfer
  654. //
  655. if (hr == S_OK) {
  656. //
  657. // WIA service will populate the MINIDRV_TRANSFER_CONTEXT by reading the WIA properties.
  658. //
  659. // The following values will be written as a result of the wiasGetImageInformation() call
  660. //
  661. // pmdtc->lWidthInPixels
  662. // pmdtc->lLines
  663. // pmdtc->lDepth
  664. // pmdtc->lXRes
  665. // pmdtc->lYRes
  666. // pmdtc->lCompression
  667. // pmdtc->lItemSize
  668. // pmdtc->guidFormatID
  669. // pmdtc->tymed
  670. //
  671. // if the FORMAT is set to BMP or MEMORYBMP, the the following values
  672. // will also be set automatically
  673. //
  674. // pmdtc->cbWidthInBytes
  675. // pmdtc->lImageSize
  676. // pmdtc->lHeaderSize
  677. // pmdtc->lItemSize (will be updated using the known image format information)
  678. //
  679. hr = wiasGetImageInformation(pWiasContext,0,pmdtc);
  680. if (hr == S_OK) {
  681. //
  682. // (4) Send the image data to the application
  683. //
  684. LONG lDepth = 0;
  685. hr = wiasReadPropLong(pWiasContext, WIA_IPA_DEPTH, &lDepth,NULL,TRUE);
  686. if (FAILED(hr)) {
  687. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasReadPropLong Failed to read WIA_IPA_DEPTH"));
  688. WIAS_LHRESULT(m_pIWiaLog, hr);
  689. return hr;
  690. }
  691. LONG lPixelsPerLine = 0;
  692. hr = wiasReadPropLong(pWiasContext, WIA_IPA_PIXELS_PER_LINE, &lPixelsPerLine,NULL,TRUE);
  693. if (FAILED(hr)) {
  694. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasReadPropLong Failed to read WIA_IPA_PIXELS_PER_LINE"));
  695. WIAS_LHRESULT(m_pIWiaLog, hr);
  696. return hr;
  697. }
  698. LONG lBytesPerLineRaw = ((lPixelsPerLine * lDepth) + 7) / 8;
  699. LONG lBytesPerLineAligned = (lPixelsPerLine * lDepth) + 31;
  700. lBytesPerLineAligned = (lBytesPerLineAligned / 8) & 0xfffffffc;
  701. LONG lTotalImageBytes = pmdtc->lImageSize + pmdtc->lHeaderSize;
  702. LONG lBytesReceived = pmdtc->lHeaderSize;
  703. lBytesTransferredToApplication = 0;
  704. pmdtc->cbOffset = 0;
  705. while ((lBytesReceived)) {
  706. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  707. //
  708. // since the feeder can return random length pages, it is a good idea to pick a common
  709. // size, and base that as the common transfer lenght. This will allow you to show
  710. // a relativly decent progress indicator percent complete value.
  711. // Note: If you ever get a percent complete over 100%, it is a good idea to stop the
  712. // increment, and hold around 95....or close to 100. This will keep appliations
  713. // from displaying a strange 105%.. or 365% complete to the end user. Remember that
  714. // the application will display the exact percent complete value you return to them.
  715. // This calculation has to be accurate, or close to accurate.
  716. //
  717. lTotalImageBytes = lBytesPerLineRaw * (AVERAGE_FAKE_PAGE_HEIGHT_INCHES * pmdtc->lYRes);
  718. LONG lPercentComplete = (LONG)(((float)lBytesTransferredToApplication/(float)lTotalImageBytes) * 100.0f);
  719. //
  720. // lock percent complete at 95%, until the scan is complete..
  721. //
  722. if (lPercentComplete >= 95) {
  723. lPercentComplete = 95;
  724. }
  725. #else
  726. LONG lPercentComplete = (LONG)(((float)lBytesTransferredToApplication/(float)lTotalImageBytes) * 100.0f);
  727. #endif
  728. switch (pmdtc->tymed) {
  729. case TYMED_MULTIPAGE_CALLBACK:
  730. case TYMED_CALLBACK:
  731. {
  732. hr = pmdtc->pIWiaMiniDrvCallBack->MiniDrvCallback(IT_MSG_DATA,IT_STATUS_TRANSFER_TO_CLIENT,
  733. lPercentComplete,pmdtc->cbOffset,lBytesReceived,pmdtc,0);
  734. pmdtc->cbOffset += lBytesReceived;
  735. lBytesTransferredToApplication += lBytesReceived;
  736. }
  737. break;
  738. case TYMED_MULTIPAGE_FILE:
  739. case TYMED_FILE:
  740. {
  741. pmdtc->lItemSize = lBytesReceived;
  742. hr = wiasWriteBufToFile(0,pmdtc);
  743. if (FAILED(hr)) {
  744. break;
  745. }
  746. hr = pmdtc->pIWiaMiniDrvCallBack->MiniDrvCallback(IT_MSG_STATUS,IT_STATUS_TRANSFER_TO_CLIENT,
  747. lPercentComplete,0,0,NULL,0);
  748. lBytesTransferredToApplication += lBytesReceived;
  749. }
  750. break;
  751. default:
  752. {
  753. hr = E_FAIL;
  754. }
  755. break;
  756. }
  757. //
  758. // scan from device, requesting lBytesToReadFromDevice
  759. //
  760. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  761. //
  762. // request buffer size, until the scanner can not return any more data
  763. //
  764. LONG lBytesRemainingToTransfer = pmdtc->lBufferSize;
  765. #else
  766. LONG lBytesRemainingToTransfer = (lTotalImageBytes - lBytesTransferredToApplication);
  767. if (lBytesRemainingToTransfer <= 0) {
  768. break;
  769. }
  770. #endif
  771. //
  772. // calculate number of bytes to request from device
  773. //
  774. LONG lBytesToReadFromDevice = (lBytesRemainingToTransfer > pmdtc->lBufferSize) ? pmdtc->lBufferSize : lBytesRemainingToTransfer;
  775. // RAW data request
  776. lBytesToReadFromDevice = (lBytesToReadFromDevice / lBytesPerLineAligned) * lBytesPerLineRaw;
  777. // Aligned data request
  778. // lBytesToReadFromDevice = (lBytesToReadFromDevice / lBytesPerLineAligned) * lBytesPerLineAligned;
  779. if ((hr == S_FALSE)||FAILED(hr)) {
  780. //
  781. // user canceled the scan, or the callback failed for some reason
  782. //
  783. lPagesRequested = 0; // set pages to 0 to cleanly exit loop
  784. break;
  785. }
  786. //
  787. // request byte amount from device
  788. //
  789. hr = m_pScanAPI->FakeScanner_Scan(lScanPhase, pmdtc->pTransferBuffer, lBytesToReadFromDevice, (DWORD*)&lBytesReceived);
  790. if (FAILED(hr)) {
  791. break;
  792. }
  793. //
  794. // This scanner, when scanning in 24-bit color mode provides RAW data with the RED and BLUE channels
  795. // swapped. If your scanner does this too, then you should call the SwapBuffer24 helper function.
  796. //
  797. if (pmdtc->lDepth == 24) {
  798. //
  799. // we are scanning color, so we need to swap the RED and BLUE values becuase our scanner
  800. // scans RAW like this.
  801. //
  802. SwapBuffer24(pmdtc->pTransferBuffer,lBytesReceived);
  803. }
  804. //
  805. // this scanner returns Raw data. If your scanner does this too, then you should call the AlignInPlace
  806. // helper function to align the data.
  807. //
  808. lBytesReceived = AlignInPlace(pmdtc->pTransferBuffer,lBytesReceived,lBytesPerLineAligned,lBytesPerLineRaw);
  809. //
  810. // advance to the next scanning stage for the device
  811. //
  812. if (lScanPhase == SCAN_START) {
  813. lScanPhase = SCAN_CONTINUE;
  814. }
  815. } // while ((lBytesReceived))
  816. }
  817. }
  818. //
  819. // force scanner to return scan head, and close device from scanning session
  820. //
  821. HRESULT Temphr = m_pScanAPI->FakeScanner_Scan(SCAN_END, NULL, 0, NULL);
  822. if (FAILED(Temphr)) {
  823. //
  824. // scanner failed to park scanner head in start position
  825. //
  826. }
  827. //
  828. // free any allocated memory for buffers
  829. //
  830. if (!pmdtc->bClassDrvAllocBuf) {
  831. CoTaskMemFree(pmdtc->pTransferBuffer);
  832. pmdtc->pTransferBuffer = NULL;
  833. pmdtc->lBufferSize = 0;
  834. }
  835. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  836. //
  837. // because we are scanning with a feeder that can not determine the page height, it is necessary
  838. // for the driver to update the final file created. Since this device scans only BMP files, it
  839. // is easy to locate the BITMAPINFOHEADER, and BITMAPFILEHEADER and update the final values.
  840. // Values that should be updated for BMP files:
  841. //
  842. // BITMAPFILEINFO - bfSize = final file size
  843. // BITMAPINFOHEADER - biHeight = final image height in pixels
  844. // BITMAPINFOHEADER - biSizeImage = final image size
  845. //
  846. if ((pmdtc->tymed == TYMED_FILE)&&(pmdtc->guidFormatID == WiaImgFmt_BMP)) {
  847. BYTE BMPHeaderData[sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)];
  848. memset(BMPHeaderData,0,sizeof(BMPHeaderData));
  849. //
  850. // read BMP header, already written to the file
  851. //
  852. if (SetFilePointer((HANDLE)((LONG_PTR)pmdtc->hFile),0,NULL,FILE_BEGIN) != INVALID_SET_FILE_POINTER) {
  853. DWORD dwBytesReadFromFile = 0;
  854. if (ReadFile((HANDLE)((LONG_PTR)pmdtc->hFile),(BYTE*)BMPHeaderData,sizeof(BMPHeaderData),&dwBytesReadFromFile,NULL)) {
  855. //
  856. // validate that the read was successful, by comparing sizes
  857. //
  858. if ((LONG)dwBytesReadFromFile != sizeof(BMPHeaderData)) {
  859. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Header was not read from the file correctly"));
  860. }
  861. //
  862. // adjust BMP HEADER values
  863. //
  864. BITMAPINFOHEADER UNALIGNED *pBMPInfoHeader = (BITMAPINFOHEADER*)(&BMPHeaderData[0] + sizeof(BITMAPFILEHEADER));
  865. BITMAPFILEHEADER UNALIGNED *pBMPFileHeader = (BITMAPFILEHEADER*)BMPHeaderData;
  866. LONG lDepth = 0;
  867. hr = wiasReadPropLong(pWiasContext, WIA_IPA_DEPTH, &lDepth,NULL,TRUE);
  868. if (S_OK == hr) {
  869. LONG lPixelsPerLine = 0;
  870. hr = wiasReadPropLong(pWiasContext, WIA_IPA_PIXELS_PER_LINE, &lPixelsPerLine,NULL,TRUE);
  871. if (S_OK == hr) {
  872. LONG lBytesPerLineRaw = ((lPixelsPerLine * lDepth) + 7) / 8;
  873. LONG lBytesPerLineAligned = (lPixelsPerLine * lDepth) + 31;
  874. lBytesPerLineAligned = (lBytesPerLineAligned / 8) & 0xfffffffc;
  875. pBMPInfoHeader->biHeight = (lBytesTransferredToApplication / lBytesPerLineAligned);
  876. pBMPInfoHeader->biSizeImage = (pBMPInfoHeader->biHeight * lBytesPerLineAligned);
  877. pBMPFileHeader->bfSize = pBMPInfoHeader->biSizeImage + pBMPFileHeader->bfOffBits;
  878. //
  879. // write BMP header, back to the file
  880. //
  881. if (SetFilePointer((HANDLE)((LONG_PTR)pmdtc->hFile),0,NULL,FILE_BEGIN) != INVALID_SET_FILE_POINTER) {
  882. DWORD dwBytesWrittenToFile = 0;
  883. WriteFile((HANDLE)((LONG_PTR)pmdtc->hFile),(BYTE*)BMPHeaderData,sizeof(BMPHeaderData),&dwBytesWrittenToFile,NULL);
  884. //
  885. // validate that the write was successful, by comparing sizes
  886. //
  887. if ((LONG)dwBytesWrittenToFile != sizeof(BMPHeaderData)) {
  888. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ScanItem, Header was not written to file correctly"));
  889. }
  890. } else {
  891. //
  892. // could not set file pointer to beginning of file
  893. //
  894. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, SetFilePointer Failed to set file pointer to the beginning of the file"));
  895. hr = E_FAIL;
  896. }
  897. } else {
  898. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasReadPropLong Failed to read WIA_IPA_PIXELS_PER_LINE"));
  899. WIAS_LHRESULT(m_pIWiaLog, hr);
  900. }
  901. } else {
  902. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasReadPropLong Failed to read WIA_IPA_DEPTH"));
  903. WIAS_LHRESULT(m_pIWiaLog, hr);
  904. }
  905. } else {
  906. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, ReadFile Failed to read data file"));
  907. hr = E_FAIL;
  908. }
  909. } else {
  910. //
  911. // could not set file pointer to beginning of file
  912. //
  913. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, SetFilePointer Failed to set file pointer to the beginning of the file"));
  914. hr = E_FAIL;
  915. }
  916. }
  917. #endif
  918. //
  919. // if the scan is going well, we should decrement the pages requested counter
  920. //
  921. if (S_OK == hr) {
  922. //
  923. // decrease the pages requested counter
  924. //
  925. lPagesRequested--;
  926. //
  927. // if we were asked to scan all pages in the document feeder, then
  928. // keep the pages request counter above 0 to stay in the loop
  929. //
  930. if (bEmptyTheADF) {
  931. lPagesRequested = 1;
  932. }
  933. //
  934. // only send ENDOFPAGE messages when the driver is set to a CALLBACK mode
  935. //
  936. if ((pmdtc->tymed == TYMED_CALLBACK)||(pmdtc->tymed == TYMED_MULTIPAGE_CALLBACK)) {
  937. //
  938. // send the NEW_PAGE message, when scanning multiple pages
  939. // in callback mode. This will let the calling application
  940. // know when an end-of-page has been hit.
  941. //
  942. hr = wiasSendEndOfPage(pWiasContext, lPagesScanned, pmdtc);
  943. if (FAILED(hr)) {
  944. lPagesRequested = 0;
  945. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvAcquireItemData, wiasSendEndOfPage Failed"));
  946. WIAS_LHRESULT(m_pIWiaLog, hr);
  947. }
  948. }
  949. //
  950. // incremement number of pages scanned
  951. //
  952. lPagesScanned++;
  953. }
  954. } // while (lPagesRequested > 0)
  955. return hr;
  956. }
  957. /**************************************************************************\
  958. * CWIADevice::drvInitItemProperties
  959. *
  960. * drvInitItemProperties is called to initialize the WIA properties for
  961. * the requested item. To find out what item is being initialized, use the
  962. * pWiasContext pointer to identify it.
  963. *
  964. * This method is called for every item in the tree that is accessed by
  965. * an application. If an application attempts to read a WIA property on an
  966. * item for the first time, the WIA service will ask the WIA driver to
  967. * initialize the WIA property set for that item. Once the WIA property
  968. * set has been initialized, any other reads/writes on that WIA item will
  969. * not produce a drvInitItemProperties call.
  970. *
  971. * After a drvInitItemProperties method call, the WIA item is marked as
  972. * initialized and is ready for use. (This is on a per-application connection
  973. * basis.)
  974. *
  975. * Arguments:
  976. *
  977. * pWiasContext - Pointer to WIA context (item information).
  978. * lFlags - Operation flags, unused.
  979. * plDevErrVal - Pointer to the device error value.
  980. *
  981. *
  982. * Return Value:
  983. *
  984. * S_OK - if the operation was successful
  985. * E_xxx - Error code if the operation failed
  986. *
  987. * Sample Notes:
  988. * This WIA driver sample calls the internal helper functions
  989. * BuildRootItemProperties(), and BuildChildItemProperties() to assist in the
  990. * construction of the WIA item property sets.
  991. *
  992. * History:
  993. *
  994. * 03/05/2002 Original Version
  995. *
  996. \**************************************************************************/
  997. HRESULT _stdcall CWIADevice::drvInitItemProperties(BYTE *pWiasContext,LONG lFlags,LONG *plDevErrVal)
  998. {
  999. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1000. WIALOG_NO_RESOURCE_ID,
  1001. WIALOG_LEVEL1,
  1002. "CWIADevice::drvInitItemProperties");
  1003. //
  1004. // If the caller did not pass in the correct parameters, then fail the
  1005. // call with E_INVALIDARG.
  1006. //
  1007. if (!pWiasContext) {
  1008. return E_INVALIDARG;
  1009. }
  1010. if (!plDevErrVal) {
  1011. return E_INVALIDARG;
  1012. }
  1013. HRESULT hr = S_OK;
  1014. //
  1015. // This device doesn't touch hardware to initialize the device item
  1016. // properties, so set plDevErrVal to 0.
  1017. //
  1018. *plDevErrVal = 0;
  1019. //
  1020. // Get a pointer to the associated driver item.
  1021. //
  1022. IWiaDrvItem* pDrvItem;
  1023. hr = wiasGetDrvItem(pWiasContext, &pDrvItem);
  1024. if (FAILED(hr)) {
  1025. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasGetDrvItem failed"));
  1026. WIAS_LHRESULT(m_pIWiaLog, hr);
  1027. return hr;
  1028. }
  1029. //
  1030. // Set initial item properties.
  1031. //
  1032. LONG lItemType = 0;
  1033. pDrvItem->GetItemFlags(&lItemType);
  1034. if (lItemType & WiaItemTypeRoot) {
  1035. //
  1036. // This is for the root item.
  1037. //
  1038. //
  1039. // Build Root Item Properties, initializing global
  1040. // structures with their default and valid values
  1041. //
  1042. hr = BuildRootItemProperties();
  1043. if (FAILED(hr)) {
  1044. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, BuildRootItemProperties failed"));
  1045. WIAS_LHRESULT(m_pIWiaLog, hr);
  1046. DeleteRootItemProperties();
  1047. return hr;
  1048. }
  1049. //
  1050. // Add the device specific root item property names,
  1051. // using WIA service.
  1052. //
  1053. hr = wiasSetItemPropNames(pWiasContext,
  1054. m_RootItemInitInfo.lNumProps,
  1055. m_RootItemInitInfo.piPropIDs,
  1056. m_RootItemInitInfo.pszPropNames);
  1057. if (FAILED(hr)) {
  1058. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasSetItemPropNames failed"));
  1059. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_NumRootItemPropeties = %d",m_RootItemInitInfo.lNumProps));
  1060. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_RootItemInitInfo.piPropIDs = %x",m_RootItemInitInfo.piPropIDs));
  1061. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_RootItemInitInfo.pszPropNames = %x",m_RootItemInitInfo.pszPropNames));
  1062. WIAS_LHRESULT(m_pIWiaLog, hr);
  1063. DeleteRootItemProperties();
  1064. return hr;
  1065. }
  1066. //
  1067. // Set the device specific root item properties to
  1068. // their default values using WIA service.
  1069. //
  1070. hr = wiasWriteMultiple(pWiasContext,
  1071. m_RootItemInitInfo.lNumProps,
  1072. m_RootItemInitInfo.psPropSpec,
  1073. m_RootItemInitInfo.pvPropVars);
  1074. //
  1075. // Free PROPVARIANT array, This frees any memory that was allocated for a prop variant value.
  1076. //
  1077. // FreePropVariantArray(m_RootItemInitInfo.lNumProps,m_RootItemInitInfo.pvPropVars);
  1078. if (FAILED(hr)) {
  1079. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasWriteMultiple failed"));
  1080. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_NumRootItemPropeties = %d",m_RootItemInitInfo.lNumProps));
  1081. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_RootItemInitInfo.pszPropNames = %x",m_RootItemInitInfo.pszPropNames));
  1082. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_RootItemInitInfo.pvPropVars = %x",m_RootItemInitInfo.pvPropVars));
  1083. WIAS_LHRESULT(m_pIWiaLog, hr);
  1084. DeleteRootItemProperties();
  1085. return hr;
  1086. }
  1087. //
  1088. // Use WIA services to set the property access and
  1089. // valid value information from m_wpiItemDefaults.
  1090. //
  1091. hr = wiasSetItemPropAttribs(pWiasContext,
  1092. m_RootItemInitInfo.lNumProps,
  1093. m_RootItemInitInfo.psPropSpec,
  1094. m_RootItemInitInfo.pwpiPropInfo);
  1095. if (FAILED(hr)) {
  1096. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasSetItemPropAttribs failed"));
  1097. WIAS_LHRESULT(m_pIWiaLog, hr);
  1098. }
  1099. //
  1100. // free allocated property arrays, for more memory
  1101. //
  1102. DeleteRootItemProperties();
  1103. } else {
  1104. //
  1105. // This is for the child item.(Top)
  1106. //
  1107. //
  1108. // Build Top Item Properties, initializing global
  1109. // structures with their default and valid values
  1110. //
  1111. hr = BuildChildItemProperties();
  1112. if (FAILED(hr)) {
  1113. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, BuildChildItemProperties failed"));
  1114. WIAS_LHRESULT(m_pIWiaLog, hr);
  1115. DeleteChildItemProperties();
  1116. return hr;
  1117. }
  1118. //
  1119. // Use the WIA service to set the item property names.
  1120. //
  1121. hr = wiasSetItemPropNames(pWiasContext,
  1122. m_ChildItemInitInfo.lNumProps,
  1123. m_ChildItemInitInfo.piPropIDs,
  1124. m_ChildItemInitInfo.pszPropNames);
  1125. if (FAILED(hr)) {
  1126. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasSetItemPropNames failed"));
  1127. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_NumItemPropeties = %d",m_ChildItemInitInfo.lNumProps));
  1128. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.piPropIDs = %x",m_ChildItemInitInfo.piPropIDs));
  1129. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.pszPropNames = %x",m_ChildItemInitInfo.pszPropNames));
  1130. WIAS_LHRESULT(m_pIWiaLog, hr);
  1131. DeleteChildItemProperties();
  1132. return hr;
  1133. }
  1134. //
  1135. // Use WIA services to set the item properties to their default
  1136. // values.
  1137. //
  1138. hr = wiasWriteMultiple(pWiasContext,
  1139. m_ChildItemInitInfo.lNumProps,
  1140. m_ChildItemInitInfo.psPropSpec,
  1141. m_ChildItemInitInfo.pvPropVars);
  1142. if (FAILED(hr)) {
  1143. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasWriteMultiple failed"));
  1144. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_NumItemPropeties = %d",m_ChildItemInitInfo.lNumProps));
  1145. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.pszPropNames = %x",m_ChildItemInitInfo.pszPropNames));
  1146. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.pvPropVars = %x",m_ChildItemInitInfo.pvPropVars));
  1147. WIAS_LHRESULT(m_pIWiaLog, hr);
  1148. DeleteChildItemProperties();
  1149. return hr;
  1150. }
  1151. //
  1152. // Use WIA services to set the property access and
  1153. // valid value information from m_wpiItemDefaults.
  1154. //
  1155. hr = wiasSetItemPropAttribs(pWiasContext,
  1156. m_ChildItemInitInfo.lNumProps,
  1157. m_ChildItemInitInfo.psPropSpec,
  1158. m_ChildItemInitInfo.pwpiPropInfo);
  1159. if (FAILED(hr)) {
  1160. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, wiasSetItemPropAttribs failed"));
  1161. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_NumItemPropeties = %d",m_ChildItemInitInfo.lNumProps));
  1162. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.psPropSpec = %x",m_ChildItemInitInfo.psPropSpec));
  1163. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvInitItemProperties, m_ChildItemInitInfo.pwpiPropInfo = %x",m_ChildItemInitInfo.pwpiPropInfo));
  1164. WIAS_LHRESULT(m_pIWiaLog, hr);
  1165. DeleteChildItemProperties();
  1166. return hr;
  1167. }
  1168. //
  1169. // Set item size properties.
  1170. //
  1171. hr = SetItemSize(pWiasContext);
  1172. if (FAILED(hr)) {
  1173. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvInitItemProperties, SetItemSize failed"));
  1174. WIAS_LHRESULT(m_pIWiaLog, hr);
  1175. }
  1176. //
  1177. // free allocated property arrays, for more memory
  1178. //
  1179. DeleteChildItemProperties();
  1180. }
  1181. return hr;
  1182. }
  1183. /**************************************************************************\
  1184. * CWIADevice::drvValidateItemProperties
  1185. *
  1186. * drvValidateItemProperties is called when changes are made
  1187. * to an item's WIA properties. The WIA driver should not only check that
  1188. * the values are valid, but must update any valid values that may change
  1189. * as a result.
  1190. *
  1191. * If an a WIA property is not being written by the application, and it's value
  1192. * is invalid, then "fold" it to a new value, else fail validation (because
  1193. * the application is setting the property to an invalid value).
  1194. *
  1195. * Arguments:
  1196. *
  1197. * pWiasContext - Pointer to the WIA item, unused.
  1198. * lFlags - Operation flags, unused.
  1199. * nPropSpec - The number of properties that are being written
  1200. * pPropSpec - An array of PropSpecs identifying the properties that
  1201. * are being written.
  1202. * plDevErrVal - Pointer to the device error value.
  1203. *
  1204. * Return Value:
  1205. *
  1206. * S_OK - if the operation was successful
  1207. * E_xxx - if the operation failed.
  1208. *
  1209. * History:
  1210. *
  1211. * 03/05/2002 Original Version
  1212. ***************************************************************************/
  1213. HRESULT _stdcall CWIADevice::drvValidateItemProperties(
  1214. BYTE *pWiasContext,
  1215. LONG lFlags,
  1216. ULONG nPropSpec,
  1217. const PROPSPEC *pPropSpec,
  1218. LONG *plDevErrVal)
  1219. {
  1220. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1221. WIALOG_NO_RESOURCE_ID,
  1222. WIALOG_LEVEL1,
  1223. "CWIADevice::drvValidateItemProperties");
  1224. //
  1225. // If the caller did not pass in the correct parameters, then fail the
  1226. // call with E_INVALIDARG.
  1227. //
  1228. if (!pWiasContext) {
  1229. return E_INVALIDARG;
  1230. }
  1231. if (!plDevErrVal) {
  1232. return E_INVALIDARG;
  1233. }
  1234. if (!pPropSpec) {
  1235. return E_INVALIDARG;
  1236. }
  1237. HRESULT hr = S_OK;
  1238. LONG lItemType = 0;
  1239. WIA_PROPERTY_CONTEXT Context;
  1240. *plDevErrVal = 0;
  1241. hr = wiasGetItemType(pWiasContext, &lItemType);
  1242. if (SUCCEEDED(hr)) {
  1243. if (lItemType & WiaItemTypeRoot) {
  1244. //
  1245. // Validate root item
  1246. //
  1247. hr = wiasCreatePropContext(nPropSpec,
  1248. (PROPSPEC*)pPropSpec,
  1249. 0,
  1250. NULL,
  1251. &Context);
  1252. if (SUCCEEDED(hr)) {
  1253. //
  1254. // Check ADF to see if the status settings need to be updated
  1255. // Also switch between FEEDER/FLATBED modes
  1256. //
  1257. hr = CheckADFStatus(pWiasContext, &Context);
  1258. if (FAILED(hr)) {
  1259. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, CheckADFStatus failed"));
  1260. WIAS_LHRESULT(m_pIWiaLog, hr);
  1261. }
  1262. //
  1263. // check Preview Property only if validation is successful so far....
  1264. //
  1265. if (SUCCEEDED(hr)) {
  1266. //
  1267. // Check Preview property to see if the settings are valid
  1268. //
  1269. hr = CheckPreview(pWiasContext, &Context);
  1270. if (SUCCEEDED(hr)) {
  1271. //
  1272. // call WIA service helper to validate other properties
  1273. //
  1274. hr = wiasValidateItemProperties(pWiasContext, nPropSpec, pPropSpec);
  1275. if (FAILED(hr)) {
  1276. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasValidateItemProperties failed."));
  1277. WIAS_LHRESULT(m_pIWiaLog, hr);
  1278. }
  1279. } else {
  1280. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, CheckPreview failed"));
  1281. WIAS_LHRESULT(m_pIWiaLog, hr);
  1282. }
  1283. }
  1284. } else {
  1285. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasCreatePropContext failed (Root Item)"));
  1286. WIAS_LHRESULT(m_pIWiaLog, hr);
  1287. }
  1288. } else {
  1289. //
  1290. // validate item properties here
  1291. //
  1292. //
  1293. // Create a property context needed by some WIA Service
  1294. // functions used below.
  1295. //
  1296. hr = wiasCreatePropContext(nPropSpec,
  1297. (PROPSPEC*)pPropSpec,
  1298. 0,
  1299. NULL,
  1300. &Context);
  1301. if (SUCCEEDED(hr)) {
  1302. //
  1303. // Check Current Intent first
  1304. //
  1305. hr = CheckIntent(pWiasContext, &Context);
  1306. if (SUCCEEDED(hr)) {
  1307. //
  1308. // Check if DataType is being written
  1309. //
  1310. hr = CheckDataType(pWiasContext, &Context);
  1311. if (SUCCEEDED(hr)) {
  1312. //
  1313. // Use the WIA service to update the scan rect
  1314. // properties and valid values.
  1315. //
  1316. LONG lBedWidth = 0;
  1317. LONG lBedHeight = 0;
  1318. hr = m_pScanAPI->FakeScanner_GetBedWidthAndHeight(&lBedWidth,&lBedHeight);
  1319. if (FAILED(hr)) {
  1320. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, FakeScanner_GetBedWidthAndHeight failed"));
  1321. WIAS_LHRESULT(m_pIWiaLog, hr);
  1322. return hr;
  1323. }
  1324. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  1325. //
  1326. // the unknown length feeder only scanner, formally called the scrollfed scanner
  1327. // has a fixed width, and only scans full pages.
  1328. //
  1329. lBedHeight = 0;
  1330. hr = CheckXExtent(pWiasContext,&Context,lBedWidth);
  1331. #else
  1332. hr = wiasUpdateScanRect(pWiasContext,&Context,lBedWidth,lBedHeight);
  1333. #endif
  1334. if (SUCCEEDED(hr)) {
  1335. //
  1336. // Use the WIA Service to update the valid values
  1337. // for Format. These are based on the value of
  1338. // WIA_IPA_TYMED, so validation is also performed
  1339. // on the tymed property by the service.
  1340. //
  1341. hr = wiasUpdateValidFormat(pWiasContext,
  1342. &Context,
  1343. (IWiaMiniDrv*) this);
  1344. if (SUCCEEDED(hr)) {
  1345. //
  1346. // Check Preferred format
  1347. //
  1348. hr = CheckPreferredFormat(pWiasContext, &Context);
  1349. if (FAILED(hr)) {
  1350. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, CheckPreferredFormat failed"));
  1351. WIAS_LHRESULT(m_pIWiaLog, hr);
  1352. }
  1353. } else {
  1354. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasUpdateValidFormat failed"));
  1355. WIAS_LHRESULT(m_pIWiaLog, hr);
  1356. }
  1357. } else {
  1358. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasUpdateScanRect failed"));
  1359. WIAS_LHRESULT(m_pIWiaLog, hr);
  1360. }
  1361. } else {
  1362. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, CheckDataType failed"));
  1363. WIAS_LHRESULT(m_pIWiaLog, hr);
  1364. }
  1365. } else {
  1366. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, CheckIntent failed"));
  1367. WIAS_LHRESULT(m_pIWiaLog, hr);
  1368. }
  1369. wiasFreePropContext(&Context);
  1370. } else {
  1371. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasCreatePropContext failed (Child Item)"));
  1372. WIAS_LHRESULT(m_pIWiaLog, hr);
  1373. }
  1374. //
  1375. // Update the item size
  1376. //
  1377. if (SUCCEEDED(hr)) {
  1378. hr = SetItemSize(pWiasContext);
  1379. if (FAILED(hr)) {
  1380. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, SetItemSize failed"));
  1381. WIAS_LHRESULT(m_pIWiaLog, hr);
  1382. }
  1383. }
  1384. //
  1385. // call WIA service helper to validate other properties
  1386. //
  1387. if (SUCCEEDED(hr)) {
  1388. //
  1389. // check image format property, and validate our pages valid values
  1390. //
  1391. hr = UpdateValidPages(pWiasContext,&Context);
  1392. if (SUCCEEDED(hr)) {
  1393. hr = wiasValidateItemProperties(pWiasContext, nPropSpec, pPropSpec);
  1394. if (FAILED(hr)) {
  1395. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasValidateItemProperties failed."));
  1396. WIAS_LHRESULT(m_pIWiaLog, hr);
  1397. }
  1398. } else {
  1399. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, UpdateValidPages failed"));
  1400. WIAS_LHRESULT(m_pIWiaLog, hr);
  1401. }
  1402. }
  1403. }
  1404. } else {
  1405. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvValidateItemProperties, wiasGetItemType failed"));
  1406. WIAS_LHRESULT(m_pIWiaLog, hr);
  1407. }
  1408. //
  1409. // log HRESULT sent back to caller
  1410. //
  1411. if (FAILED(hr)) {
  1412. WIAS_LHRESULT(m_pIWiaLog, hr);
  1413. }
  1414. return hr;
  1415. }
  1416. /**************************************************************************\
  1417. * CWIADevice::drvWriteItemProperties
  1418. *
  1419. * drvWriteItemProperties is called by the WIA Service prior to
  1420. * drvAcquireItemData when the client requests a data transfer. The WIA
  1421. * should commit any settings it needs to the hardware before returning
  1422. * from this method.
  1423. *
  1424. * When this method is called, the WIA driver has been commited to
  1425. * performing a data transfer. Any application that attempts to acquire
  1426. * data at this time, will be failed by the WIA service with a
  1427. * WIA_ERROR_BUSY.
  1428. *
  1429. * Arguments:
  1430. *
  1431. * pWiasContext - Pointer to WIA item.
  1432. * lFlags - Operation flags, unused.
  1433. * pmdtc - Pointer to mini driver context. On entry, only the
  1434. * portion of the mini driver context which is derived
  1435. * from the item properties is filled in.
  1436. * plDevErrVal - Pointer to the device error value.
  1437. *
  1438. * Return Value:
  1439. *
  1440. * S_OK - if the operation was successful
  1441. * E_xxx - if the operation failed
  1442. *
  1443. * History:
  1444. *
  1445. * 03/05/2002 Original Version
  1446. *
  1447. \**************************************************************************/
  1448. HRESULT _stdcall CWIADevice::drvWriteItemProperties(
  1449. BYTE *pWiasContext,
  1450. LONG lFlags,
  1451. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  1452. LONG *plDevErrVal)
  1453. {
  1454. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1455. WIALOG_NO_RESOURCE_ID,
  1456. WIALOG_LEVEL1,
  1457. "CWIADevice::drvWriteItemProperties");
  1458. //
  1459. // If the caller did not pass in the correct parameters, then fail the
  1460. // call with E_INVALIDARG.
  1461. //
  1462. if (!pWiasContext) {
  1463. return E_INVALIDARG;
  1464. }
  1465. if (!plDevErrVal) {
  1466. return E_INVALIDARG;
  1467. }
  1468. HRESULT hr = S_OK;
  1469. *plDevErrVal = 0;
  1470. LONG lNumProperties = 9;
  1471. PROPVARIANT pv[9];
  1472. PROPSPEC ps[9] = {
  1473. {PRSPEC_PROPID, WIA_IPS_XRES},
  1474. {PRSPEC_PROPID, WIA_IPS_YRES},
  1475. {PRSPEC_PROPID, WIA_IPS_XPOS},
  1476. {PRSPEC_PROPID, WIA_IPS_YPOS},
  1477. {PRSPEC_PROPID, WIA_IPS_XEXTENT},
  1478. {PRSPEC_PROPID, WIA_IPS_YEXTENT},
  1479. {PRSPEC_PROPID, WIA_IPA_DATATYPE},
  1480. {PRSPEC_PROPID, WIA_IPS_BRIGHTNESS},
  1481. {PRSPEC_PROPID, WIA_IPS_CONTRAST}
  1482. };
  1483. //
  1484. // initialize propvariant structures
  1485. //
  1486. for (int i = 0; i< lNumProperties;i++) {
  1487. pv[i].vt = VT_I4;
  1488. }
  1489. //
  1490. // read child item properties
  1491. //
  1492. hr = wiasReadMultiple(pWiasContext, lNumProperties, ps, pv, NULL);
  1493. if (hr == S_OK) {
  1494. hr = m_pScanAPI->FakeScanner_SetXYResolution(pv[0].lVal,pv[1].lVal);
  1495. if (FAILED(hr)) {
  1496. WIAS_LERROR(m_pIWiaLog,
  1497. WIALOG_NO_RESOURCE_ID,
  1498. ("ScanItem, Setting x any y resolutions failed"));
  1499. WIAS_LHRESULT(m_pIWiaLog, hr);
  1500. return hr;
  1501. }
  1502. hr = m_pScanAPI->FakeScanner_SetDataType(pv[6].lVal);
  1503. if (FAILED(hr)) {
  1504. WIAS_LERROR(m_pIWiaLog,
  1505. WIALOG_NO_RESOURCE_ID,
  1506. ("ScanItem, Setting data type failed"));
  1507. WIAS_LHRESULT(m_pIWiaLog, hr);
  1508. return hr;
  1509. }
  1510. hr = m_pScanAPI->FakeScanner_SetIntensity(pv[7].lVal);
  1511. if (FAILED(hr)) {
  1512. WIAS_LERROR(m_pIWiaLog,
  1513. WIALOG_NO_RESOURCE_ID,
  1514. ("ScanItem, Setting intensity failed"));
  1515. WIAS_LHRESULT(m_pIWiaLog, hr);
  1516. return hr;
  1517. }
  1518. hr = m_pScanAPI->FakeScanner_SetContrast(pv[8].lVal);
  1519. if (FAILED(hr)) {
  1520. WIAS_LERROR(m_pIWiaLog,
  1521. WIALOG_NO_RESOURCE_ID,
  1522. ("ScanItem, Setting contrast failed"));
  1523. WIAS_LHRESULT(m_pIWiaLog, hr);
  1524. return hr;
  1525. }
  1526. hr = m_pScanAPI->FakeScanner_SetSelectionArea(pv[2].lVal, pv[3].lVal, pv[4].lVal, pv[5].lVal);
  1527. if (FAILED(hr)) {
  1528. WIAS_LERROR(m_pIWiaLog,
  1529. WIALOG_NO_RESOURCE_ID,
  1530. ("ScanItem, Setting selection area (extents) failed"));
  1531. WIAS_LHRESULT(m_pIWiaLog, hr);
  1532. return hr;
  1533. }
  1534. }
  1535. return hr;
  1536. }
  1537. /**************************************************************************\
  1538. * CWIADevice::drvReadItemProperties
  1539. *
  1540. * drvReadItemProperties is called when an application tries to
  1541. * read a WIA Item's properties. The WIA Service will first notify
  1542. * the driver by calling this method.
  1543. * The WIA driver should verify that the property being read is accurate.
  1544. * This is a good place to access the hardware for properties that require
  1545. * device status.
  1546. * WIA_DPS_DOCUMENT_HANDLING_STATUS, or WIA_DPA_DEVICE_TIME if your device
  1547. * supports a clock.
  1548. *
  1549. * NOTE: The WIA driver should only go to the hardware on rare occasions.
  1550. * communicating with the hardware too much in this call, will cause
  1551. * the WIA driver to appear sluggish and slow.
  1552. *
  1553. * Arguments:
  1554. *
  1555. * pWiasContext - wia item
  1556. * lFlags - Operation flags, unused.
  1557. * nPropSpec - Number of elements in pPropSpec.
  1558. * pPropSpec - Pointer to property specification, showing which properties
  1559. * the application wants to read.
  1560. * plDevErrVal - Pointer to the device error value.
  1561. *
  1562. * Return Value:
  1563. *
  1564. * S_OK - if the operation was successful
  1565. * E_xxx - Error code, if the operation failed
  1566. *
  1567. * History:
  1568. *
  1569. * 03/05/2002 Original Version
  1570. *
  1571. \**************************************************************************/
  1572. HRESULT _stdcall CWIADevice::drvReadItemProperties(
  1573. BYTE *pWiasContext,
  1574. LONG lFlags,
  1575. ULONG nPropSpec,
  1576. const PROPSPEC *pPropSpec,
  1577. LONG *plDevErrVal)
  1578. {
  1579. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1580. WIALOG_NO_RESOURCE_ID,
  1581. WIALOG_LEVEL1,
  1582. "CWIADevice::drvReadItemProperties");
  1583. //
  1584. // If the caller did not pass in the correct parameters, then fail the
  1585. // call with E_INVALIDARG.
  1586. //
  1587. if (!pWiasContext) {
  1588. return E_INVALIDARG;
  1589. }
  1590. if (!plDevErrVal) {
  1591. return E_INVALIDARG;
  1592. }
  1593. if (!pPropSpec) {
  1594. return E_INVALIDARG;
  1595. }
  1596. *plDevErrVal = 0;
  1597. return S_OK;
  1598. }
  1599. /**************************************************************************\
  1600. * CWIADevice::drvLockWiaDevice
  1601. *
  1602. * drvLockWiaDevice will be called by the WIA service when access to the
  1603. * device is needed. Application's can not call this method directly.
  1604. * The WIA driver should see many drvLockWiaDevice() method calls followed
  1605. * by drvUnLockWiaDevice() method calls for most of the WIA operations on
  1606. * the device.
  1607. *
  1608. * It is recommended for the WIA driver to all the IStiDevice::LockDevice()
  1609. * method off of the interface passed in during the drvInitializeWia() method
  1610. * call. This will ensure that device locking is performed correctly by the
  1611. * WIA service. The WIA service will assist in keeping multiple client
  1612. * applications from connecting to the WIA driver at the same time.
  1613. *
  1614. * Arguments:
  1615. *
  1616. * pWiasContext - unused, can be NULL
  1617. * lFlags - Operation flags, unused.
  1618. * plDevErrVal - Pointer to the device error value.
  1619. *
  1620. *
  1621. * Return Value:
  1622. *
  1623. * S_OK - if the lock was successful
  1624. * E_xxx - Error code, if the operation failed
  1625. *
  1626. * History:
  1627. *
  1628. * 03/05/2002 Original Version
  1629. *
  1630. \**************************************************************************/
  1631. HRESULT _stdcall CWIADevice::drvLockWiaDevice(
  1632. BYTE *pWiasContext,
  1633. LONG lFlags,
  1634. LONG *plDevErrVal)
  1635. {
  1636. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1637. WIALOG_NO_RESOURCE_ID,
  1638. WIALOG_LEVEL1,
  1639. "CWIADevice::drvLockWiaDevice");
  1640. //
  1641. // If the caller did not pass in the correct parameters, then fail the
  1642. // call with E_INVALIDARG.
  1643. //
  1644. if (!pWiasContext) {
  1645. return E_INVALIDARG;
  1646. }
  1647. if (!plDevErrVal) {
  1648. return E_INVALIDARG;
  1649. }
  1650. *plDevErrVal = 0;
  1651. return m_pStiDevice->LockDevice(m_dwLockTimeout);
  1652. }
  1653. /**************************************************************************\
  1654. * CWIADevice::drvUnLockWiaDevice
  1655. *
  1656. * drvUnLockWiaDevice will be called by the WIA service when access to the
  1657. * device needs to be released. Application's can not call this method directly.
  1658. *
  1659. * It is recommended for the WIA driver to all the IStiDevice::UnLockDevice()
  1660. * method off of the interface passed in during the drvInitializeWia() method
  1661. * call. This will ensure that device unlocking is performed correctly by the
  1662. * WIA service. The WIA service will assist in keeping multiple client
  1663. * applications from connecting to the WIA driver at the same time.
  1664. *
  1665. * Arguments:
  1666. *
  1667. * pWiasContext - Pointer to the WIA item, unused.
  1668. * lFlags - Operation flags, unused.
  1669. * plDevErrVal - Pointer to the device error value.
  1670. *
  1671. * Return Value:
  1672. *
  1673. * S_OK - if the unlock was successful
  1674. * E_xxx - Error code, if the operation failed
  1675. *
  1676. * History:
  1677. *
  1678. * 03/05/2002 Original Version
  1679. *
  1680. \**************************************************************************/
  1681. HRESULT _stdcall CWIADevice::drvUnLockWiaDevice(
  1682. BYTE *pWiasContext,
  1683. LONG lFlags,
  1684. LONG *plDevErrVal)
  1685. {
  1686. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1687. WIALOG_NO_RESOURCE_ID,
  1688. WIALOG_LEVEL1,
  1689. "CWIADevice::drvUnLockWiaDevice");
  1690. //
  1691. // If the caller did not pass in the correct parameters, then fail the
  1692. // call with E_INVALIDARG.
  1693. //
  1694. if (!pWiasContext) {
  1695. return E_INVALIDARG;
  1696. }
  1697. if (!plDevErrVal) {
  1698. return E_INVALIDARG;
  1699. }
  1700. *plDevErrVal = 0;
  1701. return m_pStiDevice->UnLockDevice();
  1702. }
  1703. /**************************************************************************\
  1704. * CWIADevice::drvAnalyzeItem
  1705. *
  1706. * drvAnalyzeItem is called by the WIA service in response to the application
  1707. * call IWiaItem::AnalyzeItem() method call.
  1708. *
  1709. * The WIA driver should analyze the passed in WIA item (found by using
  1710. * the pWiasContext) and create/generate sub items.
  1711. *
  1712. * This feature of WIA is not currently used by any applications and is
  1713. * still being reviewed for more details.
  1714. *
  1715. * Arguments:
  1716. *
  1717. * pWiasContext - Pointer to the device item to be analyzed.
  1718. * lFlags - Operation flags.
  1719. * plDevErrVal - Pointer to the device error value.
  1720. *
  1721. * Return Value:
  1722. *
  1723. * S_OK - if the operation was successful
  1724. * E_xxx - Error code, if the operation failed
  1725. *
  1726. * History:
  1727. *
  1728. * 03/05/2002 Original Version
  1729. *
  1730. \**************************************************************************/
  1731. HRESULT _stdcall CWIADevice::drvAnalyzeItem(
  1732. BYTE *pWiasContext,
  1733. LONG lFlags,
  1734. LONG *plDevErrVal)
  1735. {
  1736. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1737. WIALOG_NO_RESOURCE_ID,
  1738. WIALOG_LEVEL1,
  1739. "CWIADevice::drvAnalyzeItem");
  1740. //
  1741. // If the caller did not pass in the correct parameters, then fail the
  1742. // call with E_INVALIDARG.
  1743. //
  1744. if (!pWiasContext) {
  1745. return E_INVALIDARG;
  1746. }
  1747. if (!plDevErrVal) {
  1748. return E_INVALIDARG;
  1749. }
  1750. *plDevErrVal = 0;
  1751. return E_NOTIMPL;
  1752. }
  1753. /**************************************************************************\
  1754. * drvGetDeviceErrorStr
  1755. *
  1756. * drvGetDeviceErrorStr is called by the WIA service to get more information
  1757. * about device specific error codes returned by each WIA driver method call.
  1758. * The WIA driver should map the incoming code to a user-readable string
  1759. * explaining the details of the error.
  1760. *
  1761. * Arguments:
  1762. *
  1763. * lFlags - Operation flags, unused.
  1764. * lDevErrVal - Device error value.
  1765. * ppszDevErrStr - Pointer to returned error string.
  1766. * plDevErrVal - Pointer to the device error value.
  1767. *
  1768. *
  1769. * Return Value:
  1770. *
  1771. * S_OK - if the operation was successful
  1772. * E_xxx - Error code, if the operation failed
  1773. *
  1774. * History:
  1775. *
  1776. * 03/05/2002 Original Version
  1777. *
  1778. \**************************************************************************/
  1779. HRESULT _stdcall CWIADevice::drvGetDeviceErrorStr(
  1780. LONG lFlags,
  1781. LONG lDevErrVal,
  1782. LPOLESTR *ppszDevErrStr,
  1783. LONG *plDevErr)
  1784. {
  1785. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1786. WIALOG_NO_RESOURCE_ID,
  1787. WIALOG_LEVEL1,
  1788. "CWIADevice::drvGetDeviceErrorStr");
  1789. //
  1790. // If the caller did not pass in the correct parameters, then fail the
  1791. // call with E_INVALIDARG.
  1792. //
  1793. if (!ppszDevErrStr) {
  1794. return E_INVALIDARG;
  1795. }
  1796. if (!plDevErr) {
  1797. return E_INVALIDARG;
  1798. }
  1799. HRESULT hr = S_OK;
  1800. //
  1801. // Map device errors to a strings
  1802. //
  1803. switch (lDevErrVal) {
  1804. case 0:
  1805. *ppszDevErrStr = NULL;
  1806. *plDevErr = 0;
  1807. break;
  1808. default:
  1809. *ppszDevErrStr = NULL;
  1810. *plDevErr = 0;
  1811. break;
  1812. }
  1813. return hr;
  1814. }
  1815. /**************************************************************************\
  1816. * drvDeviceCommand
  1817. *
  1818. * drvDeviceCommand is called by the WIA service is response to the
  1819. * application's call to IWiaItem::DeviceCommand method.
  1820. * The WIA driver should process the received device command targeted to
  1821. * the incoming WIA item. (determine the WIA item to receive the device
  1822. * command by using the pWiasContext pointer).
  1823. *
  1824. * Any command sent to the WIA driver that is not supported, should be
  1825. * failed with an E_INVALIDARG error code.
  1826. *
  1827. * Arguments:
  1828. *
  1829. * pWiasContext - Pointer to the WIA item.
  1830. * lFlags - Operation flags, unused.
  1831. * plCommand - Pointer to command GUID.
  1832. * ppWiaDrvItem - Optional pointer to returned item, unused.
  1833. * plDevErrVal - Pointer to the device error value.
  1834. *
  1835. * Return Value:
  1836. *
  1837. * S_OK - if the command was successfully processed
  1838. * E_xxx - Error code, if the operation failed.
  1839. *
  1840. * History:
  1841. *
  1842. * 03/05/2002 Original Version
  1843. *
  1844. \**************************************************************************/
  1845. HRESULT _stdcall CWIADevice::drvDeviceCommand(
  1846. BYTE *pWiasContext,
  1847. LONG lFlags,
  1848. const GUID *plCommand,
  1849. IWiaDrvItem **ppWiaDrvItem,
  1850. LONG *plDevErrVal)
  1851. {
  1852. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1853. WIALOG_NO_RESOURCE_ID,
  1854. WIALOG_LEVEL1,
  1855. "CWIADevice::drvDeviceCommand");
  1856. //
  1857. // If the caller did not pass in the correct parameters, then fail the
  1858. // call with E_INVALIDARG.
  1859. //
  1860. if (!pWiasContext) {
  1861. return E_INVALIDARG;
  1862. }
  1863. if (!plDevErrVal) {
  1864. return E_INVALIDARG;
  1865. }
  1866. if (!plCommand) {
  1867. return E_INVALIDARG;
  1868. }
  1869. *plDevErrVal = 0;
  1870. HRESULT hr = S_OK;
  1871. //
  1872. // Check which command was issued
  1873. //
  1874. if (*plCommand == WIA_CMD_SYNCHRONIZE) {
  1875. hr = S_OK;
  1876. } else {
  1877. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvDeviceCommand, unknown command sent to this device"));
  1878. hr = E_NOTIMPL;
  1879. }
  1880. return hr;
  1881. }
  1882. /**************************************************************************\
  1883. * CWIADevice::drvGetCapabilities
  1884. *
  1885. * drvGetCapabilities is called by the WIA service to obtain the WIA device
  1886. * supported EVENTS and COMMANDS.
  1887. *
  1888. * The WIA driver should first look at the incoming ulFlags parameter to
  1889. * determine what request it should be answering:
  1890. * The following requests are used:
  1891. *
  1892. * WIA_DEVICE_COMMANDS - requesting device commands only
  1893. * WIA_DEVICE_EVENTS - requesting device events only
  1894. * WIA_DEVICE_COMMANDS|WIA_DEVICE_EVENTS - requesting commands and events.
  1895. *
  1896. * The WIA driver should allocate memory (to be stored in this WIA driver
  1897. * and freed by this WIA driver) to contain an array of WIA_DEV_CAP_DRV
  1898. * structures. A pointer to this WIA driver allocated memory should be
  1899. * assigned to ppCapabilities.
  1900. *
  1901. * IMPORTANT NOTE!!! - The WIA service will not free this memory. It is up
  1902. * up to the WIA driver to manage the allocated memory.
  1903. *
  1904. * The WIA driver should place the number of structures allocated in the
  1905. * out parameter called pcelt.
  1906. *
  1907. * The WIA device should fill out each of the WIA_DEV_CAP_DRV structure fields
  1908. * with the following information.
  1909. *
  1910. * guid = Event or Command GUID
  1911. * ulFlags = Event or Command FLAGS
  1912. * wszName = Event or Command NAME
  1913. * wszDescription = Event or Command DESCRIPTION
  1914. * wszIcon = Event or Command ICON
  1915. *
  1916. *
  1917. *
  1918. * Arguments:
  1919. *
  1920. * pWiasContext - Pointer to the WIA item, unused.
  1921. * lFlags - Operation flags.
  1922. * pcelt - Pointer to returned number of elements in
  1923. * returned array.
  1924. * ppCapabilities - Pointer to driver allocate and managed array.
  1925. * plDevErrVal - Pointer to the device error value.
  1926. *
  1927. * Return Value:
  1928. *
  1929. * S_OK - if the operation was successful
  1930. * E_xxx - Error code, if the operation failed
  1931. *
  1932. * History:
  1933. *
  1934. * 03/05/2002 Original Version
  1935. *
  1936. \**************************************************************************/
  1937. HRESULT _stdcall CWIADevice::drvGetCapabilities(
  1938. BYTE *pWiasContext,
  1939. LONG ulFlags,
  1940. LONG *pcelt,
  1941. WIA_DEV_CAP_DRV **ppCapabilities,
  1942. LONG *plDevErrVal)
  1943. {
  1944. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  1945. WIALOG_NO_RESOURCE_ID,
  1946. WIALOG_LEVEL1,
  1947. "CWIADevice::drvGetCapabilites");
  1948. //
  1949. // If the caller did not pass in the correct parameters, then fail the
  1950. // call with E_INVALIDARG.
  1951. //
  1952. if (!pWiasContext) {
  1953. //
  1954. // The WIA service may pass in a NULL for the pWiasContext. This is expected
  1955. // because there is a case where no item was created at the time the event was fired.
  1956. //
  1957. }
  1958. if (!plDevErrVal) {
  1959. return E_INVALIDARG;
  1960. }
  1961. if (!pcelt) {
  1962. return E_INVALIDARG;
  1963. }
  1964. if (!ppCapabilities) {
  1965. return E_INVALIDARG;
  1966. }
  1967. *plDevErrVal = 0;
  1968. HRESULT hr = S_OK;
  1969. //
  1970. // Initialize Capabilities array
  1971. //
  1972. hr = BuildCapabilities();
  1973. if (FAILED(hr)) {
  1974. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvGetCapabilities, BuildCapabilities failed"));
  1975. WIAS_LHRESULT(m_pIWiaLog, hr);
  1976. return hr;
  1977. }
  1978. //
  1979. // Return depends on flags. Flags specify whether we should return
  1980. // commands, events, or both.
  1981. //
  1982. //
  1983. switch (ulFlags) {
  1984. case WIA_DEVICE_COMMANDS:
  1985. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvGetCapabilities, (WIA_DEVICE_COMMANDS)"));
  1986. //
  1987. // report commands only
  1988. //
  1989. *pcelt = m_NumSupportedCommands;
  1990. *ppCapabilities = &m_pCapabilities[m_NumSupportedEvents];
  1991. break;
  1992. case WIA_DEVICE_EVENTS:
  1993. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvGetCapabilities, (WIA_DEVICE_EVENTS)"));
  1994. //
  1995. // report events only
  1996. //
  1997. *pcelt = m_NumSupportedEvents;
  1998. *ppCapabilities = m_pCapabilities;
  1999. break;
  2000. case (WIA_DEVICE_COMMANDS | WIA_DEVICE_EVENTS):
  2001. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvGetCapabilities, (WIA_DEVICE_COMMANDS|WIA_DEVICE_EVENTS)"));
  2002. //
  2003. // report both events and commands
  2004. //
  2005. *pcelt = (m_NumSupportedCommands + m_NumSupportedEvents);
  2006. *ppCapabilities = m_pCapabilities;
  2007. break;
  2008. default:
  2009. //
  2010. // invalid request
  2011. //
  2012. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("drvGetCapabilities, invalid flags"));
  2013. return E_INVALIDARG;
  2014. }
  2015. return hr;
  2016. }
  2017. /**************************************************************************\
  2018. * CWIADevice::drvDeleteItem
  2019. *
  2020. * drvDeleteItem is called by the WIA service when a WIA application calls
  2021. * IWiaItem::DeleteItem() method to delete a WIA item.
  2022. *
  2023. * The WIA service will verify the following before calling this method.
  2024. * 1. The item is NOT a root item.
  2025. * 2. The item is a folder, and has NO children
  2026. * 3. The item's access rights allow deletion.
  2027. *
  2028. * Since the the WIA service verifies these conditions, it is NOT necessary
  2029. * for the WIA driver to also verify them.
  2030. *
  2031. * Arguments:
  2032. *
  2033. * pWiasContext - Indicates the item to delete.
  2034. * lFlags - Operation flags, unused.
  2035. * plDevErrVal - Pointer to the device error value.
  2036. *
  2037. * Return Value:
  2038. *
  2039. * S_OK - if the delete operation was successful
  2040. * E_xxx - Error code, if the delete operation failed
  2041. *
  2042. * History:
  2043. *
  2044. * 03/05/2002 Original Version
  2045. *
  2046. \**************************************************************************/
  2047. HRESULT _stdcall CWIADevice::drvDeleteItem(
  2048. BYTE *pWiasContext,
  2049. LONG lFlags,
  2050. LONG *plDevErrVal)
  2051. {
  2052. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2053. WIALOG_NO_RESOURCE_ID,
  2054. WIALOG_LEVEL1,
  2055. "CWIADevice::drvDeleteItem");
  2056. //
  2057. // If the caller did not pass in the correct parameters, then fail the
  2058. // call with E_INVALIDARG.
  2059. //
  2060. if (!pWiasContext) {
  2061. return E_INVALIDARG;
  2062. }
  2063. if (!plDevErrVal) {
  2064. return E_INVALIDARG;
  2065. }
  2066. *plDevErrVal = 0;
  2067. //
  2068. // if this functionality is not supported on this item, then return
  2069. // STG_E_ACCESSDENIED as the error code.
  2070. //
  2071. return STG_E_ACCESSDENIED;
  2072. }
  2073. /**************************************************************************\
  2074. * CWIADevice::drvFreeDrvItemContext
  2075. *
  2076. * drvFreeDrvItemContext is called by the WIA service to free any WIA driver
  2077. * allocated device specific context information.
  2078. *
  2079. * Arguments:
  2080. *
  2081. * lFlags - Operation flags, unused.
  2082. * pDevSpecContext - Pointer to device specific context.
  2083. * plDevErrVal - Pointer to the device error value.
  2084. *
  2085. * Return Value:
  2086. *
  2087. * S_OK - if the operation was successful
  2088. * E_xxx - Error code, if the operation failed.
  2089. *
  2090. * History:
  2091. *
  2092. * 03/05/2002 Original Version
  2093. *
  2094. \**************************************************************************/
  2095. HRESULT _stdcall CWIADevice::drvFreeDrvItemContext(
  2096. LONG lFlags,
  2097. BYTE *pSpecContext,
  2098. LONG *plDevErrVal)
  2099. {
  2100. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2101. WIALOG_NO_RESOURCE_ID,
  2102. WIALOG_LEVEL1,
  2103. "CWIADevice::drvFreeDrvItemContext");
  2104. if (!plDevErrVal) {
  2105. return E_INVALIDARG;
  2106. }
  2107. *plDevErrVal = 0;
  2108. PMINIDRIVERITEMCONTEXT pContext = NULL;
  2109. pContext = (PMINIDRIVERITEMCONTEXT) pSpecContext;
  2110. if (pContext) {
  2111. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvFreeDrvItemContext, Freeing my allocated context members"));
  2112. }
  2113. return S_OK;
  2114. }
  2115. /**************************************************************************\
  2116. * drvGetWiaFormatInfo
  2117. *
  2118. * drvGetWiaFormatInfo is called by the WIA service to obtain the WIA device
  2119. * supported TYMED and FORMAT pairs.
  2120. *
  2121. * The WIA driver should allocate memory (to be stored in this WIA driver
  2122. * and freed by this WIA driver) to contain an array of WIA_FORMAT_INFO
  2123. * structures. A pointer to this WIA driver allocated memory should be
  2124. * assigned to ppwfi.
  2125. *
  2126. * IMPORTANT NOTE!!! - The WIA service will not free this memory. It is up
  2127. * up to the WIA driver to manage the allocated memory.
  2128. *
  2129. * The WIA driver should place the number of structures allocated in the
  2130. * out parameter called pcelt.
  2131. *
  2132. * The WIA device should fill out each of the WIA_FORMAT_INFO structure fields
  2133. * with the following information.
  2134. *
  2135. * guidFormatID = Image Format GUID
  2136. * lTymed = TYMED associated with the Image Format GUID
  2137. * Valid TYMEDs are: (Also known as "Media Type")
  2138. * TYMED_FILE
  2139. * TYMED_MULTIPAGE_FILE
  2140. * TYMED_CALLBACK
  2141. * TYMED_MULTIPAGE_CALLBACK
  2142. *
  2143. * Arguments:
  2144. *
  2145. * pWiasContext - Pointer to the WIA item context, unused.
  2146. * lFlags - Operation flags, unused.
  2147. * pcelt - Pointer to returned number of elements in
  2148. * returned WIA_FORMAT_INFO array.
  2149. * ppwfi - Pointer to returned WIA_FORMAT_INFO array.
  2150. * plDevErrVal - Pointer to the device error value.
  2151. *
  2152. * Return Value:
  2153. *
  2154. * Status
  2155. *
  2156. * History:
  2157. *
  2158. * 03/05/2002 Original Version
  2159. *
  2160. \**************************************************************************/
  2161. HRESULT _stdcall CWIADevice::drvGetWiaFormatInfo(
  2162. BYTE *pWiasContext,
  2163. LONG lFlags,
  2164. LONG *pcelt,
  2165. WIA_FORMAT_INFO **ppwfi,
  2166. LONG *plDevErrVal)
  2167. {
  2168. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2169. WIALOG_NO_RESOURCE_ID,
  2170. WIALOG_LEVEL1,
  2171. "CWIADevice::drvGetWiaFormatInfo");
  2172. //
  2173. // If the caller did not pass in the correct parameters, then fail the
  2174. // call with E_INVALIDARG.
  2175. //
  2176. if (!pWiasContext) {
  2177. return E_INVALIDARG;
  2178. }
  2179. if (!plDevErrVal) {
  2180. return E_INVALIDARG;
  2181. }
  2182. if (!pcelt) {
  2183. return E_INVALIDARG;
  2184. }
  2185. if (!ppwfi) {
  2186. return E_INVALIDARG;
  2187. }
  2188. HRESULT hr = S_OK;
  2189. if (NULL == m_pSupportedFormats) {
  2190. hr = BuildSupportedFormats();
  2191. }
  2192. *plDevErrVal = 0;
  2193. *pcelt = m_NumSupportedFormats;
  2194. *ppwfi = m_pSupportedFormats;
  2195. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvGetWiaFormatInfo, m_NumSupportedFormats = %d",m_NumSupportedFormats));
  2196. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("drvGetWiaFormatInfo, m_pSupportedFormats = %x",m_pSupportedFormats));
  2197. return hr;
  2198. }
  2199. /**************************************************************************\
  2200. * drvNotifyPnpEvent
  2201. *
  2202. * drvNotifyPnpEvent is called by the WIA service when system events occur.
  2203. * The WIA driver should check the pEventGUID parameter to determine what
  2204. * event is being processed.
  2205. * Some common events that need to be processed are:
  2206. *
  2207. * WIA_EVENT_POWER_SUSPEND - system is going to suspend/sleep mode
  2208. * WIA_EVENT_POWER_RESUME - system is waking up from suspend/sleep mode
  2209. * The WIA driver should restore any event interrrupt wait states
  2210. * after returning from a suspend. This will ensure that the events
  2211. * will still function when the system wakes up.
  2212. *
  2213. * Arguments:
  2214. *
  2215. * pEventGUID - Pointer to an event GUID
  2216. * bstrDeviceID - Device ID
  2217. * ulReserved - reserved
  2218. *
  2219. * Return Value:
  2220. *
  2221. * S_OK - if the operation completed successfully
  2222. * E_xxx - Error code if the operation failed
  2223. *
  2224. * History:
  2225. *
  2226. * 03/05/2002 Original Version
  2227. *
  2228. \**************************************************************************/
  2229. HRESULT _stdcall CWIADevice::drvNotifyPnpEvent(
  2230. const GUID *pEventGUID,
  2231. BSTR bstrDeviceID,
  2232. ULONG ulReserved)
  2233. {
  2234. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2235. WIALOG_NO_RESOURCE_ID,
  2236. WIALOG_LEVEL1,
  2237. "CWIADevice::DrvNotifyPnpEvent");
  2238. //
  2239. // If the caller did not pass in the correct parameters, then fail the
  2240. // call with E_INVALIDARG.
  2241. //
  2242. if ((!pEventGUID)||(!bstrDeviceID)) {
  2243. return E_INVALIDARG;
  2244. }
  2245. HRESULT hr = S_OK;
  2246. if(*pEventGUID == WIA_EVENT_POWER_SUSPEND) {
  2247. //
  2248. // disable any driver activity to make sure we properly
  2249. // shutdown (the driver is not being unloaded, just disabled)
  2250. //
  2251. } else if(*pEventGUID == WIA_EVENT_POWER_RESUME) {
  2252. //
  2253. // re-establish any event notifications to make sure we properly setup
  2254. // any event waiting status using the WIA service supplied event
  2255. // handle
  2256. //
  2257. if(m_EventOverlapped.hEvent) {
  2258. //
  2259. // call ourselves with the cached EVENT handle given to
  2260. // the WIA driver by the WIA service.
  2261. //
  2262. SetNotificationHandle(m_EventOverlapped.hEvent);
  2263. }
  2264. }
  2265. return hr;
  2266. }
  2267. /**************************************************************************\
  2268. * CWIADevice::drvUnInitializeWia
  2269. *
  2270. * drvUnInitializeWia is called by the WIA service when an application
  2271. * releases its last reference to any WIA items created.
  2272. *
  2273. * NOTE: This call does not mean all clients are disconnected. There
  2274. * should be one call per client disconnect.
  2275. *
  2276. * drvUnInitializeWia should be paired with a corresponding drvInitializeWia
  2277. * call.
  2278. *
  2279. * The WIA driver should NOT free any driver resources in this method
  2280. * call unless it can safely determine that NO applications are
  2281. * currently connected.
  2282. *
  2283. * To determine the current application connection count, the WIA driver
  2284. * can keep a reference counter in the method calls to drvInitializeWia()
  2285. * (incrementing the counter) and drvUnInitializeWia() (decrementing the counter).
  2286. *
  2287. * Arguments:
  2288. *
  2289. * pWiasContext - Pointer to the WIA Root item context of the client's
  2290. * item tree.
  2291. *
  2292. * Return Value:
  2293. * S_OK - if the operation completed successfully
  2294. * E_xxx - Error code, if the operation failed
  2295. *
  2296. * History:
  2297. *
  2298. * 03/05/2002 Original Version
  2299. *
  2300. \**************************************************************************/
  2301. HRESULT _stdcall CWIADevice::drvUnInitializeWia(
  2302. BYTE *pWiasContext)
  2303. {
  2304. //
  2305. // If the caller did not pass in the correct parameters, then fail the
  2306. // call with E_INVALIDARG.
  2307. //
  2308. if (!pWiasContext) {
  2309. return E_INVALIDARG;
  2310. }
  2311. InterlockedDecrement(&m_lClientsConnected);
  2312. //
  2313. // make sure we never decrement below zero (0)
  2314. //
  2315. if(m_lClientsConnected < 0){
  2316. m_lClientsConnected = 0;
  2317. }
  2318. //
  2319. // check for connected applications.
  2320. //
  2321. if(m_lClientsConnected == 0){
  2322. //
  2323. // There are no application clients connected to this WIA driver
  2324. //
  2325. }
  2326. return S_OK;
  2327. }
  2328. /*******************************************************************************
  2329. *
  2330. * P R I V A T E M E T H O D S
  2331. *
  2332. *******************************************************************************/
  2333. /**************************************************************************\
  2334. * AlignInPlace
  2335. *
  2336. * DWORD align a data buffer in place.
  2337. *
  2338. * Arguments:
  2339. *
  2340. * pBuffer - Pointer to the data buffer.
  2341. * cbWritten - Size of the data in bytes.
  2342. * lBytesPerScanLine - Number of bytes per scan line in the output data.
  2343. * lBytesPerScanLineRaw - Number of bytes per scan line in the input data.
  2344. *
  2345. * Return Value:
  2346. *
  2347. * Status
  2348. *
  2349. * History:
  2350. *
  2351. * 03/05/2002 Original Version
  2352. *
  2353. \**************************************************************************/
  2354. UINT CWIADevice::AlignInPlace(
  2355. PBYTE pBuffer,
  2356. LONG cbWritten,
  2357. LONG lBytesPerScanLine,
  2358. LONG lBytesPerScanLineRaw)
  2359. {
  2360. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2361. WIALOG_NO_RESOURCE_ID,
  2362. WIALOG_LEVEL3,
  2363. "::AlignInPlace");
  2364. //
  2365. // If the caller did not pass in the correct parameters, then fail the
  2366. // call with E_INVALIDARG.
  2367. //
  2368. if (!pBuffer) {
  2369. return 0;
  2370. }
  2371. if ((lBytesPerScanLine <= 0)||(lBytesPerScanLineRaw <= 0)) {
  2372. return 0;
  2373. }
  2374. if (lBytesPerScanLineRaw % 4) {
  2375. UINT uiPadBytes = lBytesPerScanLine - lBytesPerScanLineRaw;
  2376. UINT uiDevLinesWritten = cbWritten / lBytesPerScanLineRaw;
  2377. PBYTE pSrc = pBuffer + cbWritten - 1;
  2378. PBYTE pDst = pBuffer + (uiDevLinesWritten * lBytesPerScanLine) - 1;
  2379. while (pSrc >= pBuffer) {
  2380. pDst -= uiPadBytes;
  2381. for (LONG i = 0; i < lBytesPerScanLineRaw; i++) {
  2382. *pDst-- = *pSrc--;
  2383. }
  2384. }
  2385. return uiDevLinesWritten * lBytesPerScanLine;
  2386. }
  2387. return cbWritten;
  2388. }
  2389. /**************************************************************************\
  2390. * UnlinkItemTree
  2391. *
  2392. * Call device manager to unlink and release our reference to
  2393. * all items in the driver item tree.
  2394. *
  2395. * Arguments:
  2396. *
  2397. *
  2398. *
  2399. * Return Value:
  2400. *
  2401. * Status
  2402. *
  2403. * History:
  2404. *
  2405. * 03/05/2002 Original Version
  2406. *
  2407. \**************************************************************************/
  2408. HRESULT CWIADevice::DeleteItemTree(void)
  2409. {
  2410. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2411. WIALOG_NO_RESOURCE_ID,
  2412. WIALOG_LEVEL3,
  2413. "CWIADevice::DeleteItemTree");
  2414. HRESULT hr = S_OK;
  2415. //
  2416. // If no tree, return.
  2417. //
  2418. if (!m_pIDrvItemRoot) {
  2419. WIAS_LWARNING(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("DeleteItemTree, no tree to delete..."));
  2420. return S_OK;
  2421. }
  2422. //
  2423. // Call device manager to unlink the driver item tree.
  2424. //
  2425. hr = m_pIDrvItemRoot->UnlinkItemTree(WiaItemTypeDisconnected);
  2426. if (SUCCEEDED(hr)) {
  2427. WIAS_LWARNING(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("DeleteItemTree, m_pIDrvItemRoot is being released!!"));
  2428. m_pIDrvItemRoot->Release();
  2429. m_pIDrvItemRoot = NULL;
  2430. }
  2431. return hr;
  2432. }
  2433. /**************************************************************************\
  2434. * DeleteRootItemProperties
  2435. *
  2436. * This helper deletes the arrays used for Property intialization.
  2437. *
  2438. * Arguments:
  2439. *
  2440. * none
  2441. *
  2442. * Return Value:
  2443. *
  2444. * Status
  2445. *
  2446. * History:
  2447. *
  2448. * 03/05/2002 Original Version
  2449. *
  2450. \**************************************************************************/
  2451. HRESULT CWIADevice::DeleteRootItemProperties()
  2452. {
  2453. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2454. WIALOG_NO_RESOURCE_ID,
  2455. WIALOG_LEVEL1,
  2456. "CWIADevice::DeleteRootItemProperties");
  2457. HRESULT hr = S_OK;
  2458. //
  2459. // delete any allocated arrays
  2460. //
  2461. DeleteSupportedPreviewModesArrayContents();
  2462. if (NULL != m_RootItemInitInfo.pszPropNames) {
  2463. delete [] m_RootItemInitInfo.pszPropNames;
  2464. m_RootItemInitInfo.pszPropNames = NULL;
  2465. }
  2466. if (NULL != m_RootItemInitInfo.piPropIDs) {
  2467. delete [] m_RootItemInitInfo.piPropIDs;
  2468. m_RootItemInitInfo.piPropIDs = NULL;
  2469. }
  2470. if (NULL != m_RootItemInitInfo.pvPropVars) {
  2471. FreePropVariantArray(m_RootItemInitInfo.lNumProps,m_RootItemInitInfo.pvPropVars);
  2472. delete [] m_RootItemInitInfo.pvPropVars;
  2473. m_RootItemInitInfo.pvPropVars = NULL;
  2474. }
  2475. if (NULL != m_RootItemInitInfo.psPropSpec) {
  2476. delete [] m_RootItemInitInfo.psPropSpec;
  2477. m_RootItemInitInfo.psPropSpec = NULL;
  2478. }
  2479. if (NULL != m_RootItemInitInfo.pwpiPropInfo) {
  2480. delete [] m_RootItemInitInfo.pwpiPropInfo;
  2481. m_RootItemInitInfo.pwpiPropInfo = NULL;
  2482. }
  2483. m_RootItemInitInfo.lNumProps = 0;
  2484. return hr;
  2485. }
  2486. /**************************************************************************\
  2487. * BuildRootItemProperties
  2488. *
  2489. * This helper creates/initializes the arrays used for Property intialization.
  2490. *
  2491. * Arguments:
  2492. *
  2493. * none
  2494. *
  2495. * Return Value:
  2496. *
  2497. * Status
  2498. *
  2499. * History:
  2500. *
  2501. * 03/05/2002 Original Version
  2502. *
  2503. \**************************************************************************/
  2504. HRESULT CWIADevice::BuildRootItemProperties()
  2505. {
  2506. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2507. WIALOG_NO_RESOURCE_ID,
  2508. WIALOG_LEVEL1,
  2509. "CWIADevice::BuildRootItemProperties");
  2510. HRESULT hr = S_OK;
  2511. LONG PropIndex = 0;
  2512. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2513. m_RootItemInitInfo.lNumProps = 17; // standard properties + ADF specific
  2514. #else
  2515. //
  2516. // check for ADF
  2517. //
  2518. if (m_pScanAPI->FakeScanner_ADFAttached() == S_OK) {
  2519. m_bADFAttached = TRUE;
  2520. }
  2521. //
  2522. // set the number of properties
  2523. //
  2524. if (m_bADFAttached) {
  2525. m_RootItemInitInfo.lNumProps = 19; // standard properties + ADF specific
  2526. } else {
  2527. m_RootItemInitInfo.lNumProps = 10; // standard properties only
  2528. }
  2529. #endif
  2530. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CMicroDriverAPI::BuildRootItemProperties, Number of Properties = %d",m_RootItemInitInfo.lNumProps));
  2531. m_RootItemInitInfo.pszPropNames = new LPOLESTR[m_RootItemInitInfo.lNumProps];
  2532. if (NULL != m_RootItemInitInfo.pszPropNames) {
  2533. m_RootItemInitInfo.piPropIDs = new PROPID[m_RootItemInitInfo.lNumProps];
  2534. if (NULL != m_RootItemInitInfo.piPropIDs) {
  2535. m_RootItemInitInfo.pvPropVars = new PROPVARIANT[m_RootItemInitInfo.lNumProps];
  2536. if (NULL != m_RootItemInitInfo.pvPropVars) {
  2537. m_RootItemInitInfo.psPropSpec = new PROPSPEC[m_RootItemInitInfo.lNumProps];
  2538. if (NULL != m_RootItemInitInfo.psPropSpec) {
  2539. m_RootItemInitInfo.pwpiPropInfo = new WIA_PROPERTY_INFO[m_RootItemInitInfo.lNumProps];
  2540. if (NULL == m_RootItemInitInfo.pwpiPropInfo)
  2541. hr = E_OUTOFMEMORY;
  2542. } else
  2543. hr = E_OUTOFMEMORY;
  2544. } else
  2545. hr = E_OUTOFMEMORY;
  2546. } else
  2547. hr = E_OUTOFMEMORY;
  2548. } else
  2549. hr = E_OUTOFMEMORY;
  2550. if (FAILED(hr)) {
  2551. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildRootItemProperties, memory allocation failed"));
  2552. WIAS_LHRESULT(m_pIWiaLog, hr);
  2553. DeleteRootItemProperties();
  2554. return hr;
  2555. }
  2556. ROOT_ITEM_INFORMATION RootItemInfo;
  2557. hr = m_pScanAPI->FakeScanner_GetRootPropertyInfo(&RootItemInfo);
  2558. if (FAILED(hr)) {
  2559. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildRootItemProperties, FakeScanner_GetRootPropertyInfo failed"));
  2560. WIAS_LHRESULT(m_pIWiaLog, hr);
  2561. DeleteRootItemProperties();
  2562. return hr;
  2563. }
  2564. #ifndef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2565. //
  2566. // WIA_DPS_HORIZONTAL_BED_SIZE and WIA_DPS_VERTICAL_BED_SIZE should not exist for scanners
  2567. // that only have a feeder. Theses are flatbed scanner properties only.
  2568. //
  2569. // Intialize WIA_DPS_HORIZONTAL_BED_SIZE
  2570. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_HORIZONTAL_BED_SIZE_STR;
  2571. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_HORIZONTAL_BED_SIZE;
  2572. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.ScanBedWidth;
  2573. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2574. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2575. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2576. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2577. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2578. PropIndex++;
  2579. // Intialize WIA_DPS_VERTICAL_BED_SIZE
  2580. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_VERTICAL_BED_SIZE_STR;
  2581. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_VERTICAL_BED_SIZE;
  2582. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.ScanBedHeight;
  2583. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2584. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2585. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2586. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2587. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2588. PropIndex++;
  2589. #endif
  2590. // Intialize WIA_IPA_ACCESS_RIGHTS
  2591. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_ACCESS_RIGHTS_STR;
  2592. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_ACCESS_RIGHTS;
  2593. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = WIA_ITEM_READ|WIA_ITEM_WRITE;
  2594. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_UI4;
  2595. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2596. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2597. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2598. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2599. PropIndex++;
  2600. // Intialize WIA_DPS_OPTICAL_XRES
  2601. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_OPTICAL_XRES_STR;
  2602. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_OPTICAL_XRES;
  2603. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.OpticalXResolution;
  2604. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2605. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2606. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2607. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2608. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2609. PropIndex++;
  2610. // Intialize WIA_DPS_OPTICAL_YRES
  2611. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_OPTICAL_YRES_STR;
  2612. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_OPTICAL_YRES;
  2613. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.OpticalYResolution;
  2614. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2615. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2616. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2617. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2618. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2619. PropIndex++;
  2620. // Initialize WIA_DPA_FIRMWARE_VERSION
  2621. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPA_FIRMWARE_VERSION_STR;
  2622. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPA_FIRMWARE_VERSION;
  2623. m_RootItemInitInfo.pvPropVars [PropIndex].bstrVal = SysAllocString(RootItemInfo.FirmwareVersion);
  2624. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_BSTR;
  2625. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2626. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2627. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2628. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2629. PropIndex++;
  2630. // Initialize WIA_IPA_ITEM_FLAGS
  2631. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_ITEM_FLAGS_STR;
  2632. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_ITEM_FLAGS;
  2633. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = WiaItemTypeRoot|WiaItemTypeFolder|WiaItemTypeDevice;
  2634. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2635. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2636. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2637. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_FLAG;
  2638. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2639. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.Nom = m_RootItemInitInfo.pvPropVars [PropIndex].lVal;
  2640. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.ValidBits = WiaItemTypeRoot|WiaItemTypeFolder|WiaItemTypeDevice;
  2641. PropIndex++;
  2642. // Intialize WIA_DPS_MAX_SCAN_TIME (NONE)
  2643. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_MAX_SCAN_TIME_STR;
  2644. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_MAX_SCAN_TIME;
  2645. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.MaxScanTime;
  2646. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2647. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2648. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2649. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2650. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2651. PropIndex++;
  2652. // Intialize WIA_DPS_PREVIEW (LIST)
  2653. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_PREVIEW_STR;
  2654. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_PREVIEW;
  2655. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = WIA_FINAL_SCAN;
  2656. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2657. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2658. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2659. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  2660. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2661. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList= (BYTE*)m_SupportedPreviewModes.plValues;
  2662. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_RootItemInitInfo.pvPropVars [PropIndex].lVal;
  2663. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedPreviewModes.lNumValues;
  2664. PropIndex++;
  2665. // Initialize WIA_DPS_SHOW_PREVIEW_CONTROL (NONE)
  2666. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_SHOW_PREVIEW_CONTROL_STR;
  2667. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_SHOW_PREVIEW_CONTROL;
  2668. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2669. //
  2670. // Scanners that have a feeder that can not perform a preview scan should set the
  2671. // WIA_DPS_SHOW_PREVIEW_CONTROL property to WIA_DONT_SHOW_PREVIEW_CONTROL. This
  2672. // will eliminate the preview control from being shown in the Microsoft common UI
  2673. // dialogs, and the Scanner and Camera Wizard.
  2674. //
  2675. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = WIA_DONT_SHOW_PREVIEW_CONTROL;
  2676. #else // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2677. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = WIA_SHOW_PREVIEW_CONTROL;
  2678. #endif // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2679. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2680. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2681. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2682. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2683. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2684. PropIndex++;
  2685. //
  2686. // if a Document feeder is attached...add the following properties
  2687. //
  2688. if (m_bADFAttached) {
  2689. // Initialize WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE
  2690. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE_STR;
  2691. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE;
  2692. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederWidth;
  2693. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2694. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2695. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2696. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2697. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2698. PropIndex++;
  2699. // Initialize WIA_DPS_VERTICAL_SHEET_FEED_SIZE
  2700. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_VERTICAL_SHEET_FEED_SIZE_STR;
  2701. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_VERTICAL_SHEET_FEED_SIZE;
  2702. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2703. //
  2704. // scanners that can not determine the length of the page in the feeder should
  2705. // set this property to 0. This will tell the application that the vertical
  2706. // sheet feed size of the scanner is unknown
  2707. //
  2708. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  2709. #else // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2710. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederHeight;
  2711. #endif // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2712. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2713. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2714. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2715. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2716. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2717. PropIndex++;
  2718. // Initialize WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES
  2719. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES_STR;
  2720. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES;
  2721. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederCaps;
  2722. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2723. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2724. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2725. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_FLAG;
  2726. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2727. PropIndex++;
  2728. // Initialize WIA_DPS_DOCUMENT_HANDLING_STATUS
  2729. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_DOCUMENT_HANDLING_STATUS_STR;
  2730. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_DOCUMENT_HANDLING_STATUS;
  2731. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederStatus;
  2732. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2733. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2734. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2735. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_FLAG;
  2736. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2737. PropIndex++;
  2738. // Initialize WIA_DPS_DOCUMENT_HANDLING_SELECT
  2739. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_DOCUMENT_HANDLING_SELECT_STR;
  2740. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_DOCUMENT_HANDLING_SELECT;
  2741. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2742. //
  2743. // scanners that only have a feeder and no flatbed, should set the WIA_DPS_DOCUMENT_HANDLING_SELECT
  2744. // property to FEEDER as the initial setting. This will let the application know that the device
  2745. // is currently in FEEDER mode. The valid values for this property should be set to FEEDER only
  2746. // as well. This will avoid any applications trying to set the WIA_DPS_DOCUMENT_HANDLING_SELECT
  2747. // property to FLATBED.
  2748. //
  2749. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = FEEDER;
  2750. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.ValidBits = FEEDER;
  2751. #else // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2752. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = FLATBED;
  2753. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.ValidBits = FEEDER | FLATBED;
  2754. #endif // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2755. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2756. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2757. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2758. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_FLAG;
  2759. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2760. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.Nom = m_RootItemInitInfo.pvPropVars [PropIndex].lVal;
  2761. PropIndex++;
  2762. // Initialize WIA_DPS_PAGES
  2763. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_PAGES_STR;
  2764. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_PAGES;
  2765. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = 1;
  2766. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2767. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2768. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2769. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  2770. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2771. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = 1;
  2772. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  2773. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = RootItemInfo.MaxPageCapacity;
  2774. m_RootItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = 1;
  2775. PropIndex++;
  2776. // Initialize WIA_DPS_SHEET_FEEDER_REGISTRATION
  2777. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_SHEET_FEEDER_REGISTRATION_STR;
  2778. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_SHEET_FEEDER_REGISTRATION;
  2779. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederReg;
  2780. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2781. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2782. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2783. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2784. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2785. PropIndex++;
  2786. // Initialize WIA_DPS_HORIZONTAL_BED_REGISTRATION
  2787. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_HORIZONTAL_BED_REGISTRATION_STR;
  2788. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_HORIZONTAL_BED_REGISTRATION;
  2789. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederHReg;
  2790. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2791. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2792. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2793. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2794. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2795. PropIndex++;
  2796. // Initialize WIA_DPS_VERTICAL_BED_REGISTRATION
  2797. m_RootItemInitInfo.pszPropNames[PropIndex] = WIA_DPS_VERTICAL_BED_REGISTRATION_STR;
  2798. m_RootItemInitInfo.piPropIDs [PropIndex] = WIA_DPS_VERTICAL_BED_REGISTRATION;
  2799. m_RootItemInitInfo.pvPropVars [PropIndex].lVal = RootItemInfo.DocumentFeederVReg;
  2800. m_RootItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2801. m_RootItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2802. m_RootItemInitInfo.psPropSpec [PropIndex].propid = m_RootItemInitInfo.piPropIDs [PropIndex];
  2803. m_RootItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2804. m_RootItemInitInfo.pwpiPropInfo[PropIndex].vt = m_RootItemInitInfo.pvPropVars [PropIndex].vt;
  2805. PropIndex++;
  2806. }
  2807. return hr;
  2808. }
  2809. /**************************************************************************\
  2810. * DeleteChildItemProperties
  2811. *
  2812. * This helper deletes the arrays used for Property intialization.
  2813. *
  2814. * Arguments:
  2815. *
  2816. * none
  2817. *
  2818. * Return Value:
  2819. *
  2820. * Status
  2821. *
  2822. * History:
  2823. *
  2824. * 03/05/2002 Original Version
  2825. *
  2826. \**************************************************************************/
  2827. HRESULT CWIADevice::DeleteChildItemProperties()
  2828. {
  2829. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2830. WIALOG_NO_RESOURCE_ID,
  2831. WIALOG_LEVEL1,
  2832. "CWIADevice::DeleteChildItemProperties");
  2833. HRESULT hr = S_OK;
  2834. //
  2835. // delete any allocated arrays
  2836. //
  2837. DeleteSupportedFormatsArrayContents();
  2838. DeleteSupportedDataTypesArrayContents();
  2839. DeleteSupportedCompressionsArrayContents();
  2840. DeleteSupportedTYMEDArrayContents();
  2841. DeleteInitialFormatsArrayContents();
  2842. DeleteSupportedResolutionsArrayContents();
  2843. if (NULL != m_ChildItemInitInfo.pszPropNames) {
  2844. delete [] m_ChildItemInitInfo.pszPropNames;
  2845. m_ChildItemInitInfo.pszPropNames = NULL;
  2846. }
  2847. if (NULL != m_ChildItemInitInfo.piPropIDs) {
  2848. delete [] m_ChildItemInitInfo.piPropIDs;
  2849. m_ChildItemInitInfo.piPropIDs = NULL;
  2850. }
  2851. if (NULL != m_ChildItemInitInfo.pvPropVars) {
  2852. for (LONG lPropIndex = 0; lPropIndex < m_ChildItemInitInfo.lNumProps; lPropIndex++) {
  2853. //
  2854. // set CLSID pointers to NULL, because we freed the memory above.
  2855. // If this pointer is not NULL FreePropVariantArray would
  2856. // try to free it again.
  2857. //
  2858. if (m_ChildItemInitInfo.pvPropVars[lPropIndex].vt == VT_CLSID) {
  2859. m_ChildItemInitInfo.pvPropVars[lPropIndex].puuid = NULL;
  2860. }
  2861. }
  2862. FreePropVariantArray(m_ChildItemInitInfo.lNumProps,m_ChildItemInitInfo.pvPropVars);
  2863. delete [] m_ChildItemInitInfo.pvPropVars;
  2864. m_ChildItemInitInfo.pvPropVars = NULL;
  2865. }
  2866. if (NULL != m_ChildItemInitInfo.psPropSpec) {
  2867. delete [] m_ChildItemInitInfo.psPropSpec;
  2868. m_ChildItemInitInfo.psPropSpec = NULL;
  2869. }
  2870. if (NULL != m_ChildItemInitInfo.pwpiPropInfo) {
  2871. delete [] m_ChildItemInitInfo.pwpiPropInfo;
  2872. m_ChildItemInitInfo.pwpiPropInfo = NULL;
  2873. }
  2874. m_ChildItemInitInfo.lNumProps = 0;
  2875. return hr;
  2876. }
  2877. /**************************************************************************\
  2878. * BuildChlidItemProperties
  2879. *
  2880. * This helper creates/initializes the arrays used for Property intialization.
  2881. *
  2882. * Arguments:
  2883. *
  2884. * none
  2885. *
  2886. * Return Value:
  2887. *
  2888. * Status
  2889. *
  2890. * History:
  2891. *
  2892. * 03/05/2002 Original Version
  2893. *
  2894. \**************************************************************************/
  2895. HRESULT CWIADevice::BuildChildItemProperties()
  2896. {
  2897. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  2898. WIALOG_NO_RESOURCE_ID,
  2899. WIALOG_LEVEL1,
  2900. "CWIADevice::BuildChildItemProperties");
  2901. HRESULT hr = S_OK;
  2902. m_ChildItemInitInfo.lNumProps = 29;
  2903. m_ChildItemInitInfo.pszPropNames = new LPOLESTR[m_ChildItemInitInfo.lNumProps];
  2904. if (NULL != m_ChildItemInitInfo.pszPropNames) {
  2905. m_ChildItemInitInfo.piPropIDs = new PROPID[m_ChildItemInitInfo.lNumProps];
  2906. if (NULL != m_ChildItemInitInfo.piPropIDs) {
  2907. m_ChildItemInitInfo.pvPropVars = new PROPVARIANT[m_ChildItemInitInfo.lNumProps];
  2908. if (NULL != m_ChildItemInitInfo.pvPropVars) {
  2909. m_ChildItemInitInfo.psPropSpec = new PROPSPEC[m_ChildItemInitInfo.lNumProps];
  2910. if (NULL != m_ChildItemInitInfo.psPropSpec) {
  2911. m_ChildItemInitInfo.pwpiPropInfo = new WIA_PROPERTY_INFO[m_ChildItemInitInfo.lNumProps];
  2912. if (NULL == m_ChildItemInitInfo.pwpiPropInfo)
  2913. hr = E_OUTOFMEMORY;
  2914. } else
  2915. hr = E_OUTOFMEMORY;
  2916. } else
  2917. hr = E_OUTOFMEMORY;
  2918. } else
  2919. hr = E_OUTOFMEMORY;
  2920. } else
  2921. hr = E_OUTOFMEMORY;
  2922. if (FAILED(hr)) {
  2923. DeleteChildItemProperties();
  2924. return hr;
  2925. }
  2926. ROOT_ITEM_INFORMATION RootItemInfo;
  2927. hr = m_pScanAPI->FakeScanner_GetRootPropertyInfo(&RootItemInfo);
  2928. if (FAILED(hr)) {
  2929. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildChildItemProperties, FakeScanner_GetRootPropertyInfo failed"));
  2930. WIAS_LHRESULT(m_pIWiaLog, hr);
  2931. DeleteChildItemProperties();
  2932. return hr;
  2933. }
  2934. TOP_ITEM_INFORMATION TopItemInfo;
  2935. hr = m_pScanAPI->FakeScanner_GetTopPropertyInfo(&TopItemInfo);
  2936. if (FAILED(hr)) {
  2937. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildChildItemProperties, FakeScanner_GetTopPropertyInfo failed"));
  2938. WIAS_LHRESULT(m_pIWiaLog, hr);
  2939. DeleteChildItemProperties();
  2940. return hr;
  2941. }
  2942. LONG PropIndex = 0;
  2943. // Intialize WIA_IPS_XRES (LIST)
  2944. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_XRES_STR;
  2945. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_XRES;
  2946. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = m_SupportedResolutions.plValues[0];
  2947. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2948. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2949. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  2950. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  2951. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  2952. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList= (BYTE*)m_SupportedResolutions.plValues;
  2953. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  2954. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedResolutions.lNumValues;
  2955. PropIndex++;
  2956. // Intialize WIA_IPS_YRES (LIST)
  2957. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_YRES_STR;
  2958. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_YRES;
  2959. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = m_SupportedResolutions.plValues[0];
  2960. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2961. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2962. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  2963. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  2964. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  2965. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList= (BYTE*)m_SupportedResolutions.plValues;
  2966. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  2967. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedResolutions.lNumValues;
  2968. PropIndex++;
  2969. // Intialize WIA_IPS_XEXTENT (RANGE)
  2970. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_XEXTENT_STR;
  2971. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_XEXTENT;
  2972. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = ((m_ChildItemInitInfo.pvPropVars [PropIndex-2].lVal * RootItemInfo.ScanBedWidth)/1000);
  2973. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2974. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2975. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  2976. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  2977. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  2978. //
  2979. // scanners that have a fixed width should set the valid values for WIA_IPS_XEXTENT to reflect that.
  2980. // This will let the application know that this device has this behavior.
  2981. //
  2982. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  2983. #else
  2984. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  2985. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = 1;
  2986. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 1;
  2987. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  2988. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  2989. #endif
  2990. PropIndex++;
  2991. // Intialize WIA_IPS_YEXTENT (RANGE)
  2992. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_YEXTENT_STR;
  2993. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_YEXTENT;
  2994. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  2995. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  2996. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  2997. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  2998. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  2999. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = ((m_ChildItemInitInfo.pvPropVars [PropIndex-2].lVal * RootItemInfo.ScanBedHeight)/1000);
  3000. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = 1;
  3001. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 1;
  3002. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3003. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3004. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3005. //
  3006. // scanners that have a feeder that can not determine the length of the page, should
  3007. // have 0 as the valid values for WIA_IPS_YEXTENT. This will let the application
  3008. // know that this device has this behavior.
  3009. //
  3010. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  3011. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  3012. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = 0;
  3013. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = 0;
  3014. #endif
  3015. PropIndex++;
  3016. // Intialize WIA_IPS_XPOS (RANGE)
  3017. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_XPOS_STR;
  3018. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_XPOS;
  3019. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  3020. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3021. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3022. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3023. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  3024. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3025. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = 1;
  3026. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  3027. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = (m_ChildItemInitInfo.pwpiPropInfo[PropIndex-2].ValidVal.Range.Max - 1);
  3028. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3029. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3030. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  3031. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = 0;
  3032. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = 0;
  3033. #endif
  3034. PropIndex++;
  3035. // Intialize WIA_IPS_YPOS (RANGE)
  3036. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_YPOS_STR;
  3037. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_YPOS;
  3038. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  3039. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3040. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3041. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3042. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  3043. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3044. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = 1;
  3045. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  3046. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = (m_ChildItemInitInfo.pwpiPropInfo[PropIndex-2].ValidVal.Range.Max - 1);
  3047. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3048. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3049. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = 0;
  3050. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = 0;
  3051. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = 0;
  3052. #endif
  3053. PropIndex++;
  3054. // Intialize WIA_IPA_DATATYPE (LIST)
  3055. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_DATATYPE_STR;
  3056. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_DATATYPE;
  3057. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_DATATYPE;
  3058. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3059. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3060. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3061. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  3062. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3063. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList = (BYTE*)m_SupportedDataTypes.plValues;
  3064. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3065. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedDataTypes.lNumValues;
  3066. PropIndex++;
  3067. // Intialize WIA_IPA_DEPTH (NONE)
  3068. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_DEPTH_STR;
  3069. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_DEPTH;
  3070. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_BITDEPTH;
  3071. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3072. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3073. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3074. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3075. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3076. PropIndex++;
  3077. // Intialize WIA_IPS_BRIGHTNESS (RANGE)
  3078. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_BRIGHTNESS_STR;
  3079. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_BRIGHTNESS;
  3080. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = TopItemInfo.Brightness.lNom;
  3081. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3082. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3083. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3084. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  3085. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3086. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = TopItemInfo.Brightness.lInc;
  3087. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = TopItemInfo.Brightness.lMin;
  3088. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = TopItemInfo.Brightness.lMax;
  3089. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = TopItemInfo.Brightness.lNom;
  3090. PropIndex++;
  3091. // Intialize WIA_IPS_CONTRAST (RANGE)
  3092. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_CONTRAST_STR;
  3093. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_CONTRAST;
  3094. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = TopItemInfo.Contrast.lNom;
  3095. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3096. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3097. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3098. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  3099. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3100. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = TopItemInfo.Contrast.lInc;
  3101. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = TopItemInfo.Contrast.lMin;
  3102. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = TopItemInfo.Contrast.lMax;
  3103. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = TopItemInfo.Contrast.lNom;
  3104. PropIndex++;
  3105. // Intialize WIA_IPS_CUR_INTENT (FLAG)
  3106. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_CUR_INTENT_STR;
  3107. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_CUR_INTENT;
  3108. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = WIA_INTENT_NONE;
  3109. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3110. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3111. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3112. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_FLAG;
  3113. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3114. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3115. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.ValidBits = WIA_INTENT_IMAGE_TYPE_COLOR | WIA_INTENT_IMAGE_TYPE_GRAYSCALE |
  3116. WIA_INTENT_IMAGE_TYPE_TEXT | WIA_INTENT_MINIMIZE_SIZE |
  3117. WIA_INTENT_MAXIMIZE_QUALITY;
  3118. PropIndex++;
  3119. // Intialize WIA_IPA_PIXELS_PER_LINE (NONE)
  3120. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_PIXELS_PER_LINE_STR;
  3121. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_PIXELS_PER_LINE;
  3122. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = m_ChildItemInitInfo.pvPropVars [PropIndex-9].lVal;
  3123. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3124. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3125. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3126. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3127. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3128. PropIndex++;
  3129. // Intialize WIA_IPA_NUMER_OF_LINES (NONE)
  3130. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_NUMBER_OF_LINES_STR;
  3131. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_NUMBER_OF_LINES;
  3132. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = m_ChildItemInitInfo.pvPropVars [PropIndex-9].lVal;
  3133. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3134. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3135. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3136. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3137. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3138. PropIndex++;
  3139. // Intialize WIA_IPA_PREFERRED_FORMAT (NONE)
  3140. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_PREFERRED_FORMAT_STR;
  3141. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_PREFERRED_FORMAT;
  3142. m_ChildItemInitInfo.pvPropVars [PropIndex].puuid = &m_pInitialFormats[0];
  3143. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_CLSID;
  3144. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3145. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3146. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3147. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3148. PropIndex++;
  3149. // Intialize WIA_IPA_ITEM_SIZE (NONE)
  3150. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_ITEM_SIZE_STR;
  3151. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_ITEM_SIZE;
  3152. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  3153. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3154. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3155. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3156. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3157. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3158. PropIndex++;
  3159. // Intialize WIA_IPS_THRESHOLD (RANGE)
  3160. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_THRESHOLD_STR;
  3161. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_THRESHOLD;
  3162. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = TopItemInfo.Threshold.lNom;
  3163. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3164. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3165. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3166. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_RANGE;
  3167. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3168. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Inc = TopItemInfo.Threshold.lInc;
  3169. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Min = TopItemInfo.Threshold.lMin;
  3170. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Max = TopItemInfo.Threshold.lMax;
  3171. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Range.Nom = TopItemInfo.Threshold.lNom;
  3172. PropIndex++;
  3173. // Intialize WIA_IPA_FORMAT (LIST)
  3174. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_FORMAT_STR;
  3175. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_FORMAT;
  3176. m_ChildItemInitInfo.pvPropVars [PropIndex].puuid = &m_pInitialFormats[0];
  3177. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_CLSID;
  3178. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3179. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3180. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  3181. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3182. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.ListGuid.pList = m_pInitialFormats;
  3183. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.ListGuid.Nom = *m_ChildItemInitInfo.pvPropVars[PropIndex].puuid;
  3184. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.ListGuid.cNumList = m_NumInitialFormats;
  3185. PropIndex++;
  3186. // Intialize WIA_IPA_FILENAME_EXTENSION (NONE)
  3187. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_FILENAME_EXTENSION_STR;
  3188. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_FILENAME_EXTENSION;
  3189. m_ChildItemInitInfo.pvPropVars [PropIndex].bstrVal = SysAllocString(L"BMP");
  3190. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_BSTR;
  3191. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3192. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3193. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3194. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3195. PropIndex++;
  3196. // Intialize WIA_IPA_TYMED (LIST)
  3197. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_TYMED_STR;
  3198. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_TYMED;
  3199. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_TYMED;
  3200. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3201. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3202. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3203. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  3204. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3205. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList = (BYTE*)m_SupportedTYMED.plValues;
  3206. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3207. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedTYMED.lNumValues;
  3208. PropIndex++;
  3209. // Intialize WIA_IPA_CHANNELS_PER_PIXEL (NONE)
  3210. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_CHANNELS_PER_PIXEL_STR;
  3211. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_CHANNELS_PER_PIXEL;
  3212. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_CHANNELS_PER_PIXEL;
  3213. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3214. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3215. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3216. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3217. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3218. PropIndex++;
  3219. // Intialize WIA_IPA_BITS_PER_CHANNEL (NONE)
  3220. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_BITS_PER_CHANNEL_STR;
  3221. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_BITS_PER_CHANNEL;
  3222. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_BITS_PER_CHANNEL;
  3223. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3224. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3225. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3226. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3227. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3228. PropIndex++;
  3229. // Intialize WIA_IPA_PLANAR (NONE)
  3230. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_PLANAR_STR;
  3231. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_PLANAR;
  3232. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_PLANAR;
  3233. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3234. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3235. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3236. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3237. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3238. PropIndex++;
  3239. // Intialize WIA_IPA_BYTES_PER_LINE (NONE)
  3240. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_BYTES_PER_LINE_STR;
  3241. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_BYTES_PER_LINE;
  3242. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = 0;
  3243. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3244. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3245. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3246. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3247. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3248. PropIndex++;
  3249. // Intialize WIA_IPA_MIN_BUFFER_SIZE (NONE)
  3250. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_MIN_BUFFER_SIZE_STR;
  3251. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_MIN_BUFFER_SIZE;
  3252. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = TopItemInfo.lMinimumBufferSize;
  3253. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3254. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3255. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3256. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3257. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3258. PropIndex++;
  3259. // Intialize WIA_IPA_ACCESS_RIGHTS (NONE)
  3260. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_ACCESS_RIGHTS_STR;
  3261. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_ACCESS_RIGHTS;
  3262. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = WIA_ITEM_READ|WIA_ITEM_WRITE;
  3263. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3264. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3265. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3266. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3267. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3268. PropIndex++;
  3269. // Intialize WIA_IPA_COMPRESSION (LIST)
  3270. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_COMPRESSION_STR;
  3271. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_COMPRESSION;
  3272. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_COMPRESSION;
  3273. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3274. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3275. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3276. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_RW|WIA_PROP_LIST;
  3277. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3278. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.pList = (BYTE*)m_SupportedCompressionTypes.plValues;
  3279. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3280. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.List.cNumList = m_SupportedCompressionTypes.lNumValues;
  3281. PropIndex++;
  3282. // Initialize WIA_IPA_ITEM_FLAGS
  3283. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPA_ITEM_FLAGS_STR;
  3284. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPA_ITEM_FLAGS;
  3285. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = WiaItemTypeImage|WiaItemTypeFile|WiaItemTypeDevice;
  3286. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3287. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3288. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3289. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_FLAG;
  3290. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3291. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.Nom = m_ChildItemInitInfo.pvPropVars [PropIndex].lVal;
  3292. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].ValidVal.Flag.ValidBits = WiaItemTypeImage|WiaItemTypeFile|WiaItemTypeDevice;
  3293. PropIndex++;
  3294. // Initialize WIA_IPS_PHOTOMETRIC_INTERP
  3295. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_PHOTOMETRIC_INTERP_STR;
  3296. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_PHOTOMETRIC_INTERP;
  3297. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = INITIAL_PHOTOMETRIC_INTERP;
  3298. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3299. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3300. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3301. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3302. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3303. PropIndex++;
  3304. // Intialize WIA_IPS_WARM_UP_TIME_STR (NONE)
  3305. m_ChildItemInitInfo.pszPropNames[PropIndex] = WIA_IPS_WARM_UP_TIME_STR;
  3306. m_ChildItemInitInfo.piPropIDs [PropIndex] = WIA_IPS_WARM_UP_TIME;
  3307. m_ChildItemInitInfo.pvPropVars [PropIndex].lVal = TopItemInfo.lMaxLampWarmupTime;
  3308. m_ChildItemInitInfo.pvPropVars [PropIndex].vt = VT_I4;
  3309. m_ChildItemInitInfo.psPropSpec [PropIndex].ulKind = PRSPEC_PROPID;
  3310. m_ChildItemInitInfo.psPropSpec [PropIndex].propid = m_ChildItemInitInfo.piPropIDs [PropIndex];
  3311. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].lAccessFlags = WIA_PROP_READ|WIA_PROP_NONE;
  3312. m_ChildItemInitInfo.pwpiPropInfo[PropIndex].vt = m_ChildItemInitInfo.pvPropVars [PropIndex].vt;
  3313. PropIndex++;
  3314. return hr;
  3315. }
  3316. /**************************************************************************\
  3317. * BuildSupportedResolutions
  3318. *
  3319. * This helper initializes the supported resolution array
  3320. *
  3321. * Arguments:
  3322. *
  3323. * none
  3324. *
  3325. * Return Value:
  3326. *
  3327. * Status
  3328. *
  3329. * History:
  3330. *
  3331. * 03/05/2002 Original Version
  3332. *
  3333. \**************************************************************************/
  3334. HRESULT CWIADevice::BuildSupportedResolutions()
  3335. {
  3336. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3337. WIALOG_NO_RESOURCE_ID,
  3338. WIALOG_LEVEL1,
  3339. "CWIADevice::BuildSupportedResolutions");
  3340. HRESULT hr = S_OK;
  3341. if (NULL != m_SupportedResolutions.plValues) {
  3342. //
  3343. // Supported resolutions have already been initialized,
  3344. // so return S_OK.
  3345. //
  3346. return hr;
  3347. }
  3348. m_SupportedResolutions.lNumValues = 6;
  3349. m_SupportedResolutions.plValues = new LONG[m_SupportedResolutions.lNumValues];
  3350. if (m_SupportedResolutions.plValues) {
  3351. m_SupportedResolutions.plValues[0] = 75;
  3352. m_SupportedResolutions.plValues[1] = 100;
  3353. m_SupportedResolutions.plValues[2] = 150;
  3354. m_SupportedResolutions.plValues[3] = 200;
  3355. m_SupportedResolutions.plValues[4] = 300;
  3356. m_SupportedResolutions.plValues[5] = 600;
  3357. } else
  3358. hr = E_OUTOFMEMORY;
  3359. return hr;
  3360. }
  3361. /**************************************************************************\
  3362. * DeleteSupportedResolutionsArrayContents
  3363. *
  3364. * This helper deletes the supported resolutions array
  3365. *
  3366. * Arguments:
  3367. *
  3368. * none
  3369. *
  3370. * Return Value:
  3371. *
  3372. * Status
  3373. *
  3374. * History:
  3375. *
  3376. * 03/05/2002 Original Version
  3377. *
  3378. \**************************************************************************/
  3379. HRESULT CWIADevice::DeleteSupportedResolutionsArrayContents()
  3380. {
  3381. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3382. WIALOG_NO_RESOURCE_ID,
  3383. WIALOG_LEVEL1,
  3384. "CWIADevice::DeleteSupportedResolutionsArrayContents");
  3385. HRESULT hr = S_OK;
  3386. if (NULL != m_SupportedResolutions.plValues)
  3387. delete [] m_SupportedResolutions.plValues;
  3388. m_SupportedResolutions.plValues = NULL;
  3389. m_SupportedResolutions.lNumValues = 0;
  3390. return hr;
  3391. }
  3392. /**************************************************************************\
  3393. * BuildSupportedIntents
  3394. *
  3395. * This helper initializes the supported intent array
  3396. *
  3397. * Arguments:
  3398. *
  3399. * none
  3400. *
  3401. * Return Value:
  3402. *
  3403. * Status
  3404. *
  3405. * History:
  3406. *
  3407. * 03/05/2002 Original Version
  3408. *
  3409. \**************************************************************************/
  3410. HRESULT CWIADevice::BuildSupportedIntents()
  3411. {
  3412. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3413. WIALOG_NO_RESOURCE_ID,
  3414. WIALOG_LEVEL1,
  3415. "CWIADevice::BuildSupportedIntents");
  3416. HRESULT hr = S_OK;
  3417. if (NULL != m_SupportedIntents.plValues) {
  3418. //
  3419. // Supported intents have already been initialized,
  3420. // so return S_OK.
  3421. //
  3422. return hr;
  3423. }
  3424. m_SupportedIntents.lNumValues = 6;
  3425. m_SupportedIntents.plValues = new LONG[m_SupportedIntents.lNumValues];
  3426. if (m_SupportedIntents.plValues) {
  3427. m_SupportedIntents.plValues[0] = WIA_INTENT_NONE;
  3428. m_SupportedIntents.plValues[1] = WIA_INTENT_IMAGE_TYPE_COLOR;
  3429. m_SupportedIntents.plValues[2] = WIA_INTENT_IMAGE_TYPE_GRAYSCALE;
  3430. m_SupportedIntents.plValues[3] = WIA_INTENT_IMAGE_TYPE_TEXT;
  3431. m_SupportedIntents.plValues[4] = WIA_INTENT_MINIMIZE_SIZE;
  3432. m_SupportedIntents.plValues[5] = WIA_INTENT_MAXIMIZE_QUALITY;
  3433. } else
  3434. hr = E_OUTOFMEMORY;
  3435. return hr;
  3436. }
  3437. /**************************************************************************\
  3438. * DeleteSupportedIntentsArrayContents
  3439. *
  3440. * This helper deletes the supported intent array
  3441. *
  3442. * Arguments:
  3443. *
  3444. * none
  3445. *
  3446. * Return Value:
  3447. *
  3448. * Status
  3449. *
  3450. * History:
  3451. *
  3452. * 03/05/2002 Original Version
  3453. *
  3454. \**************************************************************************/
  3455. HRESULT CWIADevice::DeleteSupportedIntentsArrayContents()
  3456. {
  3457. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3458. WIALOG_NO_RESOURCE_ID,
  3459. WIALOG_LEVEL1,
  3460. "CWIADevice::DeleteSupportedIntentsArrayContents");
  3461. HRESULT hr = S_OK;
  3462. if (NULL != m_SupportedIntents.plValues)
  3463. delete [] m_SupportedIntents.plValues;
  3464. m_SupportedIntents.plValues = NULL;
  3465. m_SupportedIntents.lNumValues = 0;
  3466. return hr;
  3467. }
  3468. /**************************************************************************\
  3469. * BuildSupportedCompressions
  3470. *
  3471. * This helper initializes the supported compression types array
  3472. *
  3473. * Arguments:
  3474. *
  3475. * none
  3476. *
  3477. * Return Value:
  3478. *
  3479. * Status
  3480. *
  3481. * History:
  3482. *
  3483. * 03/05/2002 Original Version
  3484. *
  3485. \**************************************************************************/
  3486. HRESULT CWIADevice::BuildSupportedCompressions()
  3487. {
  3488. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3489. WIALOG_NO_RESOURCE_ID,
  3490. WIALOG_LEVEL1,
  3491. "CWIADevice::BuildSupportedCompressions");
  3492. HRESULT hr = S_OK;
  3493. if (NULL != m_SupportedCompressionTypes.plValues) {
  3494. //
  3495. // Supported compression types have already been initialized,
  3496. // so return S_OK.
  3497. //
  3498. return hr;
  3499. }
  3500. m_SupportedCompressionTypes.lNumValues = 1;
  3501. m_SupportedCompressionTypes.plValues = new LONG[m_SupportedCompressionTypes.lNumValues];
  3502. if (m_SupportedCompressionTypes.plValues) {
  3503. m_SupportedCompressionTypes.plValues[0] = WIA_COMPRESSION_NONE;
  3504. } else
  3505. hr = E_OUTOFMEMORY;
  3506. return hr;
  3507. }
  3508. /**************************************************************************\
  3509. * DeleteSupportedCompressionsArrayContents
  3510. *
  3511. * This helper deletes the supported compression types array
  3512. *
  3513. * Arguments:
  3514. *
  3515. * none
  3516. *
  3517. * Return Value:
  3518. *
  3519. * Status
  3520. *
  3521. * History:
  3522. *
  3523. * 03/05/2002 Original Version
  3524. *
  3525. \**************************************************************************/
  3526. HRESULT CWIADevice::DeleteSupportedCompressionsArrayContents()
  3527. {
  3528. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3529. WIALOG_NO_RESOURCE_ID,
  3530. WIALOG_LEVEL1,
  3531. "CWIADevice::DeleteSupportedCompressionsArrayContents");
  3532. HRESULT hr = S_OK;
  3533. if (NULL != m_SupportedCompressionTypes.plValues)
  3534. delete [] m_SupportedCompressionTypes.plValues;
  3535. m_SupportedCompressionTypes.plValues = NULL;
  3536. m_SupportedCompressionTypes.lNumValues = 0;
  3537. return hr;
  3538. }
  3539. /**************************************************************************\
  3540. * BuildSupportedPreviewModes
  3541. *
  3542. * This helper initializes the supported preview mode array
  3543. *
  3544. * Arguments:
  3545. *
  3546. * none
  3547. *
  3548. * Return Value:
  3549. *
  3550. * Status
  3551. *
  3552. * History:
  3553. *
  3554. * 03/05/2002 Original Version
  3555. *
  3556. \**************************************************************************/
  3557. HRESULT CWIADevice::BuildSupportedPreviewModes()
  3558. {
  3559. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3560. WIALOG_NO_RESOURCE_ID,
  3561. WIALOG_LEVEL1,
  3562. "CWIADevice::BuildSupportedPreviewModes");
  3563. HRESULT hr = S_OK;
  3564. if (NULL != m_SupportedPreviewModes.plValues) {
  3565. //
  3566. // Supported preview modes have already been initialized,
  3567. // so return S_OK.
  3568. //
  3569. return hr;
  3570. }
  3571. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3572. //
  3573. // if your scanner can not perform a preview scan, then
  3574. // set the valid values for WIA_DPS_PREVIEW property to
  3575. // WIA_FINAL_SCAN only
  3576. //
  3577. m_SupportedPreviewModes.lNumValues = 1;
  3578. m_SupportedPreviewModes.plValues = new LONG[m_SupportedPreviewModes.lNumValues];
  3579. if (m_SupportedPreviewModes.plValues) {
  3580. m_SupportedPreviewModes.plValues[0] = WIA_FINAL_SCAN;
  3581. } else
  3582. hr = E_OUTOFMEMORY;
  3583. #else
  3584. m_SupportedPreviewModes.lNumValues = 2;
  3585. m_SupportedPreviewModes.plValues = new LONG[m_SupportedPreviewModes.lNumValues];
  3586. if (m_SupportedPreviewModes.plValues) {
  3587. m_SupportedPreviewModes.plValues[0] = WIA_FINAL_SCAN;
  3588. m_SupportedPreviewModes.plValues[1] = WIA_PREVIEW_SCAN;
  3589. } else
  3590. hr = E_OUTOFMEMORY;
  3591. #endif
  3592. return hr;
  3593. }
  3594. /**************************************************************************\
  3595. * DeleteSupportedCompressionsArrayContents
  3596. *
  3597. * This helper deletes the supported compression types array
  3598. *
  3599. * Arguments:
  3600. *
  3601. * none
  3602. *
  3603. * Return Value:
  3604. *
  3605. * Status
  3606. *
  3607. * History:
  3608. *
  3609. * 03/05/2002 Original Version
  3610. *
  3611. \**************************************************************************/
  3612. HRESULT CWIADevice::DeleteSupportedPreviewModesArrayContents()
  3613. {
  3614. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3615. WIALOG_NO_RESOURCE_ID,
  3616. WIALOG_LEVEL1,
  3617. "CWIADevice::DeleteSupportedPreviewModesArrayContents");
  3618. HRESULT hr = S_OK;
  3619. if (NULL != m_SupportedPreviewModes.plValues)
  3620. delete [] m_SupportedPreviewModes.plValues;
  3621. m_SupportedPreviewModes.plValues = NULL;
  3622. m_SupportedPreviewModes.lNumValues = 0;
  3623. return hr;
  3624. }
  3625. /**************************************************************************\
  3626. * BuildSupportedDataTypes
  3627. *
  3628. * This helper initializes the supported data types array
  3629. *
  3630. * Arguments:
  3631. *
  3632. * none
  3633. *
  3634. * Return Value:
  3635. *
  3636. * Status
  3637. *
  3638. * History:
  3639. *
  3640. * 03/05/2002 Original Version
  3641. *
  3642. \**************************************************************************/
  3643. HRESULT CWIADevice::BuildSupportedDataTypes()
  3644. {
  3645. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3646. WIALOG_NO_RESOURCE_ID,
  3647. WIALOG_LEVEL1,
  3648. "CWIADevice::BuildSupportedDataTypes");
  3649. HRESULT hr = S_OK;
  3650. if (NULL != m_SupportedDataTypes.plValues) {
  3651. //
  3652. // Supported data types have already been initialized,
  3653. // so return S_OK.
  3654. //
  3655. return hr;
  3656. }
  3657. m_SupportedDataTypes.lNumValues = 3;
  3658. m_SupportedDataTypes.plValues = new LONG[m_SupportedDataTypes.lNumValues];
  3659. if (m_SupportedDataTypes.plValues) {
  3660. m_SupportedDataTypes.plValues[0] = WIA_DATA_THRESHOLD;
  3661. m_SupportedDataTypes.plValues[1] = WIA_DATA_GRAYSCALE;
  3662. m_SupportedDataTypes.plValues[2] = WIA_DATA_COLOR;
  3663. } else
  3664. hr = E_OUTOFMEMORY;
  3665. return hr;
  3666. }
  3667. /**************************************************************************\
  3668. * DeleteSupportedDataTypesArrayContents
  3669. *
  3670. * This helper deletes the supported data types array
  3671. *
  3672. * Arguments:
  3673. *
  3674. * none
  3675. *
  3676. * Return Value:
  3677. *
  3678. * Status
  3679. *
  3680. * History:
  3681. *
  3682. * 03/05/2002 Original Version
  3683. *
  3684. \**************************************************************************/
  3685. HRESULT CWIADevice::DeleteSupportedDataTypesArrayContents()
  3686. {
  3687. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3688. WIALOG_NO_RESOURCE_ID,
  3689. WIALOG_LEVEL1,
  3690. "CWIADevice::DeleteSupportedDataTypesArrayContents");
  3691. HRESULT hr = S_OK;
  3692. if (NULL != m_SupportedDataTypes.plValues)
  3693. delete [] m_SupportedDataTypes.plValues;
  3694. m_SupportedDataTypes.plValues = NULL;
  3695. m_SupportedDataTypes.lNumValues = 0;
  3696. return hr;
  3697. }
  3698. /**************************************************************************\
  3699. * BuildInitialFormats
  3700. *
  3701. * This helper initializes the initial format array
  3702. *
  3703. * Arguments:
  3704. *
  3705. * none
  3706. *
  3707. * Return Value:
  3708. *
  3709. * Status
  3710. *
  3711. * History:
  3712. *
  3713. * 03/05/2002 Original Version
  3714. *
  3715. \**************************************************************************/
  3716. HRESULT CWIADevice::BuildInitialFormats()
  3717. {
  3718. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3719. WIALOG_NO_RESOURCE_ID,
  3720. WIALOG_LEVEL1,
  3721. "CWIADevice::BuildInitialFormats");
  3722. HRESULT hr = S_OK;
  3723. if (NULL != m_pInitialFormats) {
  3724. //
  3725. // Supported initial formats have already been initialized,
  3726. // so return S_OK.
  3727. //
  3728. return hr;
  3729. }
  3730. m_NumInitialFormats = 1;
  3731. m_pInitialFormats = new GUID[m_NumInitialFormats];
  3732. if (m_pInitialFormats) {
  3733. m_pInitialFormats[0] = WiaImgFmt_MEMORYBMP;
  3734. } else
  3735. hr = E_OUTOFMEMORY;
  3736. return hr;
  3737. }
  3738. /**************************************************************************\
  3739. * DeleteInitialFormatsArrayContents
  3740. *
  3741. * This helper deletes the initial format array
  3742. *
  3743. * Arguments:
  3744. *
  3745. * none
  3746. *
  3747. * Return Value:
  3748. *
  3749. * Status
  3750. *
  3751. * History:
  3752. *
  3753. * 03/05/2002 Original Version
  3754. *
  3755. \**************************************************************************/
  3756. HRESULT CWIADevice::DeleteInitialFormatsArrayContents()
  3757. {
  3758. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3759. WIALOG_NO_RESOURCE_ID,
  3760. WIALOG_LEVEL1,
  3761. "CWIADevice::DeleteInitialFormatsArrayContents");
  3762. HRESULT hr = S_OK;
  3763. if (NULL != m_pInitialFormats)
  3764. delete [] m_pInitialFormats;
  3765. m_pInitialFormats = NULL;
  3766. m_NumInitialFormats = 0;
  3767. return hr;
  3768. }
  3769. /**************************************************************************\
  3770. * BuildSupportedFormats
  3771. *
  3772. * This helper initializes the supported format array
  3773. *
  3774. * Arguments:
  3775. *
  3776. * none
  3777. *
  3778. * Return Value:
  3779. *
  3780. * Status
  3781. *
  3782. * History:
  3783. *
  3784. * 03/05/2002 Original Version
  3785. *
  3786. \**************************************************************************/
  3787. HRESULT CWIADevice::BuildSupportedFormats()
  3788. {
  3789. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3790. WIALOG_NO_RESOURCE_ID,
  3791. WIALOG_LEVEL1,
  3792. "CWIADevice::BuildSupportedFormats");
  3793. HRESULT hr = S_OK;
  3794. if (NULL != m_pSupportedFormats) {
  3795. //
  3796. // Supported formats have already been initialized,
  3797. // so return S_OK.
  3798. //
  3799. return hr;
  3800. }
  3801. hr = DeleteSupportedFormatsArrayContents();
  3802. if (SUCCEEDED(hr)) {
  3803. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3804. //
  3805. // the unknown length feeder only scanner, formally called the scrollfed scanner
  3806. // only supports BMP and MEMORYBMP
  3807. //
  3808. m_NumSupportedFormats = 2;
  3809. m_pSupportedFormats = new WIA_FORMAT_INFO[m_NumSupportedFormats];
  3810. if (m_pSupportedFormats) {
  3811. m_pSupportedFormats[0].guidFormatID = WiaImgFmt_MEMORYBMP;
  3812. m_pSupportedFormats[0].lTymed = TYMED_CALLBACK;
  3813. m_pSupportedFormats[1].guidFormatID = WiaImgFmt_BMP;
  3814. m_pSupportedFormats[1].lTymed = TYMED_FILE;
  3815. } else
  3816. hr = E_OUTOFMEMORY;
  3817. #else // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3818. m_NumSupportedFormats = 4;
  3819. m_pSupportedFormats = new WIA_FORMAT_INFO[m_NumSupportedFormats];
  3820. if (m_pSupportedFormats) {
  3821. m_pSupportedFormats[0].guidFormatID = WiaImgFmt_MEMORYBMP;
  3822. m_pSupportedFormats[0].lTymed = TYMED_CALLBACK;
  3823. m_pSupportedFormats[1].guidFormatID = WiaImgFmt_BMP;
  3824. m_pSupportedFormats[1].lTymed = TYMED_FILE;
  3825. m_pSupportedFormats[2].guidFormatID = WiaImgFmt_TIFF;
  3826. m_pSupportedFormats[2].lTymed = TYMED_FILE;
  3827. m_pSupportedFormats[3].guidFormatID = WiaImgFmt_TIFF;
  3828. m_pSupportedFormats[3].lTymed = TYMED_MULTIPAGE_CALLBACK;
  3829. } else
  3830. hr = E_OUTOFMEMORY;
  3831. #endif // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3832. }
  3833. return hr;
  3834. }
  3835. /**************************************************************************\
  3836. * DeleteSupportedFormatsArrayContents
  3837. *
  3838. * This helper deletes the supported formats array
  3839. *
  3840. * Arguments:
  3841. *
  3842. * none
  3843. *
  3844. * Return Value:
  3845. *
  3846. * Status
  3847. *
  3848. * History:
  3849. *
  3850. * 03/05/2002 Original Version
  3851. *
  3852. \**************************************************************************/
  3853. HRESULT CWIADevice::DeleteSupportedFormatsArrayContents()
  3854. {
  3855. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3856. WIALOG_NO_RESOURCE_ID,
  3857. WIALOG_LEVEL1,
  3858. "CWIADevice::DeleteSupportedFormatsArrayContents");
  3859. HRESULT hr = S_OK;
  3860. if (NULL != m_pSupportedFormats)
  3861. delete [] m_pSupportedFormats;
  3862. m_pSupportedFormats = NULL;
  3863. m_NumSupportedFormats = 0;
  3864. return hr;
  3865. }
  3866. /**************************************************************************\
  3867. * BuildSupportedTYMED
  3868. *
  3869. * This helper initializes the supported TYMED array
  3870. *
  3871. * Arguments:
  3872. *
  3873. * none
  3874. *
  3875. * Return Value:
  3876. *
  3877. * Status
  3878. *
  3879. * History:
  3880. *
  3881. * 03/05/2002 Original Version
  3882. *
  3883. \**************************************************************************/
  3884. HRESULT CWIADevice::BuildSupportedTYMED()
  3885. {
  3886. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3887. WIALOG_NO_RESOURCE_ID,
  3888. WIALOG_LEVEL1,
  3889. "CWIADevice::BuildSupportedTYMED");
  3890. HRESULT hr = S_OK;
  3891. if (NULL != m_SupportedTYMED.plValues) {
  3892. //
  3893. // Supported TYMED have already been initialized,
  3894. // so return S_OK.
  3895. //
  3896. return hr;
  3897. }
  3898. hr = DeleteSupportedTYMEDArrayContents();
  3899. if (SUCCEEDED(hr)) {
  3900. #ifdef UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3901. //
  3902. // if your scanner does not support multi-page
  3903. // file formats, then only report TYMED_FILE, and
  3904. // TYMED_CALLBACK for the WIA_IPA_TYMED property.
  3905. // The unknown length feeder only scanner, formally called
  3906. // the scrollfed scanner in this example does not support
  3907. // multipage file formats
  3908. //
  3909. m_SupportedTYMED.lNumValues = 2;
  3910. m_SupportedTYMED.plValues = new LONG[m_SupportedTYMED.lNumValues];
  3911. if (m_SupportedTYMED.plValues) {
  3912. m_SupportedTYMED.plValues[0] = TYMED_FILE;
  3913. m_SupportedTYMED.plValues[1] = TYMED_CALLBACK;
  3914. } else
  3915. hr = E_OUTOFMEMORY;
  3916. #else // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3917. m_SupportedTYMED.lNumValues = 3;
  3918. m_SupportedTYMED.plValues = new LONG[m_SupportedTYMED.lNumValues];
  3919. if (m_SupportedTYMED.plValues) {
  3920. m_SupportedTYMED.plValues[0] = TYMED_FILE;
  3921. m_SupportedTYMED.plValues[1] = TYMED_CALLBACK;
  3922. m_SupportedTYMED.plValues[2] = TYMED_MULTIPAGE_CALLBACK;
  3923. } else
  3924. hr = E_OUTOFMEMORY;
  3925. #endif // UNKNOWN_LENGTH_FEEDER_ONLY_SCANNER
  3926. }
  3927. return hr;
  3928. }
  3929. /**************************************************************************\
  3930. * DeleteSupportedTYMEDArrayContents
  3931. *
  3932. * This helper deletes the supported TYMED array
  3933. *
  3934. * Arguments:
  3935. *
  3936. * none
  3937. *
  3938. * Return Value:
  3939. *
  3940. * Status
  3941. *
  3942. * History:
  3943. *
  3944. * 03/05/2002 Original Version
  3945. *
  3946. \**************************************************************************/
  3947. HRESULT CWIADevice::DeleteSupportedTYMEDArrayContents()
  3948. {
  3949. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  3950. WIALOG_NO_RESOURCE_ID,
  3951. WIALOG_LEVEL1,
  3952. "CWIADevice::DeleteSupportedTYMEDArrayContents");
  3953. HRESULT hr = S_OK;
  3954. if (NULL != m_SupportedTYMED.plValues)
  3955. delete [] m_SupportedTYMED.plValues;
  3956. m_SupportedTYMED.plValues = NULL;
  3957. m_SupportedTYMED.lNumValues = 0;
  3958. return hr;
  3959. }
  3960. /**************************************************************************\
  3961. * BuildCapabilities
  3962. *
  3963. * This helper initializes the capabilities array
  3964. *
  3965. * Arguments:
  3966. *
  3967. * none
  3968. *
  3969. * Return Value:
  3970. *
  3971. * Status
  3972. *
  3973. * History:
  3974. *
  3975. * 03/05/2002 Original Version
  3976. *
  3977. \**************************************************************************/
  3978. HRESULT CWIADevice::BuildCapabilities()
  3979. {
  3980. HRESULT hr = S_OK;
  3981. if (NULL != m_pCapabilities) {
  3982. //
  3983. // Capabilities have already been initialized,
  3984. // so return S_OK.
  3985. //
  3986. return hr;
  3987. }
  3988. m_NumSupportedCommands = 1;
  3989. m_NumSupportedEvents = 5;
  3990. LONG lArrayIndex = 0; // increment this value when adding new items to
  3991. // the capabilites array
  3992. m_pCapabilities = new WIA_DEV_CAP_DRV[m_NumSupportedCommands + m_NumSupportedEvents];
  3993. if (m_pCapabilities) {
  3994. //
  3995. // Initialize EVENTS
  3996. //
  3997. // WIA_EVENT_DEVICE_CONNECTED
  3998. GetOLESTRResourceString(IDS_EVENT_DEVICE_CONNECTED_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  3999. GetOLESTRResourceString(IDS_EVENT_DEVICE_CONNECTED_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4000. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_EVENT_DEVICE_CONNECTED;
  4001. m_pCapabilities[lArrayIndex].ulFlags = WIA_NOTIFICATION_EVENT;
  4002. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_DEVICE_CONNECTED;
  4003. lArrayIndex++;
  4004. // WIA_EVENT_DEVICE_DISCONNECTED
  4005. GetOLESTRResourceString(IDS_EVENT_DEVICE_DISCONNECTED_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  4006. GetOLESTRResourceString(IDS_EVENT_DEVICE_DISCONNECTED_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4007. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_EVENT_DEVICE_DISCONNECTED;
  4008. m_pCapabilities[lArrayIndex].ulFlags = WIA_NOTIFICATION_EVENT;
  4009. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_DEVICE_DISCONNECTED;
  4010. lArrayIndex++;
  4011. // FAX BUTTON EVENT
  4012. GetOLESTRResourceString(IDS_EVENT_FAXBUTTON_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  4013. GetOLESTRResourceString(IDS_EVENT_FAXBUTTON_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4014. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_EVENT_SCAN_FAX_IMAGE;
  4015. m_pCapabilities[lArrayIndex].ulFlags = WIA_NOTIFICATION_EVENT | WIA_ACTION_EVENT;
  4016. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_SCAN_BUTTON_PRESS;
  4017. lArrayIndex++;
  4018. // COPY BUTTON EVENT
  4019. GetOLESTRResourceString(IDS_EVENT_COPYBUTTON_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  4020. GetOLESTRResourceString(IDS_EVENT_COPYBUTTON_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4021. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_EVENT_SCAN_PRINT_IMAGE;
  4022. m_pCapabilities[lArrayIndex].ulFlags = WIA_NOTIFICATION_EVENT | WIA_ACTION_EVENT;
  4023. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_SCAN_BUTTON_PRESS;
  4024. lArrayIndex++;
  4025. // SCAN BUTTON EVENT
  4026. GetOLESTRResourceString(IDS_EVENT_SCANBUTTON_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  4027. GetOLESTRResourceString(IDS_EVENT_SCANBUTTON_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4028. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_EVENT_SCAN_IMAGE;
  4029. m_pCapabilities[lArrayIndex].ulFlags = WIA_NOTIFICATION_EVENT | WIA_ACTION_EVENT;
  4030. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_SCAN_BUTTON_PRESS;
  4031. lArrayIndex++;
  4032. //
  4033. // Initialize COMMANDS
  4034. //
  4035. // WIA_CMD_SYNCHRONIZE
  4036. GetOLESTRResourceString(IDS_CMD_SYNCRONIZE_NAME,&(m_pCapabilities[lArrayIndex].wszName),TRUE);
  4037. GetOLESTRResourceString(IDS_CMD_SYNCRONIZE_DESC,&(m_pCapabilities[lArrayIndex].wszDescription),TRUE);
  4038. m_pCapabilities[lArrayIndex].guid = (GUID*)&WIA_CMD_SYNCHRONIZE;
  4039. m_pCapabilities[lArrayIndex].ulFlags = 0;
  4040. m_pCapabilities[lArrayIndex].wszIcon = WIA_ICON_SYNCHRONIZE;
  4041. lArrayIndex++;
  4042. } else
  4043. hr = E_OUTOFMEMORY;
  4044. return hr;
  4045. }
  4046. /**************************************************************************\
  4047. * DeleteCapabilitiesArrayContents
  4048. *
  4049. * This helper deletes the capabilities array
  4050. *
  4051. * Arguments:
  4052. *
  4053. * none
  4054. *
  4055. * Return Value:
  4056. *
  4057. * Status
  4058. *
  4059. * History:
  4060. *
  4061. * 03/05/2002 Original Version
  4062. *
  4063. \**************************************************************************/
  4064. HRESULT CWIADevice::DeleteCapabilitiesArrayContents()
  4065. {
  4066. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4067. WIALOG_NO_RESOURCE_ID,
  4068. WIALOG_LEVEL1,
  4069. "CWIADevice::DeleteCapabilitiesArrayContents");
  4070. HRESULT hr = S_OK;
  4071. if (NULL != m_pCapabilities) {
  4072. for (LONG i = 0; i < (m_NumSupportedCommands + m_NumSupportedEvents);i++) {
  4073. if(m_pCapabilities[i].wszName){
  4074. CoTaskMemFree(m_pCapabilities[i].wszName);
  4075. }
  4076. if(m_pCapabilities[i].wszDescription) {
  4077. CoTaskMemFree(m_pCapabilities[i].wszDescription);
  4078. }
  4079. }
  4080. delete [] m_pCapabilities;
  4081. m_pCapabilities = NULL;
  4082. }
  4083. return hr;
  4084. }
  4085. /**************************************************************************\
  4086. * GetBSTRResourceString
  4087. *
  4088. * This helper gets a BSTR from a resource location
  4089. *
  4090. * Arguments:
  4091. *
  4092. * lResourceID - Resource ID of the target BSTR value
  4093. * pBSTR - pointer to a BSTR value (caller must free this string)
  4094. * bLocal - TRUE - for local resources, FALSE - for wiaservc resources
  4095. *
  4096. * Return Value:
  4097. *
  4098. * Status
  4099. *
  4100. * History:
  4101. *
  4102. * 03/05/2002 Original Version
  4103. *
  4104. \**************************************************************************/
  4105. HRESULT CWIADevice::GetBSTRResourceString(LONG lResourceID,BSTR *pBSTR,BOOL bLocal)
  4106. {
  4107. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4108. WIALOG_NO_RESOURCE_ID,
  4109. WIALOG_LEVEL1,
  4110. "CWIADevice::GetBSTRResourceString");
  4111. HRESULT hr = S_OK;
  4112. TCHAR szStringValue[255];
  4113. if (bLocal) {
  4114. //
  4115. // We are looking for a resource in our own private resource file
  4116. //
  4117. LoadString(g_hInst,lResourceID,szStringValue,255);
  4118. //
  4119. // NOTE: caller must free this allocated BSTR
  4120. //
  4121. #ifdef UNICODE
  4122. *pBSTR = SysAllocString(szStringValue);
  4123. #else
  4124. WCHAR wszStringValue[255];
  4125. //
  4126. // convert szStringValue from char* to unsigned short* (ANSI only)
  4127. //
  4128. MultiByteToWideChar(CP_ACP,
  4129. MB_PRECOMPOSED,
  4130. szStringValue,
  4131. lstrlenA(szStringValue)+1,
  4132. wszStringValue,
  4133. (sizeof(wszStringValue)/sizeof(wszStringValue[0])));
  4134. *pBSTR = SysAllocString(wszStringValue);
  4135. #endif
  4136. } else {
  4137. //
  4138. // We are looking for a resource in the wiaservc's resource file
  4139. //
  4140. hr = E_NOTIMPL;
  4141. }
  4142. return hr;
  4143. }
  4144. /**************************************************************************\
  4145. * GetOLESTRResourceString
  4146. *
  4147. * This helper gets a LPOLESTR from a resource location
  4148. *
  4149. * Arguments:
  4150. *
  4151. * lResourceID - Resource ID of the target BSTR value
  4152. * ppsz - pointer to a OLESTR value (caller must free this string)
  4153. * bLocal - TRUE - for local resources, FALSE - for wiaservc resources
  4154. *
  4155. * Return Value:
  4156. *
  4157. * Status
  4158. *
  4159. * History:
  4160. *
  4161. * 03/05/2002 Original Version
  4162. *
  4163. \**************************************************************************/
  4164. HRESULT CWIADevice::GetOLESTRResourceString(LONG lResourceID,LPOLESTR *ppsz,BOOL bLocal)
  4165. {
  4166. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4167. WIALOG_NO_RESOURCE_ID,
  4168. WIALOG_LEVEL1,
  4169. "CWIADevice::GetOLESTRResourceString");
  4170. HRESULT hr = S_OK;
  4171. TCHAR szStringValue[255];
  4172. if (bLocal) {
  4173. //
  4174. // We are looking for a resource in our own private resource file
  4175. //
  4176. LoadString(g_hInst,lResourceID,szStringValue,255);
  4177. //
  4178. // NOTE: caller must free this allocated BSTR
  4179. //
  4180. #ifdef UNICODE
  4181. *ppsz = NULL;
  4182. *ppsz = (LPOLESTR)CoTaskMemAlloc(sizeof(szStringValue));
  4183. if (*ppsz != NULL) {
  4184. wcscpy(*ppsz,szStringValue);
  4185. } else {
  4186. return E_OUTOFMEMORY;
  4187. }
  4188. #else
  4189. WCHAR wszStringValue[255];
  4190. //
  4191. // convert szStringValue from char* to unsigned short* (ANSI only)
  4192. //
  4193. MultiByteToWideChar(CP_ACP,
  4194. MB_PRECOMPOSED,
  4195. szStringValue,
  4196. lstrlenA(szStringValue)+1,
  4197. wszStringValue,
  4198. (sizeof(wszStringValue)/sizeof(wszStringValue[0])));
  4199. *ppsz = NULL;
  4200. *ppsz = (LPOLESTR)CoTaskMemAlloc(sizeof(wszStringValue));
  4201. if (*ppsz != NULL) {
  4202. wcscpy(*ppsz,wszStringValue);
  4203. } else {
  4204. return E_OUTOFMEMORY;
  4205. }
  4206. #endif
  4207. } else {
  4208. //
  4209. // We are looking for a resource in the wiaservc's resource file
  4210. //
  4211. hr = E_NOTIMPL;
  4212. }
  4213. return hr;
  4214. }
  4215. /**************************************************************************\
  4216. * SwapBuffer24
  4217. *
  4218. * Place RGB bytes in correct order for DIB format.
  4219. *
  4220. * Arguments:
  4221. *
  4222. * pBuffer - Pointer to the data buffer.
  4223. * lByteCount - Size of the data in bytes.
  4224. *
  4225. * Return Value:
  4226. *
  4227. * Status
  4228. *
  4229. * History:
  4230. *
  4231. * 03/05/2002 Original Version
  4232. *
  4233. \**************************************************************************/
  4234. VOID CWIADevice::SwapBuffer24(PBYTE pBuffer, LONG lByteCount)
  4235. {
  4236. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4237. WIALOG_NO_RESOURCE_ID,
  4238. WIALOG_LEVEL3,
  4239. "CWIADevice::SwapBuffer24");
  4240. if (!pBuffer) {
  4241. return;
  4242. }
  4243. for (LONG i = 0; i < lByteCount; i+= 3) {
  4244. BYTE bTemp = pBuffer[i];
  4245. pBuffer[i] = pBuffer[i + 2];
  4246. pBuffer[i + 2] = bTemp;
  4247. }
  4248. }
  4249. /**************************************************************************\
  4250. * IsPreviewScan
  4251. *
  4252. * Get the current preview setting from the item properties.
  4253. * A helper for drvAcquireItemData.
  4254. *
  4255. * Arguments:
  4256. *
  4257. * pWiasContext - pointer to an Item context.
  4258. *
  4259. * Return Value:
  4260. *
  4261. * TRUE - Preview is set, FALSE - Final is set
  4262. *
  4263. * History:
  4264. *
  4265. * 03/05/2002 Original Version
  4266. *
  4267. \**************************************************************************/
  4268. BOOL CWIADevice::IsPreviewScan(BYTE *pWiasContext)
  4269. {
  4270. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4271. WIALOG_NO_RESOURCE_ID,
  4272. WIALOG_LEVEL3,
  4273. "CWIADevice::IsPreviewScan");
  4274. //
  4275. // If the caller did not pass in the correct parameters, then fail the
  4276. // call with E_INVALIDARG.
  4277. //
  4278. if (!pWiasContext) {
  4279. return FALSE;
  4280. }
  4281. //
  4282. // Get a pointer to the root item, for property access.
  4283. //
  4284. BYTE *pRootItemCtx = NULL;
  4285. HRESULT hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  4286. if (FAILED(hr)) {
  4287. WIAS_LWARNING(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("IsPreviewScan, No Preview Property Found on ROOT item!"));
  4288. return FALSE;
  4289. }
  4290. //
  4291. // Get the current preview setting.
  4292. //
  4293. LONG lPreview = 0;
  4294. hr = wiasReadPropLong(pRootItemCtx, WIA_DPS_PREVIEW, &lPreview, NULL, true);
  4295. if (hr != S_OK) {
  4296. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("IsPreviewScan, Failed to read Preview Property."));
  4297. WIAS_LHRESULT(m_pIWiaLog, hr);
  4298. return FALSE;
  4299. }
  4300. return(lPreview > 0);
  4301. }
  4302. /**************************************************************************\
  4303. * GetPageCount
  4304. *
  4305. * Get the requested number of pages to scan from the item properties.
  4306. * A helper for drvAcquireItemData.
  4307. *
  4308. * Arguments:
  4309. *
  4310. * pWiasContext - pointer to an Item context.
  4311. *
  4312. * Return Value:
  4313. *
  4314. * Number of pages to scan.
  4315. *
  4316. * History:
  4317. *
  4318. * 03/05/2002 Original Version
  4319. *
  4320. \**************************************************************************/
  4321. LONG CWIADevice::GetPageCount(BYTE *pWiasContext)
  4322. {
  4323. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4324. WIALOG_NO_RESOURCE_ID,
  4325. WIALOG_LEVEL3,
  4326. "CWIADevice::GetPageCount");
  4327. //
  4328. // If the caller did not pass in the correct parameters, then fail the
  4329. // call with E_INVALIDARG.
  4330. //
  4331. if (!pWiasContext) {
  4332. return E_INVALIDARG;
  4333. }
  4334. //
  4335. // Get a pointer to the root item, for property access.
  4336. //
  4337. BYTE *pRootItemCtx = NULL;
  4338. HRESULT hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  4339. if (FAILED(hr)) {
  4340. return 1;
  4341. }
  4342. //
  4343. // Get the requested page count.
  4344. //
  4345. LONG lPagesRequested = 0;
  4346. hr = wiasReadPropLong(pRootItemCtx, WIA_DPS_PAGES, &lPagesRequested, NULL, true);
  4347. if (hr != S_OK) {
  4348. return 1;
  4349. }
  4350. return lPagesRequested;
  4351. }
  4352. /**************************************************************************\
  4353. * SetItemSize
  4354. *
  4355. * Calulate the new item size, and write the new Item Size property value.
  4356. *
  4357. * Arguments:
  4358. *
  4359. * pWiasContext - item
  4360. *
  4361. * Return Value:
  4362. *
  4363. * Status
  4364. *
  4365. * History:
  4366. *
  4367. * 03/05/2002 Original Version
  4368. *
  4369. \**************************************************************************/
  4370. HRESULT CWIADevice::SetItemSize(BYTE *pWiasContext)
  4371. {
  4372. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  4373. WIALOG_NO_RESOURCE_ID,
  4374. WIALOG_LEVEL3,
  4375. "CWIADevice::SetItemSize");
  4376. //
  4377. // If the caller did not pass in the correct parameters, then fail the
  4378. // call with E_INVALIDARG.
  4379. //
  4380. if (!pWiasContext) {
  4381. return E_INVALIDARG;
  4382. }
  4383. HRESULT hr = S_OK;
  4384. hr = wiasWritePropLong(pWiasContext,WIA_IPA_ITEM_SIZE,0);
  4385. if (FAILED(hr)) {
  4386. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("SetItemSize, wiasWritePropLong Failed to read WIA_IPA_ITEM_SIZE"));
  4387. WIAS_LHRESULT(m_pIWiaLog, hr);
  4388. }
  4389. return hr;
  4390. }