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.

559 lines
22 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #if defined(DBG)
  4. WIA_PROPID_TO_NAME g_wiaPropIdToName[] =
  5. {
  6. { WIA_DIP_DEV_ID, WIA_DIP_DEV_ID_STR },
  7. { WIA_DIP_VEND_DESC, WIA_DIP_VEND_DESC_STR },
  8. { WIA_DIP_DEV_DESC, WIA_DIP_DEV_DESC_STR },
  9. { WIA_DIP_DEV_TYPE, WIA_DIP_DEV_TYPE_STR },
  10. { WIA_DIP_PORT_NAME, WIA_DIP_PORT_NAME_STR },
  11. { WIA_DIP_DEV_NAME, WIA_DIP_DEV_NAME_STR },
  12. { WIA_DIP_SERVER_NAME, WIA_DIP_SERVER_NAME_STR },
  13. { WIA_DIP_REMOTE_DEV_ID, WIA_DIP_REMOTE_DEV_ID_STR },
  14. { WIA_DIP_UI_CLSID, WIA_DIP_UI_CLSID_STR },
  15. { WIA_DIP_HW_CONFIG, WIA_DIP_HW_CONFIG_STR },
  16. { WIA_DIP_BAUDRATE, WIA_DIP_BAUDRATE_STR },
  17. { WIA_DIP_STI_GEN_CAPABILITIES, WIA_DIP_STI_GEN_CAPABILITIES_STR },
  18. { WIA_DPA_FIRMWARE_VERSION, WIA_DPA_FIRMWARE_VERSION_STR },
  19. { WIA_DPA_CONNECT_STATUS, WIA_DPA_CONNECT_STATUS_STR },
  20. { WIA_DPA_DEVICE_TIME, WIA_DPA_DEVICE_TIME_STR },
  21. { WIA_DPC_PICTURES_TAKEN, WIA_DPC_PICTURES_TAKEN_STR },
  22. { WIA_DPC_PICTURES_REMAINING, WIA_DPC_PICTURES_REMAINING_STR },
  23. { WIA_DPC_EXPOSURE_MODE, WIA_DPC_EXPOSURE_MODE_STR },
  24. { WIA_DPC_EXPOSURE_COMP, WIA_DPC_EXPOSURE_COMP_STR },
  25. { WIA_DPC_EXPOSURE_TIME, WIA_DPC_EXPOSURE_TIME_STR },
  26. { WIA_DPC_FNUMBER, WIA_DPC_FNUMBER_STR },
  27. { WIA_DPC_FLASH_MODE, WIA_DPC_FLASH_MODE_STR },
  28. { WIA_DPC_FOCUS_MODE, WIA_DPC_FOCUS_MODE_STR },
  29. { WIA_DPC_FOCUS_MANUAL_DIST, WIA_DPC_FOCUS_MANUAL_DIST_STR },
  30. { WIA_DPC_ZOOM_POSITION, WIA_DPC_ZOOM_POSITION_STR },
  31. { WIA_DPC_PAN_POSITION, WIA_DPC_PAN_POSITION_STR },
  32. { WIA_DPC_TILT_POSITION, WIA_DPC_TILT_POSITION_STR },
  33. { WIA_DPC_TIMER_MODE, WIA_DPC_TIMER_MODE_STR },
  34. { WIA_DPC_TIMER_VALUE, WIA_DPC_TIMER_VALUE_STR },
  35. { WIA_DPC_POWER_MODE, WIA_DPC_POWER_MODE_STR },
  36. { WIA_DPC_BATTERY_STATUS, WIA_DPC_BATTERY_STATUS_STR },
  37. { WIA_DPC_THUMB_WIDTH, WIA_DPC_THUMB_WIDTH_STR },
  38. { WIA_DPC_THUMB_HEIGHT, WIA_DPC_THUMB_HEIGHT_STR },
  39. { WIA_DPC_PICT_WIDTH, WIA_DPC_PICT_WIDTH_STR },
  40. { WIA_DPC_PICT_HEIGHT, WIA_DPC_PICT_HEIGHT_STR },
  41. { WIA_DPC_DIMENSION, WIA_DPC_DIMENSION_STR },
  42. { WIA_DPC_COMPRESSION_SETTING, WIA_DPC_COMPRESSION_SETTING_STR },
  43. { WIA_DPC_FOCUS_METERING_MODE, WIA_DPC_FOCUS_METERING_MODE_STR },
  44. { WIA_DPC_TIMELAPSE_INTERVAL, WIA_DPC_TIMELAPSE_INTERVAL_STR },
  45. { WIA_DPC_TIMELAPSE_NUMBER, WIA_DPC_TIMELAPSE_NUMBER_STR },
  46. { WIA_DPC_BURST_INTERVAL, WIA_DPC_BURST_INTERVAL_STR },
  47. { WIA_DPC_BURST_NUMBER, WIA_DPC_BURST_NUMBER_STR },
  48. { WIA_DPC_EFFECT_MODE, WIA_DPC_EFFECT_MODE_STR },
  49. { WIA_DPC_DIGITAL_ZOOM, WIA_DPC_DIGITAL_ZOOM_STR },
  50. { WIA_DPC_SHARPNESS, WIA_DPC_SHARPNESS_STR },
  51. { WIA_DPC_CONTRAST, WIA_DPC_CONTRAST_STR },
  52. { WIA_DPC_CAPTURE_MODE, WIA_DPC_CAPTURE_MODE_STR },
  53. { WIA_DPC_CAPTURE_DELAY, WIA_DPC_CAPTURE_DELAY_STR },
  54. { WIA_DPC_EXPOSURE_INDEX, WIA_DPC_EXPOSURE_INDEX_STR },
  55. { WIA_DPC_EXPOSURE_METERING_MODE, WIA_DPC_EXPOSURE_METERING_MODE_STR },
  56. { WIA_DPC_FOCUS_DISTANCE, WIA_DPC_FOCUS_DISTANCE_STR },
  57. { WIA_DPC_FOCAL_LENGTH, WIA_DPC_FOCAL_LENGTH_STR },
  58. { WIA_DPC_RGB_GAIN, WIA_DPC_RGB_GAIN_STR },
  59. { WIA_DPC_WHITE_BALANCE, WIA_DPC_WHITE_BALANCE_STR },
  60. { WIA_DPC_UPLOAD_URL, WIA_DPC_UPLOAD_URL_STR },
  61. { WIA_DPC_ARTIST, WIA_DPC_ARTIST_STR },
  62. { WIA_DPC_COPYRIGHT_INFO, WIA_DPC_COPYRIGHT_INFO_STR },
  63. { WIA_DPS_HORIZONTAL_BED_SIZE, WIA_DPS_HORIZONTAL_BED_SIZE_STR },
  64. { WIA_DPS_VERTICAL_BED_SIZE, WIA_DPS_VERTICAL_BED_SIZE_STR },
  65. { WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE, WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE_STR },
  66. { WIA_DPS_VERTICAL_SHEET_FEED_SIZE, WIA_DPS_VERTICAL_SHEET_FEED_SIZE_STR },
  67. { WIA_DPS_SHEET_FEEDER_REGISTRATION, WIA_DPS_SHEET_FEEDER_REGISTRATION_STR },
  68. { WIA_DPS_HORIZONTAL_BED_REGISTRATION, WIA_DPS_HORIZONTAL_BED_REGISTRATION_STR },
  69. { WIA_DPS_VERTICAL_BED_REGISTRATION, WIA_DPS_VERTICAL_BED_REGISTRATION_STR },
  70. { WIA_DPS_PLATEN_COLOR, WIA_DPS_PLATEN_COLOR_STR },
  71. { WIA_DPS_PAD_COLOR, WIA_DPS_PAD_COLOR_STR },
  72. { WIA_DPS_FILTER_SELECT, WIA_DPS_FILTER_SELECT_STR },
  73. { WIA_DPS_DITHER_SELECT, WIA_DPS_DITHER_SELECT_STR },
  74. { WIA_DPS_DITHER_PATTERN_DATA, WIA_DPS_DITHER_PATTERN_DATA_STR },
  75. { WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES, WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES_STR },
  76. { WIA_DPS_DOCUMENT_HANDLING_STATUS, WIA_DPS_DOCUMENT_HANDLING_STATUS_STR },
  77. { WIA_DPS_DOCUMENT_HANDLING_SELECT, WIA_DPS_DOCUMENT_HANDLING_SELECT_STR },
  78. { WIA_DPS_DOCUMENT_HANDLING_CAPACITY, WIA_DPS_DOCUMENT_HANDLING_CAPACITY_STR },
  79. { WIA_DPS_OPTICAL_XRES, WIA_DPS_OPTICAL_XRES_STR },
  80. { WIA_DPS_OPTICAL_YRES, WIA_DPS_OPTICAL_YRES_STR },
  81. { WIA_DPS_ENDORSER_CHARACTERS, WIA_DPS_ENDORSER_CHARACTERS_STR },
  82. { WIA_DPS_ENDORSER_STRING, WIA_DPS_ENDORSER_STRING_STR },
  83. { WIA_DPS_SCAN_AHEAD_PAGES, WIA_DPS_SCAN_AHEAD_PAGES_STR },
  84. { WIA_DPS_MAX_SCAN_TIME, WIA_DPS_MAX_SCAN_TIME_STR },
  85. { WIA_DPS_PAGES, WIA_DPS_PAGES_STR },
  86. { WIA_DPS_PAGE_SIZE, WIA_DPS_PAGE_SIZE_STR },
  87. { WIA_DPS_PAGE_WIDTH, WIA_DPS_PAGE_WIDTH_STR },
  88. { WIA_DPS_PAGE_HEIGHT, WIA_DPS_PAGE_HEIGHT_STR },
  89. { WIA_DPS_PREVIEW, WIA_DPS_PREVIEW_STR },
  90. { WIA_DPS_TRANSPARENCY, WIA_DPS_TRANSPARENCY_STR },
  91. { WIA_DPS_TRANSPARENCY_SELECT, WIA_DPS_TRANSPARENCY_SELECT_STR },
  92. { WIA_DPS_SHOW_PREVIEW_CONTROL, WIA_DPS_SHOW_PREVIEW_CONTROL_STR },
  93. { WIA_DPS_MIN_HORIZONTAL_SHEET_FEED_SIZE, WIA_DPS_MIN_HORIZONTAL_SHEET_FEED_SIZE_STR },
  94. { WIA_DPS_MIN_VERTICAL_SHEET_FEED_SIZE, WIA_DPS_MIN_VERTICAL_SHEET_FEED_SIZE_STR },
  95. { WIA_DPF_MOUNT_POINT, WIA_DPF_MOUNT_POINT_STR },
  96. { WIA_DPV_LAST_PICTURE_TAKEN, WIA_DPV_LAST_PICTURE_TAKEN_STR },
  97. { WIA_DPV_IMAGES_DIRECTORY, WIA_DPV_IMAGES_DIRECTORY_STR },
  98. { WIA_DPV_DSHOW_DEVICE_PATH, WIA_DPV_DSHOW_DEVICE_PATH_STR },
  99. { WIA_IPA_ITEM_NAME, WIA_IPA_ITEM_NAME_STR },
  100. { WIA_IPA_FULL_ITEM_NAME, WIA_IPA_FULL_ITEM_NAME_STR },
  101. { WIA_IPA_ITEM_TIME, WIA_IPA_ITEM_TIME_STR },
  102. { WIA_IPA_ITEM_FLAGS, WIA_IPA_ITEM_FLAGS_STR },
  103. { WIA_IPA_ACCESS_RIGHTS, WIA_IPA_ACCESS_RIGHTS_STR },
  104. { WIA_IPA_DATATYPE, WIA_IPA_DATATYPE_STR },
  105. { WIA_IPA_DEPTH, WIA_IPA_DEPTH_STR },
  106. { WIA_IPA_PREFERRED_FORMAT, WIA_IPA_PREFERRED_FORMAT_STR },
  107. { WIA_IPA_FORMAT, WIA_IPA_FORMAT_STR },
  108. { WIA_IPA_COMPRESSION, WIA_IPA_COMPRESSION_STR },
  109. { WIA_IPA_TYMED, WIA_IPA_TYMED_STR },
  110. { WIA_IPA_CHANNELS_PER_PIXEL, WIA_IPA_CHANNELS_PER_PIXEL_STR },
  111. { WIA_IPA_BITS_PER_CHANNEL, WIA_IPA_BITS_PER_CHANNEL_STR },
  112. { WIA_IPA_PLANAR, WIA_IPA_PLANAR_STR },
  113. { WIA_IPA_PIXELS_PER_LINE, WIA_IPA_PIXELS_PER_LINE_STR },
  114. { WIA_IPA_BYTES_PER_LINE, WIA_IPA_BYTES_PER_LINE_STR },
  115. { WIA_IPA_NUMBER_OF_LINES, WIA_IPA_NUMBER_OF_LINES_STR },
  116. { WIA_IPA_GAMMA_CURVES, WIA_IPA_GAMMA_CURVES_STR },
  117. { WIA_IPA_ITEM_SIZE, WIA_IPA_ITEM_SIZE_STR },
  118. { WIA_IPA_COLOR_PROFILE, WIA_IPA_COLOR_PROFILE_STR },
  119. { WIA_IPA_MIN_BUFFER_SIZE, WIA_IPA_MIN_BUFFER_SIZE_STR },
  120. { WIA_IPA_REGION_TYPE, WIA_IPA_REGION_TYPE_STR },
  121. { WIA_IPA_ICM_PROFILE_NAME, WIA_IPA_ICM_PROFILE_NAME_STR },
  122. { WIA_IPA_APP_COLOR_MAPPING, WIA_IPA_APP_COLOR_MAPPING_STR },
  123. { WIA_IPA_PROP_STREAM_COMPAT_ID, WIA_IPA_PROP_STREAM_COMPAT_ID_STR },
  124. { WIA_IPA_FILENAME_EXTENSION, WIA_IPA_FILENAME_EXTENSION_STR },
  125. { WIA_IPA_SUPPRESS_PROPERTY_PAGE, WIA_IPA_SUPPRESS_PROPERTY_PAGE_STR },
  126. { WIA_IPC_THUMBNAIL, WIA_IPC_THUMBNAIL_STR },
  127. { WIA_IPC_THUMB_WIDTH, WIA_IPC_THUMB_WIDTH_STR },
  128. { WIA_IPC_THUMB_HEIGHT, WIA_IPC_THUMB_HEIGHT_STR },
  129. { WIA_IPC_AUDIO_AVAILABLE, WIA_IPC_AUDIO_AVAILABLE_STR },
  130. { WIA_IPC_AUDIO_DATA_FORMAT, WIA_IPC_AUDIO_DATA_FORMAT_STR },
  131. { WIA_IPC_AUDIO_DATA, WIA_IPC_AUDIO_DATA_STR },
  132. { WIA_IPC_NUM_PICT_PER_ROW, WIA_IPC_NUM_PICT_PER_ROW_STR },
  133. { WIA_IPC_SEQUENCE, WIA_IPC_SEQUENCE_STR },
  134. { WIA_IPC_TIMEDELAY, WIA_IPC_TIMEDELAY_STR },
  135. { WIA_IPS_CUR_INTENT, WIA_IPS_CUR_INTENT_STR },
  136. { WIA_IPS_XRES, WIA_IPS_XRES_STR },
  137. { WIA_IPS_YRES, WIA_IPS_YRES_STR },
  138. { WIA_IPS_XPOS, WIA_IPS_XPOS_STR },
  139. { WIA_IPS_YPOS, WIA_IPS_YPOS_STR },
  140. { WIA_IPS_XEXTENT, WIA_IPS_XEXTENT_STR },
  141. { WIA_IPS_YEXTENT, WIA_IPS_YEXTENT_STR },
  142. { WIA_IPS_PHOTOMETRIC_INTERP, WIA_IPS_PHOTOMETRIC_INTERP_STR },
  143. { WIA_IPS_BRIGHTNESS, WIA_IPS_BRIGHTNESS_STR },
  144. { WIA_IPS_CONTRAST, WIA_IPS_CONTRAST_STR },
  145. { WIA_IPS_ORIENTATION, WIA_IPS_ORIENTATION_STR },
  146. { WIA_IPS_ROTATION, WIA_IPS_ROTATION_STR },
  147. { WIA_IPS_MIRROR, WIA_IPS_MIRROR_STR },
  148. { WIA_IPS_THRESHOLD, WIA_IPS_THRESHOLD_STR },
  149. { WIA_IPS_INVERT, WIA_IPS_INVERT_STR },
  150. { WIA_IPS_WARM_UP_TIME, WIA_IPS_WARM_UP_TIME_STR },
  151. {0, L"Not a WIA property"}
  152. };
  153. #endif
  154. namespace PropStorageHelpers
  155. {
  156. CPropertyId::CPropertyId(void)
  157. : m_strPropId(L""), m_nPropId(0), m_bIsStringPropId(false)
  158. {
  159. }
  160. CPropertyId::CPropertyId( const CSimpleStringWide &strPropId )
  161. : m_strPropId(strPropId), m_nPropId(0), m_bIsStringPropId(true)
  162. {
  163. }
  164. CPropertyId::CPropertyId( PROPID propId )
  165. : m_strPropId(L""), m_nPropId(propId), m_bIsStringPropId(false)
  166. {
  167. }
  168. CPropertyId::CPropertyId( const CPropertyId &other )
  169. : m_strPropId(other.PropIdString()), m_nPropId(other.PropIdNumber()), m_bIsStringPropId(other.IsString())
  170. {
  171. }
  172. CPropertyId::~CPropertyId(void)
  173. {
  174. }
  175. CPropertyId &CPropertyId::operator=( const CPropertyId &other )
  176. {
  177. if (this != &other)
  178. {
  179. m_strPropId = other.PropIdString();
  180. m_nPropId = other.PropIdNumber();
  181. m_bIsStringPropId = other.IsString();
  182. }
  183. return(*this);
  184. }
  185. CSimpleStringWide CPropertyId::PropIdString(void) const
  186. {
  187. return(m_strPropId);
  188. }
  189. PROPID CPropertyId::PropIdNumber(void) const
  190. {
  191. return(m_nPropId);
  192. }
  193. bool CPropertyId::IsString(void) const
  194. {
  195. return(m_bIsStringPropId);
  196. }
  197. CSimpleString PropertyName( const CPropertyId &propertyName )
  198. {
  199. #if defined(DBG)
  200. if (propertyName.IsString())
  201. {
  202. return CSimpleStringConvert::NaturalString(propertyName.PropIdString());
  203. }
  204. for (int i=0;g_wiaPropIdToName[i].propid;i++)
  205. {
  206. if (propertyName.PropIdNumber() == g_wiaPropIdToName[i].propid)
  207. {
  208. return CSimpleStringConvert::NaturalString(CSimpleStringWide(g_wiaPropIdToName[i].pszName));
  209. }
  210. }
  211. return CSimpleString().Format( TEXT("Unknown property %d"), propertyName.PropIdNumber() );
  212. #endif
  213. return TEXT("");
  214. }
  215. bool SetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, PROPVARIANT &pv, PROPID nNameFirst )
  216. {
  217. WIA_PUSH_FUNCTION((TEXT("PropStorageHelpers::SetProperty(\"%s\")"), PropertyName(propertyName).String() ));
  218. PROPSPEC ps = {0};
  219. if (propertyName.IsString())
  220. {
  221. ps.ulKind = PRSPEC_LPWSTR;
  222. ps.lpwstr = const_cast<LPWSTR>(propertyName.PropIdString().String());
  223. }
  224. else
  225. {
  226. ps.ulKind = PRSPEC_PROPID;
  227. ps.propid = propertyName.PropIdNumber();
  228. }
  229. CComPtr<IWiaPropertyStorage> pIWiaPropertyStorage;
  230. HRESULT hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage);
  231. if (FAILED(hr))
  232. {
  233. return(false);
  234. }
  235. hr = pIWiaPropertyStorage->WriteMultiple( 1, &ps, &pv, nNameFirst );
  236. return(SUCCEEDED(hr));
  237. }
  238. bool SetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, LONG nValue, PROPID nNameFirst )
  239. {
  240. PROPVARIANT pv = {0};
  241. pv.vt = VT_I4;
  242. pv.lVal = nValue;
  243. return(SetProperty( pIUnknown, propertyName, pv, nNameFirst ));
  244. }
  245. bool SetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, const GUID &guidValue, PROPID nNameFirst )
  246. {
  247. PROPVARIANT pv = {0};
  248. pv.vt = VT_CLSID;
  249. pv.puuid = const_cast<GUID*>(&guidValue);
  250. return(SetProperty( pIUnknown, propertyName, pv, nNameFirst ));
  251. }
  252. bool GetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, PROPVARIANT &pPropVar )
  253. {
  254. WIA_PUSH_FUNCTION((TEXT("PropStorageHelpers::GetProperty(\"%s\")"), PropertyName(propertyName).String() ));
  255. ZeroMemory(&pPropVar,sizeof(pPropVar));
  256. if (pIUnknown)
  257. {
  258. PROPSPEC ps = {0};
  259. if (propertyName.IsString())
  260. {
  261. ps.ulKind = PRSPEC_LPWSTR;
  262. ps.lpwstr = const_cast<LPWSTR>(propertyName.PropIdString().String());
  263. }
  264. else
  265. {
  266. ps.ulKind = PRSPEC_PROPID;
  267. ps.propid = propertyName.PropIdNumber();
  268. }
  269. CComPtr<IWiaPropertyStorage> pIWiaPropertyStorage;
  270. HRESULT hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage);
  271. if (FAILED(hr))
  272. {
  273. WIA_PRINTHRESULT((hr,TEXT("GetProperty: pIUnknown->QueryInterface failed:")));
  274. return(false);
  275. }
  276. hr = pIWiaPropertyStorage->ReadMultiple( 1, &ps, &pPropVar );
  277. if (FAILED(hr) || S_FALSE==hr)
  278. {
  279. WIA_PRINTHRESULT((hr,TEXT("GetProperty: pIUnknown->ReadMultiple failed:")));
  280. return(false);
  281. }
  282. return(SUCCEEDED(hr));
  283. }
  284. else
  285. {
  286. WIA_ERROR((TEXT("GetProperty: pIUnknown is NULL")));
  287. return(false);
  288. }
  289. }
  290. bool GetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, CSimpleStringWide &strPropertyValue )
  291. {
  292. strPropertyValue = L"";
  293. PROPVARIANT pvPropValue;
  294. if (!GetProperty( pIUnknown, propertyName, pvPropValue ))
  295. {
  296. PropVariantClear(&pvPropValue);
  297. return(false);
  298. }
  299. if (VT_LPWSTR != pvPropValue.vt && VT_BSTR != pvPropValue.vt)
  300. {
  301. PropVariantClear(&pvPropValue);
  302. return(false);
  303. }
  304. strPropertyValue = pvPropValue.pwszVal;
  305. PropVariantClear(&pvPropValue);
  306. return(true);
  307. }
  308. bool GetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, LONG &nValue )
  309. {
  310. nValue = 0;
  311. PROPVARIANT pvPropValue;
  312. if (!GetProperty( pIUnknown, propertyName, pvPropValue ))
  313. {
  314. PropVariantClear(&pvPropValue);
  315. return(false);
  316. }
  317. if (VT_I4 != pvPropValue.vt && VT_UI4 != pvPropValue.vt)
  318. {
  319. WIA_ERROR((TEXT("GetProperty: Property value type must be VT_I4 or VT_UI4 and it was 0x%08X (%d)"),pvPropValue.vt,pvPropValue.vt));
  320. PropVariantClear(&pvPropValue);
  321. return(false);
  322. }
  323. nValue = pvPropValue.lVal;
  324. PropVariantClear(&pvPropValue);
  325. return(true);
  326. }
  327. bool GetProperty( IUnknown *pIUnknown, const CPropertyId &propertyName, GUID &guidValue )
  328. {
  329. guidValue = IID_NULL;
  330. PROPVARIANT pvPropValue;
  331. if (!GetProperty( pIUnknown, propertyName, pvPropValue ))
  332. {
  333. PropVariantClear(&pvPropValue);
  334. return(false);
  335. }
  336. if (VT_CLSID != pvPropValue.vt)
  337. {
  338. WIA_ERROR((TEXT("GetProperty: Property value type must be VT_I4 or VT_UI4 and it was 0x%08X (%d)"),pvPropValue.vt,pvPropValue.vt));
  339. PropVariantClear(&pvPropValue);
  340. return(false);
  341. }
  342. if (!pvPropValue.puuid)
  343. {
  344. WIA_ERROR((TEXT("GetProperty: NULL pvPropValue.puuid")));
  345. PropVariantClear(&pvPropValue);
  346. return(false);
  347. }
  348. guidValue = *(pvPropValue.puuid);
  349. PropVariantClear(&pvPropValue);
  350. return(true);
  351. }
  352. bool GetPropertyAttributes( IUnknown *pIUnknown, const CPropertyId &propertyName, ULONG &nAccessFlags, PROPVARIANT &pvAttributes )
  353. {
  354. WIA_PUSH_FUNCTION((TEXT("PropStorageHelpers::GetPropertyAttributes(\"%s\")"), PropertyName(propertyName).String() ));
  355. ZeroMemory( &pvAttributes, sizeof(pvAttributes) );
  356. if (!pIUnknown)
  357. {
  358. WIA_ERROR((TEXT("pIUnknown is NULL")));
  359. return false;
  360. }
  361. CComPtr<IWiaPropertyStorage> pIWiaPropertyStorage;
  362. HRESULT hr = pIUnknown->QueryInterface(IID_IWiaPropertyStorage, (void**)&pIWiaPropertyStorage);
  363. if (SUCCEEDED(hr))
  364. {
  365. PROPSPEC ps;
  366. if (propertyName.IsString())
  367. {
  368. ps.ulKind = PRSPEC_LPWSTR;
  369. ps.lpwstr = const_cast<LPWSTR>(propertyName.PropIdString().String());
  370. }
  371. else
  372. {
  373. ps.ulKind = PRSPEC_PROPID;
  374. ps.propid = propertyName.PropIdNumber();
  375. }
  376. hr = pIWiaPropertyStorage->GetPropertyAttributes( 1, &ps, &nAccessFlags, &pvAttributes );
  377. if (SUCCEEDED(hr))
  378. {
  379. hr = S_OK;
  380. }
  381. else
  382. {
  383. WIA_PRINTHRESULT((hr,TEXT("pIWiaPropertyStorage->GetPropertyAttributes failed")));
  384. }
  385. }
  386. else
  387. {
  388. WIA_PRINTHRESULT((hr,TEXT("pIUnknown->QueryInterface failed")));
  389. }
  390. WIA_PRINTHRESULT((hr,TEXT("PropStorageHelpers::GetPropertyAttributes is returning")));
  391. return (SUCCEEDED(hr) != FALSE);
  392. }
  393. bool GetPropertyAttributes( IUnknown *pIUnknown, const CPropertyId &propertyName, PROPVARIANT &pvAttributes )
  394. {
  395. ULONG nAccessFlags;
  396. bool bResult = GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes );
  397. return (bResult);
  398. }
  399. bool GetPropertyAccessFlags( IUnknown *pIUnknown, const CPropertyId &propertyName, ULONG &nAccessFlags )
  400. {
  401. PROPVARIANT pvAttributes;
  402. bool bResult = GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes );
  403. if (bResult)
  404. PropVariantClear(&pvAttributes);
  405. return (bResult);
  406. }
  407. bool IsReadOnlyProperty( IUnknown *pIUnknown, const CPropertyId &propertyName )
  408. {
  409. WIA_PUSH_FUNCTION((TEXT("PropStorageHelpers::IsReadOnlyProperty")));
  410. bool bResult = true;
  411. ULONG nAccessFlags = 0;
  412. if (GetPropertyAccessFlags(pIUnknown,propertyName,nAccessFlags))
  413. {
  414. WIA_TRACE((TEXT("nAccessFlags = %08X"),nAccessFlags));
  415. bResult = ((nAccessFlags & WIA_PROP_WRITE) == 0);
  416. WIA_TRACE((TEXT("bResult = %d"),bResult));
  417. }
  418. return bResult;
  419. }
  420. bool GetPropertyRange( IUnknown *pIUnknown, const CPropertyId &propertyName, CPropertyRange &propertyRange )
  421. {
  422. ZeroMemory( &propertyRange, sizeof(propertyRange) );
  423. PROPVARIANT pvAttributes;
  424. ULONG nAccessFlags;
  425. bool bResult = false;
  426. if (GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes ))
  427. {
  428. if ((WIA_PROP_RANGE & nAccessFlags) &&
  429. (pvAttributes.vt & VT_VECTOR) &&
  430. ((pvAttributes.vt & VT_I4) || (pvAttributes.vt & VT_UI4)))
  431. {
  432. propertyRange.nMin = (LONG)pvAttributes.caul.pElems[WIA_RANGE_MIN];
  433. propertyRange.nMax = (LONG)pvAttributes.caul.pElems[WIA_RANGE_MAX];
  434. propertyRange.nStep = (LONG)pvAttributes.caul.pElems[WIA_RANGE_STEP];
  435. bResult = true;
  436. }
  437. else
  438. {
  439. WIA_ERROR((TEXT("\"%s\" is not a WIA_PROP_RANGE value"), PropertyName(propertyName).String() ));
  440. }
  441. PropVariantClear(&pvAttributes);
  442. }
  443. return bResult;
  444. }
  445. bool GetPropertyList( IUnknown *pIUnknown, const CPropertyId &propertyName, CSimpleDynamicArray<LONG> &aProp )
  446. {
  447. aProp.Destroy();
  448. PROPVARIANT pvAttributes;
  449. ULONG nAccessFlags;
  450. bool bResult = false;
  451. if (GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes ))
  452. {
  453. if ((WIA_PROP_LIST & nAccessFlags) &&
  454. (pvAttributes.vt & VT_VECTOR) &&
  455. ((pvAttributes.vt & VT_I4) || (pvAttributes.vt & VT_UI4)))
  456. {
  457. for (ULONG i=0;i<pvAttributes.cal.cElems - WIA_LIST_VALUES;i++)
  458. aProp.Append((LONG)pvAttributes.cal.pElems[WIA_LIST_VALUES + i]);
  459. bResult = true;
  460. }
  461. else
  462. {
  463. WIA_ERROR((TEXT("\"%s\" is not a WIA_PROP_LIST value"), PropertyName(propertyName).String() ));
  464. }
  465. PropVariantClear(&pvAttributes);
  466. }
  467. return bResult;
  468. }
  469. bool GetPropertyList( IUnknown *pIUnknown, const CPropertyId &propertyName, CSimpleDynamicArray<GUID> &aProp )
  470. {
  471. aProp.Destroy();
  472. PROPVARIANT pvAttributes;
  473. ULONG nAccessFlags;
  474. bool bResult = false;
  475. if (GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes ))
  476. {
  477. if ((WIA_PROP_LIST & nAccessFlags) &&
  478. (pvAttributes.vt & VT_VECTOR) &&
  479. (pvAttributes.vt & VT_CLSID))
  480. {
  481. for (ULONG i=0;i<pvAttributes.cal.cElems - WIA_LIST_VALUES;i++)
  482. aProp.Append(pvAttributes.cauuid.pElems[WIA_LIST_VALUES + i]);
  483. bResult = true;
  484. }
  485. else
  486. {
  487. WIA_ERROR((TEXT("\"%s\" is not a WIA_PROP_LIST value"), PropertyName(propertyName).String() ));
  488. }
  489. PropVariantClear(&pvAttributes);
  490. }
  491. return bResult;
  492. }
  493. bool GetPropertyFlags( IUnknown *pIUnknown, const CPropertyId &propertyName, LONG &nFlags )
  494. {
  495. WIA_PUSH_FUNCTION((TEXT("PropStorageHelpers::GetPropertyFlags(\"%s\")"), PropertyName(propertyName).String() ));
  496. nFlags = 0;
  497. PROPVARIANT pvAttributes;
  498. ULONG nAccessFlags;
  499. bool bResult = false;
  500. if (GetPropertyAttributes( pIUnknown, propertyName, nAccessFlags, pvAttributes ))
  501. {
  502. if (WIA_PROP_FLAG & nAccessFlags)
  503. {
  504. nFlags = pvAttributes.caul.pElems[WIA_FLAG_VALUES];
  505. WIA_TRACE((TEXT("nFlags = %08X"), nFlags ));
  506. bResult = true;
  507. }
  508. else
  509. {
  510. WIA_ERROR((TEXT("\"%s\" is not a WIA_PROP_FLAG value"), PropertyName(propertyName).String() ));
  511. }
  512. PropVariantClear(&pvAttributes);
  513. }
  514. else
  515. {
  516. WIA_ERROR((TEXT("GetPropertyAttributes failed")));
  517. }
  518. return bResult;
  519. }
  520. } // Namespace PropStorageHelpers