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.

67 lines
1.8 KiB

  1. #ifndef __DEVLIST_H_INCLUDED
  2. #define __DEVLIST_H_INCLUDED
  3. #include <windows.h>
  4. #include <sti.h>
  5. #include "proparry.h"
  6. #include "pshelper.h"
  7. typedef CComPtr<IWiaPropertyStorage> CDeviceListType;
  8. class CDeviceList : public CSimpleDynamicArray<CDeviceListType>
  9. {
  10. public:
  11. CDeviceList( IWiaDevMgr *pIWiaDevMgr=NULL, LONG nDeviceTypes=StiDeviceTypeDefault, LONG nFlags=0 )
  12. {
  13. Initialize( pIWiaDevMgr, nDeviceTypes, nFlags );
  14. }
  15. CDeviceList( const CDeviceList &other )
  16. {
  17. Append(other);
  18. }
  19. const CDeviceList &operator=( const CDeviceList &other )
  20. {
  21. Destroy();
  22. Append(other);
  23. return *this;
  24. }
  25. virtual ~CDeviceList(void)
  26. {
  27. }
  28. bool Initialize( IWiaDevMgr *pIWiaDevMgr, LONG nDeviceTypes, LONG nFlags=0 )
  29. {
  30. Destroy();
  31. if (!pIWiaDevMgr)
  32. return false;
  33. CComPtr<IEnumWIA_DEV_INFO> pIEnumWIA_DEV_INFO;
  34. HRESULT hr = pIWiaDevMgr->EnumDeviceInfo( nFlags, &pIEnumWIA_DEV_INFO );
  35. if (SUCCEEDED(hr))
  36. {
  37. ULONG ulFetched;
  38. CComPtr<IWiaPropertyStorage> pIWiaPropertyStorage;
  39. while ((hr = pIEnumWIA_DEV_INFO->Next(1,&pIWiaPropertyStorage,&ulFetched)) == S_OK)
  40. {
  41. LONG nDeviceType;
  42. if (!PropStorageHelpers::GetProperty( pIWiaPropertyStorage, WIA_DIP_DEV_TYPE, nDeviceType ))
  43. {
  44. // An error occurred
  45. return false;
  46. }
  47. if (nDeviceTypes == StiDeviceTypeDefault || (nDeviceTypes == GET_STIDEVICE_TYPE(nDeviceType)))
  48. {
  49. Append(pIWiaPropertyStorage);
  50. }
  51. pIWiaPropertyStorage.Release();
  52. }
  53. }
  54. else
  55. {
  56. return false;
  57. }
  58. return true;
  59. }
  60. };
  61. #endif