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.

418 lines
14 KiB

  1. /****************************************************************************
  2. *
  3. * TESTUSD.H
  4. *
  5. * Copyright (c) Microsoft Corporation 1996-1997
  6. * All rights reserved
  7. *
  8. ***************************************************************************/
  9. #ifndef WIN32_LEAN_AND_MEAN
  10. #define WIN32_LEAN_AND_MEAN
  11. #endif
  12. #include <windows.h>
  13. #pragma intrinsic(memcmp,memset)
  14. #include <objbase.h>
  15. #include "sti.h"
  16. #include "stierr.h"
  17. #include "stiusd.h"
  18. #include "wiamindr.h"
  19. #define DATA_SRC_NAME L"TESTUSD.BMP" // Data source file name.
  20. // GUID's
  21. #if defined( _WIN32 ) && !defined( _NO_COM)
  22. // {ACBF6AF6-51C9-46a9-87D8-A93F352BCB3E}
  23. DEFINE_GUID(CLSID_TestUsd,
  24. 0xacbf6af6, 0x51c9, 0x46a9, 0x87, 0xd8, 0xa9, 0x3f, 0x35, 0x2b, 0xcb, 0x3e);
  25. // {61127F40-E1A5-11D0-B454-00A02438AD48}
  26. DEFINE_GUID(guidEventTimeChanged, 0x61127F40L, 0xE1A5, 0x11D0, 0xB4, 0x54, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  27. // {052ED270-28A3-11D1-ACAD-00A02438AD48}
  28. DEFINE_GUID(guidEventSizeChanged, 0x052ED270L, 0x28A3, 0x11D1, 0xAC, 0xAD, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  29. // {052ED270-28A3-11D1-ACAD-00A02438AD48}
  30. DEFINE_GUID(guidEventFirstLoaded, 0x052ED270L, 0x28A3, 0x11D3, 0xAC, 0xAD, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  31. #endif
  32. #define DATASEG_PERINSTANCE ".instance"
  33. #define DATASEG_SHARED ".shared"
  34. #define DATASEG_READONLY ".code"
  35. #define DATASEG_DEFAULT DATASEG_SHARED
  36. #pragma data_seg(DATASEG_PERINSTANCE)
  37. // Set the default data segment
  38. #pragma data_seg(DATASEG_DEFAULT)
  39. //
  40. // Module ref counting
  41. //
  42. extern UINT g_cRefThisDll;
  43. extern UINT g_cLocks;
  44. extern BOOL DllInitializeCOM(void);
  45. extern BOOL DllUnInitializeCOM(void);
  46. extern void DllAddRef(void);
  47. extern void DllRelease(void);
  48. typedef struct _MEMCAM_IMAGE_CONTEXT
  49. {
  50. PTCHAR pszCameraImagePath;
  51. }MEMCAM_IMAGE_CONTEXT,*PMEMCAM_IMAGE_CONTEXT;
  52. typedef struct _CAMERA_PICTURE_INFO
  53. {
  54. LONG PictNumber ;
  55. LONG ThumbWidth ;
  56. LONG ThumbHeight ;
  57. LONG PictWidth ;
  58. LONG PictHeight ;
  59. LONG PictCompSize ;
  60. LONG PictFormat ;
  61. LONG PictBitsPerPixel ;
  62. LONG PictBytesPerRow ;
  63. SYSTEMTIME TimeStamp;
  64. }CAMERA_PICTURE_INFO,*PCAMERA_PICTURE_INFO;
  65. typedef struct _CAMERA_STATUS
  66. {
  67. LONG FirmwareVersion ;
  68. LONG NumPictTaken ;
  69. LONG NumPictRemaining ;
  70. LONG ThumbWidth ;
  71. LONG ThumbHeight ;
  72. LONG PictWidth ;
  73. LONG PictHeight ;
  74. SYSTEMTIME CameraTime;
  75. } CAMERA_STATUS,*PCAMERA_STATUS;
  76. #define ALLOC(s) LocalAlloc(0,s)
  77. #define FREE(s) LocalFree(s)
  78. //
  79. // Base class for supporting non-delegating IUnknown for contained objects
  80. //
  81. struct INonDelegatingUnknown
  82. {
  83. // *** IUnknown-like methods ***
  84. STDMETHOD(NonDelegatingQueryInterface)( THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  85. STDMETHOD_(ULONG,NonDelegatingAddRef)(THIS) PURE;
  86. STDMETHOD_(ULONG,NonDelegatingRelease)( THIS) PURE;
  87. };
  88. //
  89. // Class definition for object
  90. //
  91. class TestUsdDevice : public IStiUSD,
  92. public IWiaMiniDrv,
  93. public INonDelegatingUnknown
  94. {
  95. private:
  96. // COM object data
  97. ULONG m_cRef; // Device object reference count.
  98. // STI information
  99. BOOL m_fValid; // Is object initialized?
  100. LPUNKNOWN m_punkOuter; // Pointer to outer unknown.
  101. PSTIDEVICECONTROL m_pIStiDevControl; // Device control interface.
  102. BOOLEAN m_bUsdLoadEvent; // Controls load event.
  103. DWORD m_dwLastOperationError; // Last error.
  104. // Data source file information.
  105. TCHAR m_szSrcDataName[MAX_PATH]; // Path of data source file.
  106. FILETIME m_ftLastWriteTime; // Last time of source data file.
  107. LARGE_INTEGER m_dwLastHugeSize; // Last size of source data file.
  108. // Event information
  109. CRITICAL_SECTION m_csShutdown; // Syncronizes shutdown.
  110. HANDLE m_hShutdownEvent; // Shutdown event handle.
  111. HANDLE m_hEventNotifyThread; // Does event notification.
  112. // WIA information, one time initialization.
  113. IStiDevice *m_pStiDevice; // Sti object.
  114. BSTR m_bstrRootFullItemName; // Device name for prop streams.
  115. IWiaEventCallback *m_pIWiaEventCallback; // WIA event sink.
  116. IWiaDrvItem *m_pIDrvItemRoot; // root item
  117. BOOL inline IsValid(VOID) {
  118. return m_fValid;
  119. }
  120. //
  121. // make public until dlg proc is a member
  122. //
  123. public:
  124. BSTR m_bstrDeviceID; // WIA unique device ID.
  125. HANDLE m_hSignalEvent; // Signal event handle.
  126. HWND m_hDlg;
  127. GUID m_guidLastEvent; // Last event ID.
  128. public:
  129. // *** IUnknown-like methods ***
  130. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  131. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  132. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  133. // *** IUnknown methods ***
  134. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  135. STDMETHODIMP_(ULONG) AddRef( void);
  136. STDMETHODIMP_(ULONG) Release( void);
  137. /*** IStiUSD methods ***/
  138. STDMETHOD(Initialize) (THIS_ PSTIDEVICECONTROL pHelDcb,DWORD dwStiVersion,HKEY hParametersKey) ;
  139. STDMETHOD(GetCapabilities) (THIS_ PSTI_USD_CAPS pDevCaps) ;
  140. STDMETHOD(GetStatus) (THIS_ PSTI_DEVICE_STATUS pDevStatus) ;
  141. STDMETHOD(DeviceReset)(THIS ) ;
  142. STDMETHOD(Diagnostic)(THIS_ LPDIAG pBuffer) ;
  143. STDMETHOD(Escape)(THIS_ STI_RAW_CONTROL_CODE EscapeFunction,LPVOID lpInData,DWORD cbInDataSize,LPVOID pOutData,DWORD dwOutDataSize,LPDWORD pdwActualData) ;
  144. STDMETHOD(GetLastError) (THIS_ LPDWORD pdwLastDeviceError) ;
  145. STDMETHOD(LockDevice) (THIS ) ;
  146. STDMETHOD(UnLockDevice) (THIS ) ;
  147. STDMETHOD(RawReadData)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  148. STDMETHOD(RawWriteData)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  149. STDMETHOD(RawReadCommand)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  150. STDMETHOD(RawWriteCommand)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  151. STDMETHOD(SetNotificationHandle)(THIS_ HANDLE hEvent) ;
  152. STDMETHOD(GetNotificationData)(THIS_ LPSTINOTIFY lpNotify) ;
  153. STDMETHOD(GetLastErrorInfo) (THIS_ STI_ERROR_INFO *pLastErrorInfo);
  154. //
  155. // MiniDrv methods
  156. //
  157. STDMETHOD(drvInitializeWia)(THIS_
  158. BYTE* pWiasContext,
  159. LONG lFlags,
  160. BSTR bstrDeviceID,
  161. BSTR bstrRootFullItemName,
  162. IUnknown *pStiDevice,
  163. IUnknown *pIUnknownOuter,
  164. IWiaDrvItem **ppIDrvItemRoot,
  165. IUnknown **ppIUnknownInner,
  166. LONG *plDevErrVal);
  167. STDMETHOD(drvGetDeviceErrorStr)(THIS_
  168. LONG lFlags,
  169. LONG lDevErrVal,
  170. LPOLESTR *ppszDevErrStr,
  171. LONG *plDevErr);
  172. STDMETHOD(drvDeviceCommand)(THIS_
  173. BYTE *pWiasContext,
  174. LONG lFlags,
  175. const GUID *pGUIDCommand,
  176. IWiaDrvItem **ppMiniDrvItem,
  177. LONG *plDevErrVal);
  178. STDMETHOD(drvAcquireItemData)(THIS_
  179. BYTE *pWiasContext,
  180. LONG lFlags,
  181. PMINIDRV_TRANSFER_CONTEXT pDataContext,
  182. LONG *plDevErrVal);
  183. STDMETHOD(drvInitItemProperties)(THIS_
  184. BYTE *pWiasContext,
  185. LONG lFlags,
  186. LONG *plDevErrVal);
  187. STDMETHOD(drvValidateItemProperties)(THIS_
  188. BYTE *pWiasContext,
  189. LONG lFlags,
  190. ULONG nPropSpec,
  191. const PROPSPEC *pPropSpec,
  192. LONG *plDevErrVal);
  193. STDMETHOD(drvWriteItemProperties)(THIS_
  194. BYTE *pWiasContext,
  195. LONG lFLags,
  196. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  197. LONG *plDevErrVal);
  198. STDMETHOD(drvReadItemProperties)(THIS_
  199. BYTE *pWiaItem,
  200. LONG lFlags,
  201. ULONG nPropSpec,
  202. const PROPSPEC *pPropSpec,
  203. LONG *plDevErrVal);
  204. STDMETHOD(drvLockWiaDevice)(THIS_
  205. BYTE *pWiasContext,
  206. LONG lFlags,
  207. LONG *plDevErrVal);
  208. STDMETHOD(drvUnLockWiaDevice)(THIS_
  209. BYTE *pWiasContext,
  210. LONG lFlags,
  211. LONG *plDevErrVal );
  212. STDMETHOD(drvAnalyzeItem)(THIS_
  213. BYTE *pWiasContext,
  214. LONG lFlags,
  215. LONG *plDevErrVal);
  216. STDMETHOD(drvDeleteItem)(THIS_
  217. BYTE *pWiasContext,
  218. LONG lFlags,
  219. LONG *plDevErrVal);
  220. STDMETHOD(drvFreeDrvItemContext)(THIS_
  221. LONG lFlags,
  222. BYTE *pDevContext,
  223. LONG *plDevErrVal);
  224. STDMETHOD(drvGetCapabilities)(THIS_
  225. BYTE *pWiasContext,
  226. LONG lFlags,
  227. LONG *pCelt,
  228. WIA_DEV_CAP_DRV **ppCapabilities,
  229. LONG *plDevErrVal);
  230. STDMETHOD(drvGetWiaFormatInfo)(THIS_
  231. BYTE *pWiasContext,
  232. LONG lFlags,
  233. LONG *pCelt,
  234. WIA_FORMAT_INFO **ppwfi,
  235. LONG *plDevErrVal);
  236. STDMETHOD(drvNotifyPnpEvent)(THIS_
  237. const GUID *pEventGUID,
  238. BSTR bstrDeviceID,
  239. ULONG ulReserved);
  240. STDMETHOD(drvUnInitializeWia)(THIS_
  241. BYTE*);
  242. /*** Private helper methods ***/
  243. private:
  244. HRESULT InitImageInformation(
  245. BYTE *pWiasContext,
  246. MEMCAM_IMAGE_CONTEXT *pContext,
  247. LONG *plDevErrVal);
  248. HRESULT InitAudioInformation(
  249. BYTE *pWiasContext,
  250. MEMCAM_IMAGE_CONTEXT *pContext,
  251. LONG *plDevErrVal);
  252. HRESULT EnumDiskImages(
  253. IWiaDrvItem *pRootItem,
  254. LPTSTR pszDirName);
  255. HRESULT CreateItemFromFileName(
  256. LONG lFolderType,
  257. PTCHAR pszPath,
  258. PTCHAR pszName,
  259. IWiaDrvItem **ppNewFolder);
  260. HRESULT CamLoadPicture(
  261. PMEMCAM_IMAGE_CONTEXT pMCamContext,
  262. PMINIDRV_TRANSFER_CONTEXT pDataTransCtx,
  263. PLONG plDevErrVal);
  264. HRESULT CamLoadPictureCB(
  265. PMEMCAM_IMAGE_CONTEXT pMCamContext,
  266. MINIDRV_TRANSFER_CONTEXT *pDataTransCtx,
  267. PLONG plDevErrVal);
  268. HRESULT CamGetPictureInfo(
  269. PMEMCAM_IMAGE_CONTEXT pMCamContext,
  270. PCAMERA_PICTURE_INFO pPictInfo,
  271. PBYTE *ppBITMAPINFO,
  272. LONG *pBITMAPINFOSize);
  273. HRESULT CamLoadThumbnail(PMEMCAM_IMAGE_CONTEXT, PBYTE *,LONG *);
  274. HRESULT CamBuildImageTree(CAMERA_STATUS *,IWiaDrvItem **);
  275. HRESULT CamOpenCamera(CAMERA_STATUS *);
  276. HRESULT BuildDeviceItemTree(LONG *plDevErrVal);
  277. HRESULT DeleteDeviceItemTree(LONG *plDevErrVal);
  278. HRESULT InitDeviceProperties(BYTE *, LONG *plDevErrVal);
  279. public:
  280. TestUsdDevice(LPUNKNOWN punkOuter);
  281. HRESULT PrivateInitialize();
  282. ~TestUsdDevice();
  283. VOID RunNotifications(VOID);
  284. };
  285. typedef TestUsdDevice *PTestUsdDevice;
  286. HRESULT SetItemSize(BYTE*);
  287. //
  288. // Utility function to set up the attributes for format property
  289. //
  290. HRESULT SetFormatAttribs();
  291. //
  292. // Syncronization mechanisms
  293. //
  294. #define ENTERCRITICAL DllEnterCrit(void);
  295. #define LEAVECRITICAL DllLeaveCrit(void);
  296. // Device constants:
  297. const LEN_INQUIRE_BUTTON = 8;
  298. const BYTE INQUIRE_BUTTON[LEN_INQUIRE_BUTTON + 1] = "INQUIREB";
  299. const LEN_INQUIRE_BUTTON_READ = 10;
  300. const LEN_CLEAR_BUTTON = 5;
  301. const BYTE CLEAR_BUTTON[LEN_CLEAR_BUTTON + 1] = "CLRBT";
  302. const LEN_CURRENT_ERROR = 7;
  303. const BYTE CURRENT_ERROR[LEN_CURRENT_ERROR + 1] = "CURERR";
  304. const LEN_DIAGS = 5;
  305. const BYTE TURN_ON_LAMP[LEN_DIAGS + 1] = "LAMPO";
  306. const BYTE TURN_OFF_LAMP[LEN_DIAGS + 1] = "LAMPF";
  307. const BYTE SELF_TEST[LEN_DIAGS + 1] = "SELFT";
  308. const BYTE STATUS_STRING[LEN_DIAGS + 1] = "STATS";
  309. BOOL
  310. _stdcall CameraEventDlgProc(
  311. HWND hDlg,
  312. unsigned message,
  313. DWORD wParam,
  314. LONG lParam
  315. );
  316. typedef struct _CAM_EVENT
  317. {
  318. PTCHAR pszEvent;
  319. const GUID *pguid;
  320. }CAM_EVENT,*PCAM_EVENT;
  321. extern TCHAR gpszPath[];