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.

66 lines
1.9 KiB

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