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.

354 lines
14 KiB

  1. /**************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2001
  4. *
  5. * TITLE: wiacam.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 15 Nov, 2000
  10. *
  11. * DESCRIPTION:
  12. * Definition of WIA File System Device driver object
  13. *
  14. ***************************************************************************/
  15. #ifndef WIACAM__H_
  16. #define WIACAM__H_
  17. extern HINSTANCE g_hInst; // DLL module instance
  18. // extern IWiaLog *g_pIWiaLog; // pointer to WIA logging interface
  19. #if defined( _WIN32 ) && !defined( _NO_COM)
  20. // {D2923B86-15F1-46FF-A19A-DE825F919576}
  21. DEFINE_GUID(CLSID_FSUsd, 0xD2923B86, 0x15F1, 0x46FF, 0xA1, 0x9A, 0xDE, 0x82, 0x5F, 0x91, 0x95, 0x76);
  22. #endif
  23. //////////////////////////////////////////////////////////////////////////
  24. // DLL #define Section //
  25. //////////////////////////////////////////////////////////////////////////
  26. #define DATASEG_PERINSTANCE ".instance"
  27. #define DATASEG_SHARED ".shared"
  28. #define DATASEG_READONLY ".code"
  29. #define DATASEG_DEFAULT DATASEG_SHARED
  30. #define ENTERCRITICAL DllEnterCrit(void);
  31. #define LEAVECRITICAL DllLeaveCrit(void);
  32. #pragma data_seg(DATASEG_PERINSTANCE)
  33. #pragma data_seg(DATASEG_DEFAULT)
  34. extern UINT g_cRefThisDll;
  35. extern UINT g_cLocks;
  36. extern BOOL DllInitializeCOM(void);
  37. extern BOOL DllUnInitializeCOM(void);
  38. extern void DllAddRef(void);
  39. extern void DllRelease(void);
  40. /***************************************************************************\
  41. *
  42. * CWiaCameraDeviceClassFactory
  43. *
  44. \****************************************************************************/
  45. class CWiaCameraDeviceClassFactory : public IClassFactory
  46. {
  47. private:
  48. ULONG m_cRef;
  49. public:
  50. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  51. STDMETHODIMP_(ULONG) AddRef(void);
  52. STDMETHODIMP_(ULONG) Release(void);
  53. STDMETHODIMP CreateInstance(
  54. /* [unique][in] */ IUnknown __RPC_FAR *pUnkOuter,
  55. /* [in] */ REFIID riid,
  56. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
  57. STDMETHODIMP LockServer(
  58. /* [in] */ BOOL fLock);
  59. CWiaCameraDeviceClassFactory();
  60. ~CWiaCameraDeviceClassFactory();
  61. };
  62. //
  63. // Base structure for supporting non-delegating IUnknown for contained objects
  64. //
  65. DECLARE_INTERFACE(INonDelegatingUnknown)
  66. {
  67. STDMETHOD (NonDelegatingQueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppv) PURE;
  68. STDMETHOD_(ULONG,NonDelegatingAddRef) (THIS) PURE;
  69. STDMETHOD_(ULONG,NonDelegatingRelease) (THIS) PURE;
  70. };
  71. //
  72. // General purpose GUIDs
  73. //
  74. DEFINE_GUID(GUID_NULL, 0,0,0,0,0,0,0,0,0,0,0);
  75. DEFINE_GUID(FMT_NOTHING,
  76. 0x81a566e7,0x8620,0x4fba,0xbc,0x8e,0xb2,0x7c,0x17,0xad,0x9e,0xfd);
  77. //
  78. // Driver item context
  79. //
  80. typedef struct _ITEM_CONTEXT{
  81. ITEM_HANDLE ItemHandle; // Handle to the camera item
  82. LONG NumFormatInfo; // Number of entries in format info array
  83. WIA_FORMAT_INFO *pFormatInfo; // Pointer to format info array
  84. LONG ThumbSize; // Size of the thumbnail data in bytes
  85. BYTE *pThumb; // Thumbnail data
  86. } ITEM_CONTEXT, *PITEM_CONTEXT;
  87. //
  88. // Handy constants for common item types
  89. //
  90. const ULONG ITEMTYPE_FILE = WiaItemTypeFile;
  91. const ULONG ITEMTYPE_IMAGE = WiaItemTypeFile | WiaItemTypeImage;
  92. const ULONG ITEMTYPE_AUDIO = WiaItemTypeFile | WiaItemTypeAudio;
  93. const ULONG ITEMTYPE_VIDEO = WiaItemTypeFile | WiaItemTypeVideo;
  94. const ULONG ITEMTYPE_FOLDER = WiaItemTypeFolder;
  95. const ULONG ITEMTYPE_BURST = WiaItemTypeFolder | WiaItemTypeBurst;
  96. const ULONG ITEMTYPE_HPAN = WiaItemTypeFolder | WiaItemTypeHPanorama;
  97. const ULONG ITEMTYPE_VPAN = WiaItemTypeFolder | WiaItemTypeVPanorama;
  98. //
  99. // Structure which holds everything needed for each format type.
  100. //
  101. #ifndef FORMAT_INFO_STRUCTURE
  102. #define FORMAT_INFO_STRUCTURE
  103. #define MAXEXTENSIONSTRINGLENGTH 8
  104. typedef struct _FORMAT_INFO
  105. {
  106. GUID FormatGuid; // WIA format GUID
  107. WCHAR ExtensionString[MAXEXTENSIONSTRINGLENGTH]; // File extension
  108. LONG ItemType; // WIA item type
  109. } FORMAT_INFO, *PFORMAT_INFO;
  110. #endif
  111. typedef struct _DEFAULT_FORMAT_INFO
  112. {
  113. GUID *pFormatGuid; // WIA format GUID
  114. LONG ItemType; // WIA item type
  115. WCHAR *ExtensionString; // File extension
  116. } DEFAULT_FORMAT_INFO, *PDEFAULT_FORMAT_INFO;
  117. //
  118. // Minimum data call back transfer buffer size
  119. //
  120. const LONG MIN_BUFFER_SIZE = 0x8000;
  121. //
  122. // When doing a transfer and convert to BMP, this value
  123. // represents how much of the time is spent doing the
  124. // transfer of data from the device.
  125. //
  126. const LONG TRANSFER_PERCENT = 90;
  127. //
  128. // Class definition for sample WIA scanner object
  129. //
  130. class CWiaCameraDevice : public IStiUSD, // STI USD interface
  131. public IWiaMiniDrv, // WIA Minidriver interface
  132. public INonDelegatingUnknown // NonDelegatingUnknown
  133. {
  134. public:
  135. /////////////////////////////////////////////////////////////////////////
  136. // Construction/Destruction Section //
  137. /////////////////////////////////////////////////////////////////////////
  138. CWiaCameraDevice(LPUNKNOWN punkOuter);
  139. ~CWiaCameraDevice();
  140. private:
  141. // COM object data
  142. ULONG m_cRef; // Device object reference count
  143. LPUNKNOWN m_punkOuter; // Pointer to outer unknown
  144. // STI data
  145. PSTIDEVICECONTROL m_pIStiDevControl; // Device control interface
  146. IStiDevice *m_pStiDevice; // Sti object
  147. DWORD m_dwLastOperationError; // Last error
  148. WCHAR m_pPortName[MAX_PATH]; // Port name for accessing the device
  149. // WIA data
  150. BSTR m_bstrDeviceID; // WIA unique device ID
  151. BSTR m_bstrRootFullItemName; // Root item name
  152. IWiaDrvItem *m_pRootItem; // Root item
  153. LONG m_NumSupportedCommands; // Number of supported commands
  154. LONG m_NumSupportedEvents; // Number of supported events
  155. LONG m_NumCapabilities; // Number of capabilities
  156. WIA_DEV_CAP_DRV *m_pCapabilities; // Capabilities array
  157. // Device data
  158. FakeCamera *m_pDevice; // Pointer to device class
  159. DEVICE_INFO m_DeviceInfo; // Device information
  160. CWiaMap<ITEM_HANDLE, IWiaDrvItem *>
  161. m_HandleItemMap; // Maps item handles to drv items
  162. // Misc data
  163. int m_ConnectedApps; // Number of app connected to this driver
  164. CWiauFormatConverter m_Converter;
  165. IWiaLog *m_pIWiaLog;
  166. public:
  167. FORMAT_INFO *m_FormatInfo;
  168. UINT m_NumFormatInfo;
  169. /////////////////////////////////////////////////////////////////////////
  170. // Standard COM Section //
  171. /////////////////////////////////////////////////////////////////////////
  172. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  173. STDMETHODIMP_(ULONG) AddRef( void);
  174. STDMETHODIMP_(ULONG) Release( void);
  175. /////////////////////////////////////////////////////////////////////////
  176. // IStiUSD Interface Section (for all WIA drivers) //
  177. /////////////////////////////////////////////////////////////////////////
  178. //
  179. // Methods for implementing the IStiUSD interface.
  180. //
  181. STDMETHODIMP Initialize(PSTIDEVICECONTROL pHelDcb, DWORD dwStiVersion, HKEY hParametersKey);
  182. STDMETHODIMP GetCapabilities(PSTI_USD_CAPS pDevCaps);
  183. STDMETHODIMP GetStatus(PSTI_DEVICE_STATUS pDevStatus);
  184. STDMETHODIMP DeviceReset();
  185. STDMETHODIMP Diagnostic(LPDIAG pBuffer);
  186. STDMETHODIMP Escape(STI_RAW_CONTROL_CODE EscapeFunction, LPVOID lpInData, DWORD cbInDataSize,
  187. LPVOID pOutData, DWORD dwOutDataSize, LPDWORD pdwActualData);
  188. STDMETHODIMP GetLastError(LPDWORD pdwLastDeviceError);
  189. STDMETHODIMP LockDevice();
  190. STDMETHODIMP UnLockDevice();
  191. STDMETHODIMP RawReadData(LPVOID lpBuffer, LPDWORD lpdwNumberOfBytes, LPOVERLAPPED lpOverlapped);
  192. STDMETHODIMP RawWriteData(LPVOID lpBuffer, DWORD nNumberOfBytes, LPOVERLAPPED lpOverlapped);
  193. STDMETHODIMP RawReadCommand(LPVOID lpBuffer, LPDWORD lpdwNumberOfBytes, LPOVERLAPPED lpOverlapped);
  194. STDMETHODIMP RawWriteCommand(LPVOID lpBuffer, DWORD nNumberOfBytes, LPOVERLAPPED lpOverlapped);
  195. STDMETHODIMP SetNotificationHandle(HANDLE hEvent);
  196. STDMETHODIMP GetNotificationData(LPSTINOTIFY lpNotify);
  197. STDMETHODIMP GetLastErrorInfo(STI_ERROR_INFO *pLastErrorInfo);
  198. /////////////////////////////////////////////////////////////////////////
  199. // IWiaMiniDrv Interface Section (for all WIA drivers) //
  200. /////////////////////////////////////////////////////////////////////////
  201. //
  202. // Methods for implementing WIA's Mini driver interface
  203. //
  204. STDMETHODIMP drvInitializeWia(BYTE *pWiasContext, LONG lFlags, BSTR bstrDeviceID, BSTR bstrRootFullItemName,
  205. IUnknown *pStiDevice, IUnknown *pIUnknownOuter, IWiaDrvItem **ppIDrvItemRoot,
  206. IUnknown **ppIUnknownInner, LONG *plDevErrVal);
  207. STDMETHODIMP drvUnInitializeWia(BYTE* pWiasContext);
  208. STDMETHODIMP drvDeviceCommand(BYTE *pWiasContext, LONG lFlags, const GUID *pGUIDCommand,
  209. IWiaDrvItem **ppMiniDrvItem, LONG *plDevErrVal);
  210. STDMETHODIMP drvDeleteItem(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  211. STDMETHODIMP drvGetCapabilities(BYTE *pWiasContext, LONG lFlags, LONG *pCelt,
  212. WIA_DEV_CAP_DRV **ppCapabilities, LONG *plDevErrVal);
  213. STDMETHODIMP drvInitItemProperties(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  214. STDMETHODIMP drvLockWiaDevice(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  215. STDMETHODIMP drvUnLockWiaDevice(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  216. STDMETHODIMP drvAnalyzeItem(BYTE *pWiasContext, LONG lFlags, LONG *plDevErrVal);
  217. STDMETHODIMP drvGetWiaFormatInfo(BYTE *pWiasContext, LONG lFlags, LONG *pCelt,
  218. WIA_FORMAT_INFO **ppwfi, LONG *plDevErrVal);
  219. STDMETHODIMP drvNotifyPnpEvent(const GUID *pEventGUID, BSTR bstrDeviceID, ULONG ulReserved);
  220. STDMETHODIMP drvReadItemProperties(BYTE *pWiaItem, LONG lFlags, ULONG nPropSpec,
  221. const PROPSPEC *pPropSpec, LONG *plDevErrVal);
  222. STDMETHODIMP drvWriteItemProperties(BYTE *pWiasContext, LONG lFLags,
  223. PMINIDRV_TRANSFER_CONTEXT pmdtc, LONG *plDevErrVal);
  224. STDMETHODIMP drvValidateItemProperties(BYTE *pWiasContext, LONG lFlags, ULONG nPropSpec,
  225. const PROPSPEC *pPropSpec, LONG *plDevErrVal);
  226. STDMETHODIMP drvAcquireItemData(BYTE *pWiasContext, LONG lFlags,
  227. PMINIDRV_TRANSFER_CONTEXT pDataContext, LONG *plDevErrVal);
  228. STDMETHODIMP drvGetDeviceErrorStr(LONG lFlags, LONG lDevErrVal, LPOLESTR *ppszDevErrStr, LONG *plDevErrVal);
  229. STDMETHODIMP drvFreeDrvItemContext(LONG lFlags, BYTE *pDevContext, LONG *plDevErrVal);
  230. /////////////////////////////////////////////////////////////////////////
  231. // INonDelegating Interface Section (for all WIA drivers) //
  232. /////////////////////////////////////////////////////////////////////////
  233. //
  234. // IUnknown-like methods. Needed in conjunction with normal IUnknown
  235. // methods to implement delegating components.
  236. //
  237. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  238. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  239. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  240. private:
  241. /////////////////////////////////////////////////////////////////////////
  242. // Private helper functions section (for your specific driver) //
  243. /////////////////////////////////////////////////////////////////////////
  244. //
  245. // WIA Item Management Helpers
  246. //
  247. HRESULT BuildItemTree(void);
  248. HRESULT AddObject(ITEM_HANDLE ItemHandle, BOOL bQueueEvent = FALSE);
  249. HRESULT DeleteItemTree(LONG lReason);
  250. //
  251. // WIA Property Management Helpers
  252. //
  253. HRESULT BuildRootItemProperties(BYTE *pWiasContext);
  254. HRESULT ReadRootItemProperties(BYTE *pWiasContext, LONG NumPropSpecs, const PROPSPEC *pPropSpecs);
  255. HRESULT BuildChildItemProperties(BYTE *pWiasContext);
  256. HRESULT GetValidFormats(BYTE *pWiasContext, LONG TymedValue, int *pNumFormats, GUID **ppFormatArray);
  257. HRESULT ReadChildItemProperties(BYTE *pWiasContext, LONG NumPropSpecs, const PROPSPEC *pPropSpecs);
  258. HRESULT CacheThumbnail(ITEM_CONTEXT *pItemCtx, ULONG uItemType);
  259. HRESULT AcquireData(ITEM_CONTEXT *pItemCtx, PMINIDRV_TRANSFER_CONTEXT pmdtc,
  260. BYTE *pBuf, LONG lBufSize, BOOL bConverting);
  261. HRESULT Convert(BYTE *pWiasContext, ITEM_CONTEXT *pItemCtx, PMINIDRV_TRANSFER_CONTEXT pmdtc,
  262. BYTE *pNativeImage, LONG lNativeSize);
  263. //
  264. // WIA Capability Management Helpers
  265. //
  266. HRESULT BuildCapabilities();
  267. HRESULT DeleteCapabilitiesArrayContents();
  268. HRESULT SetItemSize(BYTE *pWiasContext);
  269. //
  270. // WIA Resource file Helpers
  271. //
  272. HRESULT GetBSTRResourceString(LONG lLocalResourceID, BSTR *pBSTR, BOOL bLocal);
  273. HRESULT GetOLESTRResourceString(LONG lLocalResourceID, LPOLESTR *ppsz, BOOL bLocal);
  274. //
  275. // Miscellaneous Helpers
  276. //
  277. HRESULT GetDrvItemContext(BYTE *pWiasContext, ITEM_CONTEXT **ppItemCtx, IWiaDrvItem **ppDrvItem = NULL);
  278. VOID VerticalFlip(
  279. PITEM_CONTEXT pDrvItemContext,
  280. PMINIDRV_TRANSFER_CONTEXT pDataTransferContext);
  281. FORMAT_INFO *FormatCode2FormatInfo(FORMAT_CODE ItemType);
  282. DWORD PopulateFormatInfo(void);
  283. void UnPopulateFormatInfo(void);
  284. public:
  285. VOID RunNotifications(VOID);
  286. };
  287. typedef CWiaCameraDevice *PWIACAMERADEVICE;
  288. #endif // #ifndef WIACAM__H_