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.

176 lines
6.0 KiB

  1. #ifndef __WIADEV_H_
  2. #define __WIADEV_H_
  3. typedef HRESULT (CALLBACK *PFNDEVICEEVENTCALLBACK)(LONG lEvent, LPARAM lParam);
  4. typedef HRESULT (CALLBACK *PFNLOADIMAGECALLBACK)(LONG lMessage,
  5. LONG lStatus,
  6. LONG lPercentComplete,
  7. LONG lOffset,
  8. LONG Length,
  9. BYTE *pData
  10. );
  11. //
  12. // structure definitions
  13. //
  14. typedef struct tagCAPVALUES {
  15. LONG xResolution; // x-resolution
  16. LONG yResolution; // y-resolution
  17. LONG xPos; // x position (selection window)
  18. LONG yPos; // y position (selection window)
  19. LONG xExtent; // x extent (selection window)
  20. LONG yExtent; // y extent (selection window)
  21. LONG DataType; // Data Type, (BW,GRAY,RGB)
  22. }CAPVALUES, *PCAPVALUES;
  23. typedef struct tagBasicInfo
  24. {
  25. TW_UINT32 Size; // structure size
  26. TW_UINT32 xOpticalRes; // x optical resolution in DPI
  27. TW_UINT32 yOpticalRes; // y optical resolution in DPI
  28. TW_UINT32 xBedSize; // Scan bed size in 1000th Inches
  29. TW_UINT32 yBedSize; // Scan bed size in 1000th Inches
  30. TW_UINT32 FeederCaps; // document handling capability
  31. }BASIC_INFO, *PBASIC_INFO;
  32. //
  33. // WIA event callback class definition
  34. //
  35. class CWiaEventCallback : public IWiaEventCallback {
  36. public:
  37. CWiaEventCallback()
  38. {
  39. m_Ref = 0;
  40. m_pfnCallback = NULL;
  41. m_CallbackParam = (LPARAM)0;
  42. }
  43. ~CWiaEventCallback()
  44. {
  45. }
  46. HRESULT Initialize(PFNDEVICEEVENTCALLBACK pCallback, LPARAM lParam)
  47. {
  48. if (!pCallback)
  49. return E_INVALIDARG;
  50. m_pfnCallback = pCallback;
  51. m_CallbackParam = lParam;
  52. return S_OK;
  53. }
  54. //
  55. // IUnknown interface
  56. //
  57. STDMETHODIMP_(ULONG) AddRef()
  58. {
  59. InterlockedIncrement((LONG*)&m_Ref);
  60. return m_Ref;
  61. }
  62. STDMETHODIMP_(ULONG) Release()
  63. {
  64. if (!InterlockedDecrement((LONG*)&m_Ref)) {
  65. m_Ref++;
  66. delete this;
  67. return(ULONG) 0;
  68. }
  69. return m_Ref;
  70. }
  71. STDMETHODIMP QueryInterface(REFIID iid, void **ppv)
  72. {
  73. if (!ppv)
  74. return E_INVALIDARG;
  75. *ppv = NULL;
  76. if (IID_IUnknown == iid) {
  77. *ppv = (IUnknown*)this;
  78. AddRef();
  79. } else if (IID_IWiaEventCallback == iid) {
  80. *ppv = (IWiaEventCallback*)this;
  81. AddRef();
  82. return S_OK;
  83. }
  84. return E_NOINTERFACE;
  85. }
  86. //
  87. // IWiaEventCallback interface
  88. //
  89. STDMETHODIMP ImageEventCallback(const GUID *pEventGuid,
  90. BSTR bstrEventDescription,
  91. BSTR bstrDeviceId,
  92. BSTR bstrDeviceDescription,
  93. DWORD dwDeviceType,
  94. BSTR bstrFullItemName,
  95. ULONG *pulEventType,
  96. ULONG ulReserved);
  97. private:
  98. ULONG m_Ref;
  99. TCHAR m_szDeviceID[MAX_PATH];
  100. PFNDEVICEEVENTCALLBACK m_pfnCallback;
  101. LPARAM m_CallbackParam;
  102. };
  103. //
  104. // WIA device class definition
  105. //
  106. class CWiaDevice {
  107. public:
  108. CWiaDevice()
  109. {
  110. m_pRootItem = NULL;
  111. m_ImageItemArray = NULL;
  112. m_NumImageItems = 0;
  113. memset(m_szDeviceName,0,sizeof(m_szDeviceName));
  114. memset(m_szDeviceDesc,0,sizeof(m_szDeviceDesc));
  115. memset(m_szDeviceVendorDesc,0,sizeof(m_szDeviceVendorDesc));
  116. memset(m_szDeviceID,0,sizeof(m_szDeviceID));
  117. }
  118. virtual ~CWiaDevice()
  119. {
  120. }
  121. LPCTSTR GetDeviceId() const
  122. {
  123. return m_szDeviceID;
  124. }
  125. virtual HRESULT Initialize(LPCTSTR DeviceId);
  126. virtual HRESULT Open(PFNDEVICEEVENTCALLBACK pEventCallback,LPARAM lParam);
  127. virtual HRESULT Close();
  128. virtual HRESULT AcquireImages(HWND hwndOwner, BOOL ShowUI);
  129. virtual HRESULT LoadImage(IWiaItem *pIWiaItem, GUID guidFormatID,IWiaDataCallback *pIDataCB);
  130. virtual HRESULT LoadThumbnail(IWiaItem *pIWiaItem, HGLOBAL *phThumbnail,ULONG *pThumbnailSize);
  131. virtual HRESULT LoadImageToDisk(IWiaItem *pIWiaItem,CHAR *pFileName, GUID guidFormatID,IWiaDataCallback *pIDataCB);
  132. HRESULT GetImageInfo(IWiaItem *pIWiaItem, PMEMORY_TRANSFER_INFO pImageInfo);
  133. HRESULT GetThumbnailImageInfo(IWiaItem *pIWiaItem, PMEMORY_TRANSFER_INFO pImageInfo);
  134. HRESULT GetImageRect(IWiaItem *pIWiaItem, LPRECT pRect);
  135. HRESULT GetThumbnailRect(IWiaItem *pIWiaItem, LPRECT pRect);
  136. HRESULT GetDeviceName(LPTSTR Name, UINT NameSize, UINT *pActualSize);
  137. HRESULT GetDeviceDesc(LPTSTR Desc, UINT DescSize, UINT *pActualSize);
  138. HRESULT GetDeviceVendorName(LPTSTR Name, UINT NameSize, UINT *pActualSize);
  139. HRESULT GetDeviceFamilyName(LPTSTR Name, UINT NameSize, UINT *pActualSize);
  140. HRESULT FreeAcquiredImages();
  141. HRESULT EnumAcquiredImage(DWORD Index, IWiaItem **ppIWiaItem);
  142. HRESULT GetNumAcquiredImages(LONG *plNumImages);
  143. HRESULT GetAcquiredImageList(LONG lBufferSize, IWiaItem **ppIWiaItem, LONG *plActualSize);
  144. HRESULT GetBasicScannerInfo(PBASIC_INFO pBasicInfo);
  145. BOOL TwainCapabilityPassThrough();
  146. protected:
  147. HRESULT CollectImageItems(IWiaItem *pStartItem, IWiaItem **ImageItemList,
  148. DWORD ImageItemListSize, DWORD *pCount);
  149. TCHAR m_szDeviceID[MAX_PATH];
  150. IWiaItem *m_pRootItem;
  151. IWiaItem **m_ImageItemArray;
  152. LONG m_NumImageItems;
  153. CWiaEventCallback m_EventCallback;
  154. TCHAR m_szDeviceName[MAX_PATH];
  155. TCHAR m_szDeviceDesc[MAX_PATH];
  156. TCHAR m_szDeviceVendorDesc[MAX_PATH];
  157. };
  158. #endif // #ifndef __WIADEV_H_