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.

328 lines
15 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT 2000, MICROSOFT CORP.
  4. *
  5. * TITLE: Root.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 18 July, 2000
  10. *
  11. * DESCRIPTION:
  12. * This file implements the helper methods for IWiaMiniDrv for the root item.
  13. *
  14. *******************************************************************************/
  15. #include "pch.h"
  16. /**************************************************************************\
  17. * BuildRootItemProperties
  18. *
  19. * Create the properties for the root item.
  20. *
  21. * Arguments:
  22. *
  23. * pWiasContext - WIA service context
  24. *
  25. \**************************************************************************/
  26. HRESULT
  27. CWiaCameraDevice::BuildRootItemProperties(
  28. BYTE *pWiasContext
  29. )
  30. {
  31. DBG_FN("CWiaCameraDevice::BuildRootItemProperties");
  32. HRESULT hr = S_OK;
  33. //
  34. // Locals
  35. //
  36. BSTR bstrFirmwareVer = NULL;
  37. //
  38. // Create a WIA property list and allocate enough space for all
  39. // the properties created below
  40. //
  41. CWiauPropertyList RootProps;
  42. hr = RootProps.Init(50);
  43. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "Init property list failed");
  44. //
  45. // These are the WHQL required properties for cameras:
  46. //
  47. INT index;
  48. hr = RootProps.DefineProperty(&index, WIA_IPA_ACCESS_RIGHTS, WIA_IPA_ACCESS_RIGHTS_STR,
  49. WIA_PROP_READ, WIA_PROP_NONE);
  50. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  51. RootProps.SetCurrentValue(index, (LONG) WIA_ITEM_READ | WIA_ITEM_WRITE);
  52. if (m_pDeviceInfo->pwszFirmwareVer) {
  53. hr = RootProps.DefineProperty(&index, WIA_DPA_FIRMWARE_VERSION, WIA_DPA_FIRMWARE_VERSION_STR,
  54. WIA_PROP_READ, WIA_PROP_NONE);
  55. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  56. bstrFirmwareVer = SysAllocString(m_pDeviceInfo->pwszFirmwareVer);
  57. REQUIRE_ALLOC(bstrFirmwareVer, hr, "BuildRootItemProperties");
  58. RootProps.SetCurrentValue(index, bstrFirmwareVer);
  59. }
  60. hr = RootProps.DefineProperty(&index, WIA_DPC_PICTURES_TAKEN, WIA_DPC_PICTURES_TAKEN_STR,
  61. WIA_PROP_READ, WIA_PROP_NONE);
  62. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  63. RootProps.SetCurrentValue(index, m_pDeviceInfo->lPicturesTaken);
  64. hr = RootProps.DefineProperty(&index, WIA_DPC_PICTURES_REMAINING, WIA_DPC_PICTURES_REMAINING_STR,
  65. WIA_PROP_READ, WIA_PROP_NONE);
  66. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  67. RootProps.SetCurrentValue(index, m_pDeviceInfo->lPicturesRemaining);
  68. //
  69. // These are WHQL optional properties
  70. //
  71. hr = RootProps.DefineProperty(&index, WIA_DPA_DEVICE_TIME, WIA_DPA_DEVICE_TIME_STR,
  72. WIA_PROP_RW, WIA_PROP_NONE);
  73. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  74. RootProps.SetCurrentValue(index, &m_pDeviceInfo->Time);
  75. #if DEADCODE
  76. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_MODE, WIA_DPC_EXPOSURE_MODE_STR,
  77. WIA_PROP_RW, WIA_PROP_NONE);
  78. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  79. RootProps.SetCurrentValue(index, CameraStats.ExposureMode);
  80. FakeCamera_SetValidValues(index, pRootProperties);
  81. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_COMP, WIA_DPC_EXPOSURE_COMP_STR,
  82. WIA_PROP_RW, WIA_PROP_NONE);
  83. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  84. RootProps.SetCurrentValue(index, CameraStats.ExposureComp);
  85. FakeCamera_SetValidValues(index, pRootProperties);
  86. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_TIME, WIA_DPC_EXPOSURE_TIME_STR,
  87. WIA_PROP_RW, WIA_PROP_NONE);
  88. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  89. RootProps.SetCurrentValue(index, CameraStats.ExposureTime);
  90. hr = RootProps.DefineProperty(&index, WIA_DPC_FNUMBER, WIA_DPC_FNUMBER_STR,
  91. WIA_PROP_RW, WIA_PROP_NONE);
  92. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  93. RootProps.SetCurrentValue(index, CameraStats.FNumber);
  94. hr = RootProps.DefineProperty(&index, WIA_DPC_FLASH_MODE, WIA_DPC_FLASH_MODE_STR,
  95. WIA_PROP_RW, WIA_PROP_NONE);
  96. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  97. RootProps.SetCurrentValue(index, CameraStats.FlashMode);
  98. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_MODE, WIA_DPC_FOCUS_MODE_STR,
  99. WIA_PROP_RW, WIA_PROP_NONE);
  100. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  101. RootProps.SetCurrentValue(index, CameraStats.FocusMode);
  102. hr = RootProps.DefineProperty(&index, WIA_DPC_PAN_POSITION, WIA_DPC_PAN_POSITION_STR,
  103. WIA_PROP_RW, WIA_PROP_NONE);
  104. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  105. RootProps.SetCurrentValue(index, CameraStats.PanPosition);
  106. hr = RootProps.DefineProperty(&index, WIA_DPC_TILT_POSITION, WIA_DPC_TILT_POSITION_STR,
  107. WIA_PROP_RW, WIA_PROP_NONE);
  108. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  109. RootProps.SetCurrentValue(index, CameraStats.TiltPosition);
  110. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMER_MODE, WIA_DPC_TIMER_MODE_STR,
  111. WIA_PROP_RW, WIA_PROP_NONE);
  112. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  113. RootProps.SetCurrentValue(index, CameraStats.TimerMode);
  114. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMER_VALUE, WIA_DPC_TIMER_VALUE_STR,
  115. WIA_PROP_RW, WIA_PROP_NONE);
  116. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  117. RootProps.SetCurrentValue(index, CameraStats.TimerValue);
  118. hr = RootProps.DefineProperty(&index, WIA_DPC_POWER_MODE, WIA_DPC_POWER_MODE_STR,
  119. WIA_PROP_READ, WIA_PROP_NONE);
  120. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  121. RootProps.SetCurrentValue(index, CameraStats.PowerMode);
  122. hr = RootProps.DefineProperty(&index, WIA_DPC_BATTERY_STATUS, WIA_DPC_BATTERY_STATUS_STR,
  123. WIA_PROP_READ, WIA_PROP_NONE);
  124. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  125. RootProps.SetCurrentValue(index, CameraStats.BatteryStatus);
  126. hr = RootProps.DefineProperty(&index, WIA_DPC_THUMB_WIDTH, WIA_DPC_THUMB_WIDTH_STR,
  127. WIA_PROP_RW, WIA_PROP_NONE);
  128. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  129. RootProps.SetCurrentValue(index, CameraStats.ThumbWidth);
  130. hr = RootProps.DefineProperty(&index, WIA_DPC_THUMB_HEIGHT, WIA_DPC_THUMB_HEIGHT_STR,
  131. WIA_PROP_RW, WIA_PROP_NONE);
  132. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  133. RootProps.SetCurrentValue(index, CameraStats.ThumbHeight);
  134. hr = RootProps.DefineProperty(&index, WIA_DPC_PICT_WIDTH, WIA_DPC_PICT_WIDTH_STR,
  135. WIA_PROP_RW, WIA_PROP_NONE);
  136. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  137. RootProps.SetCurrentValue(index, CameraStats.PictWidth);
  138. hr = RootProps.DefineProperty(&index, WIA_DPC_PICT_HEIGHT, WIA_DPC_PICT_HEIGHT_STR,
  139. WIA_PROP_RW, WIA_PROP_NONE);
  140. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  141. RootProps.SetCurrentValue(index, CameraStats.PictHeight);
  142. hr = RootProps.DefineProperty(&index, WIA_DPC_COMPRESSION_SETTING, WIA_DPC_COMPRESSION_SETTING_STR,
  143. WIA_PROP_RW, WIA_PROP_NONE);
  144. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  145. RootProps.SetCurrentValue(index, CameraStats.CompressionSetting);
  146. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMELAPSE_INTERVAL, WIA_DPC_TIMELAPSE_INTERVAL_STR,
  147. WIA_PROP_RW, WIA_PROP_NONE);
  148. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  149. RootProps.SetCurrentValue(index, CameraStats.TimelapseInterval);
  150. hr = RootProps.DefineProperty(&index, WIA_DPC_BURST_INTERVAL, WIA_DPC_BURST_INTERVAL_STR,
  151. WIA_PROP_RW, WIA_PROP_NONE);
  152. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  153. RootProps.SetCurrentValue(index, CameraStats.BurstInterval);
  154. hr = RootProps.DefineProperty(&index, WIA_DPC_BURST_NUMBER, WIA_DPC_BURST_NUMBER_STR,
  155. WIA_PROP_RW, WIA_PROP_NONE);
  156. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  157. RootProps.SetCurrentValue(index, CameraStats.BurstNumber);
  158. hr = RootProps.DefineProperty(&index, WIA_DPC_EFFECT_MODE, WIA_DPC_EFFECT_MODE_STR,
  159. WIA_PROP_RW, WIA_PROP_NONE);
  160. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  161. RootProps.SetCurrentValue(index, CameraStats.EffectMode);
  162. hr = RootProps.DefineProperty(&index, WIA_DPC_DIGITAL_ZOOM, WIA_DPC_DIGITAL_ZOOM_STR,
  163. WIA_PROP_RW, WIA_PROP_NONE);
  164. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  165. RootProps.SetCurrentValue(index, CameraStats.DigitalZoom);
  166. hr = RootProps.DefineProperty(&index, WIA_DPC_SHARPNESS, WIA_DPC_SHARPNESS_STR,
  167. WIA_PROP_RW, WIA_PROP_NONE);
  168. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  169. RootProps.SetCurrentValue(index, CameraStats.Sharpness);
  170. hr = RootProps.DefineProperty(&index, WIA_DPC_CONTRAST, WIA_DPC_CONTRAST_STR,
  171. WIA_PROP_RW, WIA_PROP_NONE);
  172. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  173. RootProps.SetCurrentValue(index, CameraStats.Constrast);
  174. hr = RootProps.DefineProperty(&index, WIA_DPC_CAPTURE_MODE, WIA_DPC_CAPTURE_MODE_STR,
  175. WIA_PROP_RW, WIA_PROP_NONE);
  176. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  177. RootProps.SetCurrentValue(index, CameraStats.CaptureMode);
  178. hr = RootProps.DefineProperty(&index, WIA_DPC_CAPTURE_DELAY, WIA_DPC_CAPTURE_DELAY_STR,
  179. WIA_PROP_RW, WIA_PROP_NONE);
  180. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  181. RootProps.SetCurrentValue(index, CameraStats.CaptureDelay);
  182. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_INDEX, WIA_DPC_EXPOSURE_INDEX_STR,
  183. WIA_PROP_RW, WIA_PROP_NONE);
  184. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  185. RootProps.SetCurrentValue(index, CameraStats.ExposureIndex);
  186. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_METERING_MODE, WIA_DPC_EXPOSURE_METERING_MODE_STR,
  187. WIA_PROP_RW, WIA_PROP_NONE);
  188. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  189. RootProps.SetCurrentValue(index, CameraStats.ExposureMeteringMode);
  190. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_METERING_MODE, WIA_DPC_FOCUS_METERING_MODE_STR,
  191. WIA_PROP_RW, WIA_PROP_NONE);
  192. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  193. RootProps.SetCurrentValue(index, CameraStats.FocusMeteringMode);
  194. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_DISTANCE, WIA_DPC_FOCUS_DISTANCE_STR,
  195. WIA_PROP_RW, WIA_PROP_NONE);
  196. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  197. RootProps.SetCurrentValue(index, CameraStats.FocusDistance);
  198. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCAL_LENGTH, WIA_DPC_FOCAL_LENGTH_STR,
  199. WIA_PROP_RW, WIA_PROP_NONE);
  200. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  201. RootProps.SetCurrentValue(index, CameraStats.FocalLength);
  202. hr = RootProps.DefineProperty(&index, WIA_DPC_RGBGAIN, WIA_DPC_RGBGAIN_STR,
  203. WIA_PROP_RW, WIA_PROP_NONE);
  204. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  205. RootProps.SetCurrentValue(index, CameraStats.RGBGain);
  206. hr = RootProps.DefineProperty(&index, WIA_DPC_WHITE_BALANCE, WIA_DPC_WHITE_BALANCE_STR,
  207. WIA_PROP_RW, WIA_PROP_NONE);
  208. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "DefineProperty failed");
  209. RootProps.SetCurrentValue(index, CameraStats.WhiteBalance);
  210. #endif // DEADCODE
  211. //
  212. // TODO: Add other optional properties that your device supports here
  213. //
  214. // Last step: send all the properties to WIA
  215. hr = RootProps.SendToWia(pWiasContext);
  216. REQUIRE_SUCCESS(hr, "BuildRootItemProperties", "SendToWia failed");
  217. Cleanup:
  218. if (bstrFirmwareVer)
  219. SysFreeString(bstrFirmwareVer);
  220. return hr;
  221. }
  222. /**************************************************************************\
  223. * ReadRootItemProperties
  224. *
  225. * Update the properties for the root item.
  226. *
  227. * Arguments:
  228. *
  229. * pWiasContext - WIA service context
  230. *
  231. \**************************************************************************/
  232. HRESULT
  233. CWiaCameraDevice::ReadRootItemProperties(
  234. BYTE *pWiasContext,
  235. LONG NumPropSpecs,
  236. const PROPSPEC *pPropSpecs
  237. )
  238. {
  239. DBG_FN("CWiaCameraDevice::ReadRootItemProperties");
  240. HRESULT hr = S_OK;
  241. REQUIRE_ARGS(!NumPropSpecs || !pPropSpecs, hr, "ReadRootItemProperties");
  242. //
  243. // Loop through all of the PropSpecs
  244. //
  245. for (int count = 0; count < NumPropSpecs; count++)
  246. {
  247. PROPID propId = pPropSpecs[count].propid;
  248. switch (propId)
  249. {
  250. case WIA_DPC_PICTURES_TAKEN:
  251. hr = wiasWritePropLong(pWiasContext, WIA_DPC_PICTURES_TAKEN, m_pDeviceInfo->lPicturesTaken);
  252. break;
  253. case WIA_DPC_PICTURES_REMAINING:
  254. hr = wiasWritePropLong(pWiasContext, WIA_DPC_PICTURES_REMAINING, m_pDeviceInfo->lPicturesRemaining);
  255. break;
  256. default:
  257. break;
  258. }
  259. REQUIRE_SUCCESS(hr, "ReadRootItemProperties", "wiasWritePropLong failed");
  260. }
  261. Cleanup:
  262. return hr;
  263. }