Source code of Windows XP (NT5)
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.

510 lines
15 KiB

  1. /****************************************************************************
  2. *
  3. * (C) COPYRIGHT 2000, MICROSOFT CORP.
  4. *
  5. * FILE: wiaprop.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 11/10/2000
  10. *
  11. * AUTHOR: Dave Parsons
  12. *
  13. * DESCRIPTION:
  14. * Helper functions for initializing WIA driver properties.
  15. *
  16. *****************************************************************************/
  17. #include "pch.h"
  18. //
  19. // Constructor
  20. //
  21. CWiauPropertyList::CWiauPropertyList() :
  22. m_NumAlloc(0),
  23. m_NumProps(0),
  24. m_pId(NULL),
  25. m_pNames(NULL),
  26. m_pCurrent(NULL),
  27. m_pPropSpec(NULL),
  28. m_pAttrib(NULL)
  29. {
  30. }
  31. //
  32. // Destructor
  33. //
  34. CWiauPropertyList::~CWiauPropertyList()
  35. {
  36. if (m_pId)
  37. delete []m_pId;
  38. if (m_pNames)
  39. delete []m_pNames;
  40. if (m_pCurrent)
  41. delete []m_pCurrent;
  42. if (m_pPropSpec)
  43. delete []m_pPropSpec;
  44. if (m_pAttrib)
  45. delete []m_pAttrib;
  46. }
  47. //
  48. // This function allocates the property arrays
  49. //
  50. // Input:
  51. // NumProps -- number of properties to reserve space for. This number can be larger
  52. // than the actual number used, but cannot be smaller.
  53. //
  54. HRESULT
  55. CWiauPropertyList::Init(INT NumProps)
  56. {
  57. HRESULT hr = S_OK;
  58. REQUIRE_ARGS(NumProps < 1, hr, "Init");
  59. if (m_NumAlloc > 0)
  60. {
  61. wiauDbgError("Init", "Property list already initialized");
  62. hr = E_FAIL;
  63. goto Cleanup;
  64. }
  65. m_pId = new PROPID[NumProps];
  66. m_pNames = new LPOLESTR[NumProps];
  67. m_pCurrent = new PROPVARIANT[NumProps];
  68. m_pPropSpec = new PROPSPEC[NumProps];
  69. m_pAttrib = new WIA_PROPERTY_INFO[NumProps];
  70. REQUIRE_ALLOC(m_pId, hr, "Init");
  71. REQUIRE_ALLOC(m_pNames, hr, "Init");
  72. REQUIRE_ALLOC(m_pCurrent, hr, "Init");
  73. REQUIRE_ALLOC(m_pPropSpec, hr, "Init");
  74. REQUIRE_ALLOC(m_pAttrib, hr, "Init");
  75. m_NumAlloc = NumProps;
  76. m_NumProps = 0;
  77. Cleanup:
  78. return hr;
  79. }
  80. //
  81. // This function adds a property definition to the arrays
  82. //
  83. // Input:
  84. // index -- pointer to an int that will be set to the array index, useful
  85. // for passing to other property functions
  86. // PropId -- property ID constant
  87. // PropName -- property name string
  88. // Access -- determines access to the property, usually either
  89. // WIA_PROP_READ or WIA_PROP_RW
  90. // SubType -- indicates subtype of the property, usually either WIA_PROP_NONE,
  91. // WIA_PROP_RANGE, or WIA_PROP_LIST
  92. //
  93. HRESULT
  94. CWiauPropertyList::DefineProperty(int *pIdx, PROPID PropId, LPOLESTR PropName, ULONG Access, ULONG SubType)
  95. {
  96. HRESULT hr = S_OK;
  97. REQUIRE_ARGS(!pIdx, hr, "DefineProperty");
  98. if (m_NumProps >= m_NumAlloc)
  99. {
  100. wiauDbgError("DefineProperty", "PropertyList is full. Increase number passed to Init");
  101. hr = E_FAIL;
  102. goto Cleanup;
  103. }
  104. int idx = m_NumProps++;
  105. m_pId[idx] = PropId;
  106. m_pNames[idx] = PropName;
  107. m_pCurrent[idx].vt = VT_EMPTY;
  108. m_pPropSpec[idx].ulKind = PRSPEC_PROPID;
  109. m_pPropSpec[idx].propid = PropId;
  110. m_pAttrib[idx].vt = VT_EMPTY;
  111. m_pAttrib[idx].lAccessFlags = Access | SubType;
  112. if (pIdx)
  113. *pIdx = idx;
  114. Cleanup:
  115. return hr;
  116. }
  117. //
  118. // This function sends all the newly created properties to WIA
  119. //
  120. // Input:
  121. // pWiasContext -- pointer to the context passed to drvInitItemProperties
  122. //
  123. HRESULT
  124. CWiauPropertyList::SendToWia(BYTE *pWiasContext)
  125. {
  126. HRESULT hr = S_OK;
  127. REQUIRE_ARGS(!pWiasContext, hr, "SendToWia");
  128. if (m_NumProps == 0)
  129. {
  130. wiauDbgError("SendToWia", "No properties in the array, use DefineProperty");
  131. hr = E_FAIL;
  132. goto Cleanup;
  133. }
  134. //
  135. // Set the property names
  136. //
  137. hr = wiasSetItemPropNames(pWiasContext, m_NumProps, m_pId, m_pNames);
  138. REQUIRE_SUCCESS(hr, "SendToWia", "wiasSetItemPropNames failed");
  139. //
  140. // Set the default values for the properties
  141. //
  142. hr = wiasWriteMultiple(pWiasContext, m_NumProps, m_pPropSpec, m_pCurrent);
  143. REQUIRE_SUCCESS(hr, "SendToWia", "wiasWriteMultiple failed");
  144. //
  145. // Set property access and valid value info
  146. //
  147. hr = wiasSetItemPropAttribs(pWiasContext, m_NumProps, m_pPropSpec, m_pAttrib);
  148. REQUIRE_SUCCESS(hr, "SendToWia", "wiasSetItemPropAttribs failed");
  149. Cleanup:
  150. return hr;
  151. }
  152. //
  153. // This function can be used to reset the access and subtype of a property
  154. //
  155. // Input:
  156. // index -- the index into the arrays, pass in value returned from DefineProperty
  157. // Access -- determines access to the property, usually either
  158. // WIA_PROP_READ or WIA_PROP_RW
  159. // SubType -- indicates subtype of the property, usually either WIA_PROP_NONE,
  160. // WIA_PROP_RANGE, or WIA_PROP_LIST
  161. //
  162. VOID
  163. CWiauPropertyList::SetAccessSubType(INT index, ULONG Access, ULONG SubType)
  164. {
  165. m_pAttrib[index].lAccessFlags = Access | SubType;
  166. }
  167. //
  168. // Polymorphic function for setting the type and current, default, and valid values of a
  169. // property. This function handles flag properties.
  170. //
  171. // Input:
  172. // index -- the index into the arrays, pass in value returned from DefineProperty
  173. // defaultValue -- default setting of this property on the device
  174. // currentValue -- current setting of this property on the device
  175. // validFlags -- combination of all valid flags
  176. //
  177. VOID
  178. CWiauPropertyList::SetValidValues(INT index, LONG defaultValue, LONG currentValue, LONG validFlags)
  179. {
  180. m_pAttrib[index].vt = VT_I4;
  181. m_pAttrib[index].ValidVal.Flag.Nom = defaultValue;
  182. m_pAttrib[index].ValidVal.Flag.ValidBits = validFlags;
  183. m_pAttrib[index].lAccessFlags |= WIA_PROP_FLAG;
  184. m_pCurrent[index].vt = VT_I4;
  185. m_pCurrent[index].lVal = currentValue;
  186. return;
  187. }
  188. //
  189. // Polymorphic function for setting the type and current, default, and valid values of a
  190. // property. This function handles VT_I4 range.
  191. //
  192. // Input:
  193. // index -- the index into the arrays, pass in value returned from DefineProperty
  194. // defaultValue -- default setting of this property on the device
  195. // currentValue -- current setting of this property on the device
  196. // minValue -- minimum value for the range
  197. // maxValue -- maximum value for the range
  198. // stepValue -- step value for the range
  199. //
  200. VOID
  201. CWiauPropertyList::SetValidValues(INT index, LONG defaultValue, LONG currentValue,
  202. LONG minValue, LONG maxValue, LONG stepValue)
  203. {
  204. m_pAttrib[index].vt = VT_I4;
  205. m_pAttrib[index].ValidVal.Range.Nom = defaultValue;
  206. m_pAttrib[index].ValidVal.Range.Min = minValue;
  207. m_pAttrib[index].ValidVal.Range.Max = maxValue;
  208. m_pAttrib[index].ValidVal.Range.Inc = stepValue;
  209. m_pAttrib[index].lAccessFlags |= WIA_PROP_RANGE;
  210. m_pCurrent[index].vt = VT_I4;
  211. m_pCurrent[index].lVal = currentValue;
  212. return;
  213. }
  214. //
  215. // Polymorphic function for setting the type and current, default, and valid values of a
  216. // property. This function handles VT_I4 list.
  217. //
  218. // Input:
  219. // index -- the index into the arrays, pass in value returned from DefineProperty
  220. // defaultValue -- default setting of this property on the device
  221. // currentValue -- current setting of this property on the device
  222. // numValues -- number of values in the list
  223. // pValues -- pointer to the value list
  224. //
  225. VOID
  226. CWiauPropertyList::SetValidValues(INT index, LONG defaultValue, LONG currentValue,
  227. INT numValues, PLONG pValues)
  228. {
  229. m_pAttrib[index].vt = VT_I4;
  230. m_pAttrib[index].ValidVal.List.Nom = defaultValue;
  231. m_pAttrib[index].ValidVal.List.cNumList = numValues;
  232. m_pAttrib[index].ValidVal.List.pList = (BYTE*)pValues;
  233. m_pAttrib[index].lAccessFlags |= WIA_PROP_LIST;
  234. m_pCurrent[index].vt = VT_I4;
  235. m_pCurrent[index].lVal = currentValue;
  236. return;
  237. }
  238. //
  239. // Polymorphic function for setting the type and current, default, and valid values of a
  240. // property. This function handles VT_BSTR list.
  241. //
  242. // Input:
  243. // index -- the index into the arrays, pass in value returned from DefineProperty
  244. // defaultValue -- default setting of this property on the device
  245. // currentValue -- current setting of this property on the device
  246. // numValues -- number of values in the list
  247. // pValues -- pointer to the value list
  248. //
  249. VOID
  250. CWiauPropertyList::SetValidValues(INT index, BSTR defaultValue, BSTR currentValue,
  251. INT numValues, BSTR *pValues)
  252. {
  253. m_pAttrib[index].vt = VT_BSTR;
  254. m_pAttrib[index].ValidVal.ListBStr.Nom = defaultValue;
  255. m_pAttrib[index].ValidVal.ListBStr.cNumList = numValues;
  256. m_pAttrib[index].ValidVal.ListBStr.pList = pValues;
  257. m_pAttrib[index].lAccessFlags |= WIA_PROP_LIST;
  258. m_pCurrent[index].vt = VT_BSTR;
  259. m_pCurrent[index].bstrVal = currentValue;
  260. return;
  261. }
  262. //
  263. // Polymorphic function for setting the type and current, default, and valid values of a
  264. // property. This function handles VT_R4 range.
  265. //
  266. // Input:
  267. // index -- the index into the arrays, pass in value returned from DefineProperty
  268. // defaultValue -- default setting of this property on the device
  269. // currentValue -- current setting of this property on the device
  270. // minValue -- minimum value for the range
  271. // maxValue -- maximum value for the range
  272. // stepValue -- step value for the range
  273. //
  274. VOID
  275. CWiauPropertyList::SetValidValues(INT index, FLOAT defaultValue, FLOAT currentValue,
  276. FLOAT minValue, FLOAT maxValue, FLOAT stepValue)
  277. {
  278. m_pAttrib[index].vt = VT_R4;
  279. m_pAttrib[index].ValidVal.RangeFloat.Nom = defaultValue;
  280. m_pAttrib[index].ValidVal.RangeFloat.Min = minValue;
  281. m_pAttrib[index].ValidVal.RangeFloat.Max = maxValue;
  282. m_pAttrib[index].ValidVal.RangeFloat.Inc = stepValue;
  283. m_pAttrib[index].lAccessFlags |= WIA_PROP_RANGE;
  284. m_pCurrent[index].vt = VT_R4;
  285. m_pCurrent[index].fltVal = currentValue;
  286. return;
  287. }
  288. //
  289. // Polymorphic function for setting the type and current, default, and valid values of a
  290. // property. This function handles VT_R4 list.
  291. //
  292. // Input:
  293. // index -- the index into the arrays, pass in value returned from DefineProperty
  294. // defaultValue -- default setting of this property on the device
  295. // currentValue -- current setting of this property on the device
  296. // numValues -- number of values in the list
  297. // pValues -- pointer to the value list
  298. //
  299. VOID
  300. CWiauPropertyList::SetValidValues(INT index, FLOAT defaultValue, FLOAT currentValue,
  301. INT numValues, PFLOAT pValues)
  302. {
  303. m_pAttrib[index].vt = VT_R4;
  304. m_pAttrib[index].ValidVal.ListFloat.Nom = defaultValue;
  305. m_pAttrib[index].ValidVal.ListFloat.cNumList = numValues;
  306. m_pAttrib[index].ValidVal.ListFloat.pList = (BYTE*)pValues;
  307. m_pAttrib[index].lAccessFlags |= WIA_PROP_LIST;
  308. m_pCurrent[index].vt = VT_R4;
  309. m_pCurrent[index].fltVal = currentValue;
  310. return;
  311. }
  312. //
  313. // Polymorphic function for setting the type and current, default, and valid values of a
  314. // property. This function handles VT_CLSID list.
  315. //
  316. // Input:
  317. // index -- the index into the arrays, pass in value returned from DefineProperty
  318. // defaultValue -- default setting of this property on the device
  319. // currentValue -- current setting of this property on the device
  320. // numValues -- number of values in the list
  321. // pValues -- pointer to the value list
  322. //
  323. VOID
  324. CWiauPropertyList::SetValidValues(INT index, CLSID *defaultValue, CLSID *currentValue,
  325. INT numValues, CLSID **pValues)
  326. {
  327. m_pAttrib[index].vt = VT_CLSID;
  328. m_pAttrib[index].ValidVal.ListGuid.Nom = *defaultValue;
  329. m_pAttrib[index].ValidVal.ListGuid.cNumList = numValues;
  330. m_pAttrib[index].ValidVal.ListGuid.pList = *pValues;
  331. m_pAttrib[index].lAccessFlags |= WIA_PROP_LIST;
  332. m_pCurrent[index].vt = VT_CLSID;
  333. m_pCurrent[index].puuid = currentValue;
  334. return;
  335. }
  336. //
  337. // Polymorphic function for setting the type and current value for a VT_I4
  338. //
  339. // Input:
  340. // index -- the index into the arrays, pass in value returned from DefineProperty
  341. // value -- value to use for the current value
  342. //
  343. VOID
  344. CWiauPropertyList::SetCurrentValue(INT index, LONG value)
  345. {
  346. m_pCurrent[index].vt = VT_I4;
  347. m_pAttrib[index].vt = VT_I4;
  348. m_pCurrent[index].lVal = value;
  349. return;
  350. }
  351. //
  352. // Polymorphic function for setting the type and current value for a VT_BSTR
  353. //
  354. // Input:
  355. // index -- the index into the arrays, pass in value returned from DefineProperty
  356. // value -- value to use for the current value
  357. //
  358. VOID
  359. CWiauPropertyList::SetCurrentValue(INT index, BSTR value)
  360. {
  361. m_pCurrent[index].vt = VT_BSTR;
  362. m_pAttrib[index].vt = VT_BSTR;
  363. m_pCurrent[index].bstrVal = value;
  364. return;
  365. }
  366. //
  367. // Polymorphic function for setting the type and current value for a VT_R4
  368. //
  369. // Input:
  370. // index -- the index into the arrays, pass in value returned from DefineProperty
  371. // value -- value to use for the current value
  372. //
  373. VOID
  374. CWiauPropertyList::SetCurrentValue(INT index, FLOAT value)
  375. {
  376. m_pCurrent[index].vt = VT_R4;
  377. m_pAttrib[index].vt = VT_R4;
  378. m_pCurrent[index].fltVal = value;
  379. return;
  380. }
  381. //
  382. // Polymorphic function for setting the type and current value for a VT_CLSID
  383. //
  384. // Input:
  385. // index -- the index into the arrays, pass in value returned from DefineProperty
  386. // value -- value to use for the current value
  387. //
  388. VOID
  389. CWiauPropertyList::SetCurrentValue(INT index, CLSID *pValue)
  390. {
  391. m_pCurrent[index].vt = VT_CLSID;
  392. m_pAttrib[index].vt = VT_CLSID;
  393. m_pCurrent[index].puuid = pValue;
  394. return;
  395. }
  396. //
  397. // Polymorphic function for setting the type and current value for a property which holds a SYSTEMTIME
  398. //
  399. // Input:
  400. // index -- the index into the arrays, pass in value returned from DefineProperty
  401. // value -- value to use for the current value
  402. //
  403. VOID
  404. CWiauPropertyList::SetCurrentValue(INT index, PSYSTEMTIME value)
  405. {
  406. m_pCurrent[index].vt = VT_UI2 | VT_VECTOR;
  407. m_pAttrib[index].vt = VT_UI2 | VT_VECTOR;
  408. m_pAttrib[index].lAccessFlags |= WIA_PROP_NONE;
  409. m_pCurrent[index].caui.cElems = sizeof(SYSTEMTIME)/sizeof(WORD);
  410. m_pCurrent[index].caui.pElems = (USHORT *) value;
  411. return;
  412. }
  413. //
  414. // Polymorphic function for setting the type and current value for a property which holds a VT_UI1 vector
  415. //
  416. // Input:
  417. // index -- the index into the arrays, pass in value returned from DefineProperty
  418. // value -- value to use for the current value
  419. // size -- number of elements in the vector
  420. //
  421. VOID
  422. CWiauPropertyList::SetCurrentValue(INT index, BYTE *value, INT size)
  423. {
  424. m_pCurrent[index].vt = VT_UI1 | VT_VECTOR;
  425. m_pAttrib[index].vt = VT_UI1 | VT_VECTOR;
  426. m_pCurrent[index].caub.cElems = size;
  427. m_pCurrent[index].caub.pElems = value;
  428. return;
  429. }
  430. //
  431. // Finds the index given a property ID
  432. //
  433. INT
  434. CWiauPropertyList::LookupPropId(PROPID PropId)
  435. {
  436. for (int count = 0; count < m_NumProps; count++)
  437. {
  438. if (m_pId[count] == PropId)
  439. return count;
  440. }
  441. //
  442. // Value not found
  443. //
  444. return -1;
  445. }