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.

260 lines
11 KiB

  1. /**************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: wiacam.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 18 July, 2000
  10. *
  11. * DESCRIPTION:
  12. *
  13. *
  14. ***************************************************************************/
  15. #pragma once
  16. //
  17. // Globals
  18. //
  19. extern HINSTANCE g_hInst; // DLL module instance
  20. //
  21. // Driver item context
  22. //
  23. typedef struct _ITEM_CONTEXT{
  24. MCAM_ITEM_INFO *pItemInfo; // Handle to the camera item
  25. BOOL bItemChanged; // Indicates the item has changed on the device
  26. LONG lNumFormatInfo; // Number of entries in format info array
  27. WIA_FORMAT_INFO *pFormatInfo; // Pointer to format info array
  28. } ITEM_CONTEXT, *PITEM_CONTEXT;
  29. //
  30. // Handy constants for common item types
  31. //
  32. const LONG ITEMTYPE_FILE = WiaItemTypeFile;
  33. const LONG ITEMTYPE_IMAGE = WiaItemTypeFile | WiaItemTypeImage;
  34. const LONG ITEMTYPE_AUDIO = WiaItemTypeFile | WiaItemTypeAudio;
  35. const LONG ITEMTYPE_VIDEO = WiaItemTypeFile | WiaItemTypeVideo;
  36. const LONG ITEMTYPE_FOLDER = WiaItemTypeFolder;
  37. const LONG ITEMTYPE_BURST = WiaItemTypeFolder | WiaItemTypeBurst;
  38. const LONG ITEMTYPE_HPAN = WiaItemTypeFolder | WiaItemTypeHPanorama;
  39. const LONG ITEMTYPE_VPAN = WiaItemTypeFolder | WiaItemTypeVPanorama;
  40. //
  41. // Minimum data call back transfer buffer size
  42. //
  43. const LONG MIN_BUFFER_SIZE = 0x8000;
  44. //
  45. // When doing a transfer and convert to BMP, this value
  46. // represents how much of the time is spent doing the
  47. // transfer of data from the device.
  48. //
  49. const LONG TRANSFER_PERCENT = 90;
  50. //
  51. // Base structure for supporting non-delegating IUnknown for contained objects
  52. //
  53. DECLARE_INTERFACE(INonDelegatingUnknown)
  54. {
  55. STDMETHOD (NonDelegatingQueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppv) PURE;
  56. STDMETHOD_(ULONG,NonDelegatingAddRef) (THIS) PURE;
  57. STDMETHOD_(ULONG,NonDelegatingRelease) (THIS) PURE;
  58. };
  59. //
  60. // Class definition for sample WIA scanner object
  61. //
  62. class CWiaCameraDevice : public IStiUSD, // STI USD interface
  63. public IWiaMiniDrv, // WIA Minidriver interface
  64. public INonDelegatingUnknown // NonDelegatingUnknown
  65. {
  66. public:
  67. /////////////////////////////////////////////////////////////////////////
  68. // Construction/Destruction Section //
  69. /////////////////////////////////////////////////////////////////////////
  70. CWiaCameraDevice(LPUNKNOWN punkOuter);
  71. ~CWiaCameraDevice();
  72. /////////////////////////////////////////////////////////////////////////
  73. // Standard COM Section //
  74. /////////////////////////////////////////////////////////////////////////
  75. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  76. STDMETHODIMP_(ULONG) AddRef( void);
  77. STDMETHODIMP_(ULONG) Release( void);
  78. /////////////////////////////////////////////////////////////////////////
  79. // IStiUSD Interface Section (for all WIA drivers) //
  80. /////////////////////////////////////////////////////////////////////////
  81. //
  82. // Methods for implementing the IStiUSD interface.
  83. //
  84. STDMETHODIMP Initialize(PSTIDEVICECONTROL pHelDcb, DWORD dwStiVersion, HKEY hParametersKey);
  85. STDMETHODIMP GetCapabilities(PSTI_USD_CAPS pDevCaps);
  86. STDMETHODIMP GetStatus(PSTI_DEVICE_STATUS pDevStatus);
  87. STDMETHODIMP DeviceReset();
  88. STDMETHODIMP Diagnostic(LPDIAG pBuffer);
  89. STDMETHODIMP Escape(STI_RAW_CONTROL_CODE EscapeFunction, LPVOID lpInData, DWORD cbInDataSize,
  90. LPVOID pOutData, DWORD dwOutDataSize, LPDWORD pdwActualData);
  91. STDMETHODIMP GetLastError(LPDWORD pdwLastDeviceError);
  92. STDMETHODIMP LockDevice();
  93. STDMETHODIMP UnLockDevice();
  94. STDMETHODIMP RawReadData(LPVOID lpBuffer, LPDWORD lpdwNumberOfBytes, LPOVERLAPPED lpOverlapped);
  95. STDMETHODIMP RawWriteData(LPVOID lpBuffer, DWORD nNumberOfBytes, LPOVERLAPPED lpOverlapped);
  96. STDMETHODIMP RawReadCommand(LPVOID lpBuffer, LPDWORD lpdwNumberOfBytes, LPOVERLAPPED lpOverlapped);
  97. STDMETHODIMP RawWriteCommand(LPVOID lpBuffer, DWORD nNumberOfBytes, LPOVERLAPPED lpOverlapped);
  98. STDMETHODIMP SetNotificationHandle(HANDLE hEvent);
  99. STDMETHODIMP GetNotificationData(LPSTINOTIFY lpNotify);
  100. STDMETHODIMP GetLastErrorInfo(STI_ERROR_INFO *pLastErrorInfo);
  101. /////////////////////////////////////////////////////////////////////////
  102. // IWiaMiniDrv Interface Section (for all WIA drivers) //
  103. /////////////////////////////////////////////////////////////////////////
  104. //
  105. // Methods for implementing WIA's Mini driver interface
  106. //
  107. STDMETHODIMP drvInitializeWia(BYTE *pWiasContext, LONG lFlags, BSTR bstrDeviceID, BSTR bstrRootFullItemName,
  108. IUnknown *pStiDevice, IUnknown *pIUnknownOuter, IWiaDrvItem **ppIDrvItemRoot,
  109. IUnknown **ppIUnknownInner, LONG *plDevErrVal);
  110. STDMETHODIMP drvUnInitializeWia(BYTE* pWiasContext);
  111. STDMETHODIMP drvDeviceCommand(BYTE *pWiasContext, LONG lFlags, const GUID *pGUIDCommand,
  112. IWiaDrvItem **ppMiniDrvItem, LONG *plDevErrVal);
  113. STDMETHODIMP drvDeleteItem(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  114. STDMETHODIMP drvGetCapabilities(BYTE *pWiasContext, LONG lFlags, LONG *pCelt,
  115. WIA_DEV_CAP_DRV **ppCapabilities, LONG *plDevErrVal);
  116. STDMETHODIMP drvInitItemProperties(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  117. STDMETHODIMP drvLockWiaDevice(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  118. STDMETHODIMP drvUnLockWiaDevice(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  119. STDMETHODIMP drvAnalyzeItem(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  120. STDMETHODIMP drvGetWiaFormatInfo(BYTE *pWiasContext, LONG lFlags, LONG *pCelt,
  121. WIA_FORMAT_INFO **ppwfi, LONG *plDevErrVal);
  122. STDMETHODIMP drvNotifyPnpEvent(const GUID *pEventGUID, BSTR bstrDeviceID, ULONG ulReserved);
  123. STDMETHODIMP drvReadItemProperties(BYTE *pWiaItem, LONG lFlags, ULONG nPropSpec,
  124. const PROPSPEC *pPropSpec, LONG *plDevErrVal);
  125. STDMETHODIMP drvWriteItemProperties(BYTE *pWiasContext, LONG lFLags,
  126. PMINIDRV_TRANSFER_CONTEXT pmdtc, LONG *plDevErrVal);
  127. STDMETHODIMP drvValidateItemProperties(BYTE *pWiasContext, LONG lFlags, ULONG nPropSpec,
  128. const PROPSPEC *pPropSpec, LONG *plDevErrVal);
  129. STDMETHODIMP drvAcquireItemData(BYTE *pWiasContext, LONG lFlags,
  130. PMINIDRV_TRANSFER_CONTEXT pDataContext, LONG *plDevErrVal);
  131. STDMETHODIMP drvGetDeviceErrorStr(LONG lFlags, LONG lDevErrVal, LPOLESTR *ppszDevErrStr, LONG *plDevErrVal);
  132. STDMETHODIMP drvFreeDrvItemContext(LONG lFlags, BYTE *pDevContext, LONG *plDevErrVal);
  133. /////////////////////////////////////////////////////////////////////////
  134. // INonDelegating Interface Section (for all WIA drivers) //
  135. /////////////////////////////////////////////////////////////////////////
  136. //
  137. // IUnknown-like methods. Needed in conjunction with normal IUnknown
  138. // methods to implement delegating components.
  139. //
  140. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  141. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  142. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  143. VOID RunNotifications(VOID);
  144. private:
  145. /////////////////////////////////////////////////////////////////////////
  146. // Private helper functions section (for your specific driver) //
  147. /////////////////////////////////////////////////////////////////////////
  148. HRESULT FreeResources();
  149. HRESULT GetOLESTRResourceString(LONG lResourceID, LPOLESTR *ppsz);
  150. //
  151. // WIA Item Management Helpers
  152. //
  153. HRESULT BuildItemTree(MCAM_ITEM_INFO *pItem);
  154. HRESULT AddObject(MCAM_ITEM_INFO *pItem);
  155. HRESULT ConstructFullName(MCAM_ITEM_INFO *pItemInfo, WCHAR *pwszFullName, INT cchFullNameSize);
  156. HRESULT LinkToParent(MCAM_ITEM_INFO *pItem, BOOL bQueueEvent = FALSE);
  157. HRESULT DeleteItemTree(LONG lReason);
  158. //
  159. // WIA Property Management Helpers
  160. //
  161. HRESULT BuildRootItemProperties(BYTE *pWiasContext);
  162. HRESULT ReadRootItemProperties(BYTE *pWiasContext, LONG lNumPropSpecs, const PROPSPEC *pPropSpecs);
  163. HRESULT BuildChildItemProperties(BYTE *pWiasContext);
  164. HRESULT GetValidFormats(BYTE *pWiasContext, LONG lTymedValue, INT *piNumFormats, GUID **ppFormatArray);
  165. HRESULT ReadChildItemProperties(BYTE *pWiasContext, LONG lNumPropSpecs, const PROPSPEC *pPropSpecs);
  166. HRESULT AcquireData(ITEM_CONTEXT *pItemCtx, PMINIDRV_TRANSFER_CONTEXT pmdtc,
  167. BYTE *pBuf, LONG lBufSize, BOOL bConverting);
  168. HRESULT Convert(BYTE *pWiasContext, ITEM_CONTEXT *pItemCtx, PMINIDRV_TRANSFER_CONTEXT pmdtc,
  169. BYTE *pNativeImage, LONG lNativeSize);
  170. //
  171. // WIA Capability Management Helpers
  172. //
  173. HRESULT BuildCapabilities();
  174. HRESULT DeleteCapabilitiesArrayContents();
  175. private:
  176. // COM object data
  177. ULONG m_cRef; // Device object reference count
  178. LPUNKNOWN m_punkOuter; // Pointer to outer unknown
  179. // STI data
  180. PSTIDEVICECONTROL m_pIStiDevControl; // Device control interface
  181. IStiDevice *m_pStiDevice; // Sti object
  182. DWORD m_dwLastOperationError; // Last error
  183. WCHAR m_wszPortName[MAX_PATH]; // Port name for accessing the device
  184. // WIA data
  185. BSTR m_bstrDeviceID; // WIA unique device ID
  186. BSTR m_bstrRootFullItemName; // Root item name
  187. IWiaDrvItem *m_pRootItem; // Root item
  188. LONG m_lNumSupportedCommands; // Number of supported commands
  189. LONG m_lNumSupportedEvents; // Number of supported events
  190. LONG m_lNumCapabilities; // Number of capabilities
  191. WIA_DEV_CAP_DRV *m_pCapabilities; // Capabilities array
  192. // Device data
  193. CCamMicro *m_pDevice; // Pointer to DLL wrapper class
  194. MCAM_DEVICE_INFO *m_pDeviceInfo; // Device information
  195. // Misc data
  196. INT m_iConnectedApps; // Number of app connected to this driver
  197. CWiauFormatConverter m_Converter;
  198. };
  199. typedef CWiaCameraDevice *PWIACAMERADEVICE;
  200. /***************************************************************************\
  201. *
  202. * CWiaCameraDeviceClassFactory
  203. *
  204. \****************************************************************************/
  205. class CWiaCameraDeviceClassFactory : public IClassFactory
  206. {
  207. public:
  208. CWiaCameraDeviceClassFactory();
  209. ~CWiaCameraDeviceClassFactory();
  210. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  211. STDMETHODIMP_(ULONG) AddRef(void);
  212. STDMETHODIMP_(ULONG) Release(void);
  213. STDMETHODIMP CreateInstance(IUnknown __RPC_FAR *pUnkOuter, REFIID riid,
  214. void __RPC_FAR *__RPC_FAR *ppvObject);
  215. STDMETHODIMP LockServer(BOOL fLock);
  216. private:
  217. ULONG m_cRef;
  218. };