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.

273 lines
8.5 KiB

  1. /*-----------------------------------------------------------------------------
  2. *
  3. * File: wiadevinf.cpp
  4. * Author: Samuel Clement (samclem)
  5. * Date: Fri Aug 13 15:47:16 1999
  6. * Description:
  7. * Defines the CWiaDeviceInfo object
  8. *
  9. * Copyright 1999 Microsoft Corporation
  10. *
  11. * History:
  12. * 13 Aug 1999: Created.
  13. *----------------------------------------------------------------------------*/
  14. #include "stdafx.h"
  15. /*-----------------------------------------------------------------------------
  16. * CWiaDeviceInfo::CWiaDeviceInfo
  17. *
  18. * Creates a new CWiaDevice info shell, does nothing until AttachTo() is
  19. * called.
  20. *--(samclem)-----------------------------------------------------------------*/
  21. CWiaDeviceInfo::CWiaDeviceInfo()
  22. : m_pWiaStorage( NULL ), m_pWia( NULL )
  23. {
  24. TRACK_OBJECT( "CWiaDeviceInfo" );
  25. }
  26. /*-----------------------------------------------------------------------------
  27. * CWiaDeviceInfo::FinalRelease
  28. *
  29. * This handles the final release of this object. We need to release our
  30. * pointer to the wia property storage.
  31. *--(samclem)-----------------------------------------------------------------*/
  32. STDMETHODIMP_(void)
  33. CWiaDeviceInfo::FinalRelease()
  34. {
  35. if ( m_pWiaStorage )
  36. {
  37. m_pWiaStorage->Release();
  38. m_pWiaStorage = NULL;
  39. }
  40. if ( m_pWia )
  41. {
  42. m_pWia = NULL;
  43. }
  44. }
  45. /*-----------------------------------------------------------------------------
  46. * CWiaDeviceInfo::AttachTo
  47. *
  48. * This method is internal to the server it is called when we want to attach
  49. * to a IWiaPropertyStorage for a device. this is used when building the
  50. * collection of device info.
  51. *
  52. * see: CWia::get_Devices()
  53. *
  54. * pStg: the IWiaPropertyStorage to attach to.
  55. * pWia: An IWia pointer for creating the device
  56. *--(samclem)-----------------------------------------------------------------*/
  57. HRESULT
  58. CWiaDeviceInfo::AttachTo( IWiaPropertyStorage* pStg, IWia* pWia )
  59. {
  60. if ( !pStg || !pWia )
  61. return E_POINTER;
  62. if ( m_pWiaStorage )
  63. return E_UNEXPECTED;
  64. m_pWiaStorage = pStg;
  65. m_pWiaStorage->AddRef();
  66. // Inorder to avoid a nasty circular referance this doesn't
  67. // AddRef the pWia pointer. This should be okay, since as long
  68. // as we exist the pWia can't go away anyhow.
  69. // Basically, the only thing we need this for is for calling
  70. m_pWia = pWia;
  71. return S_OK;
  72. }
  73. /*-----------------------------------------------------------------------------
  74. * CWiaDeviceInfo::Create
  75. *
  76. * This creates a connection the IWiaItem which represents the device.
  77. * This simply delegates the call to IWia::Create() using the m_pWia
  78. * member.
  79. *
  80. * ppDevice: Out, recieves the IDispatch pointer for the device
  81. *--(samclem)-----------------------------------------------------------------*/
  82. STDMETHODIMP
  83. CWiaDeviceInfo::Create( IWiaDispatchItem** ppDevice )
  84. {
  85. VARIANT vaThis;
  86. HRESULT hr;
  87. if ( !m_pWia )
  88. return E_UNEXPECTED;
  89. VariantInit( &vaThis );
  90. vaThis.vt = VT_DISPATCH;
  91. hr = QueryInterface( IID_IDispatch, reinterpret_cast<void**>(&vaThis.pdispVal) );
  92. Assert( SUCCEEDED( hr ) );
  93. hr = m_pWia->Create( &vaThis, ppDevice );
  94. VariantClear( &vaThis );
  95. return hr;
  96. }
  97. /*-----------------------------------------------------------------------------
  98. * CWiaDeviceInfo::get_Id [IWiaDeviceInfo]
  99. *
  100. * This gets the device Id for this device. (WIA_DIP_DEV_ID)
  101. *
  102. * pbstrDeviceId: Out, recieces the id of the device
  103. *--(samclem)-----------------------------------------------------------------*/
  104. STDMETHODIMP
  105. CWiaDeviceInfo::get_Id( BSTR* pbstrDeviceId )
  106. {
  107. if ( !pbstrDeviceId )
  108. return E_POINTER;
  109. return THR( GetWiaPropertyBSTR( m_pWiaStorage, WIA_DIP_DEV_ID, pbstrDeviceId ) );
  110. }
  111. /*-----------------------------------------------------------------------------
  112. * CWiaDeviceInfo::get_Name [IWiaDeviceInfo]
  113. *
  114. * This gets the name of the device, this is a human readable name for
  115. * the device. (WIA_DIP_DEV_NAME)
  116. *
  117. * pbstrName: Out, recieves the device name
  118. *--(samclem)-----------------------------------------------------------------*/
  119. STDMETHODIMP
  120. CWiaDeviceInfo::get_Name( BSTR* pbstrName )
  121. {
  122. if ( !pbstrName )
  123. return E_POINTER;
  124. return THR( GetWiaPropertyBSTR( m_pWiaStorage, WIA_DIP_DEV_NAME, pbstrName ) );
  125. }
  126. /*-----------------------------------------------------------------------------
  127. * CWiaDeviceInfo::get_Type [IWiaDeviceInfo]
  128. *
  129. * This gets the type of the device. This will return a BSTR representation
  130. * of the device, not the integer constant. (WIA_DIP_DEV_TYPE)
  131. *
  132. * pBstrType: Out, recieves the BSTR rep. of the device type
  133. * Values: DigitalCamer, Scanner, Default.
  134. *--(samclem)-----------------------------------------------------------------*/
  135. STDMETHODIMP
  136. CWiaDeviceInfo::get_Type( BSTR* pbstrType )
  137. {
  138. PROPVARIANT vaProp;
  139. HRESULT hr;
  140. // WIA currently uses the STI device constants. they also use the
  141. // GET_STIDEVICE_TYPE() macro. This simply does a HIWORD() on the
  142. // value since the real property value is split into a major device
  143. // type and a minor device type.
  144. STRING_TABLE_DEF( StiDeviceTypeDefault, "Default" )
  145. STRING_ENTRY( StiDeviceTypeScanner, "Scanner" )
  146. STRING_ENTRY( StiDeviceTypeDigitalCamera, "DigitalCamera" )
  147. STRING_ENTRY( StiDeviceTypeStreamingVideo, "StreamingVideo")
  148. END_STRING_TABLE()
  149. if ( !pbstrType )
  150. return E_POINTER;
  151. hr = THR( GetWiaProperty( m_pWiaStorage, WIA_DIP_DEV_TYPE, &vaProp ) );
  152. if ( FAILED( hr ) )
  153. return hr;
  154. DWORD devType = vaProp.ulVal;
  155. PropVariantClear( &vaProp );
  156. *pbstrType = SysAllocString( GetStringForVal( StiDeviceTypeDefault, GET_STIDEVICE_TYPE( devType ) ) );
  157. if ( !*pbstrType )
  158. return E_OUTOFMEMORY;
  159. return S_OK;
  160. }
  161. /*-----------------------------------------------------------------------------
  162. * CWiaDeviceInfo::get_Port [IWiaDeviceInfo]
  163. *
  164. * Gets the port that this device is attached to. (WIA_DIP_PORT_NAME)
  165. *
  166. * pbstrPort: Out, Recieves the name of the port.
  167. *--(samclem)-----------------------------------------------------------------*/
  168. STDMETHODIMP
  169. CWiaDeviceInfo::get_Port( BSTR* pbstrPort )
  170. {
  171. if ( !pbstrPort )
  172. return E_POINTER;
  173. return THR( GetWiaPropertyBSTR( m_pWiaStorage, WIA_DIP_PORT_NAME, pbstrPort ) );
  174. }
  175. /*-----------------------------------------------------------------------------
  176. * CWiaDeviceInfo::get_UIClsid [IWiaDeviceInfo]
  177. *
  178. * Gets the CLSID for the UI associated with this device. This returns the
  179. * string representation of the GUID. (WIA_DIP_UI_CLSID)
  180. *
  181. * pbstrGuidUI: Out, recieves the CLSID for the UI.
  182. *--(samclem)-----------------------------------------------------------------*/
  183. STDMETHODIMP
  184. CWiaDeviceInfo::get_UIClsid( BSTR* pbstrGuidUI )
  185. {
  186. if ( !pbstrGuidUI )
  187. return E_POINTER;
  188. return THR( GetWiaPropertyBSTR( m_pWiaStorage, WIA_DIP_UI_CLSID, pbstrGuidUI ) );
  189. }
  190. /*-----------------------------------------------------------------------------
  191. * CWiaDeviceInfo::get_Manufacturer [IWiaDeviceInfo]
  192. *
  193. * Gets the vendor of the device. (WIA_DIP_VEND_DESC)
  194. *
  195. * pbstrVendor: Out, recieves the vendor name
  196. *--(samclem)-----------------------------------------------------------------*/
  197. STDMETHODIMP
  198. CWiaDeviceInfo::get_Manufacturer( BSTR* pbstrVendor )
  199. {
  200. if ( !pbstrVendor )
  201. return E_POINTER;
  202. return THR( GetWiaPropertyBSTR( m_pWiaStorage, WIA_DIP_VEND_DESC, pbstrVendor ) );
  203. }
  204. /*-----------------------------------------------------------------------------
  205. * CWiaDevInfo::GetPropById [IWiaDeviceInfo]
  206. *
  207. * Gets the valu of the property with the given prop id. this will return
  208. * the raw value of the property no translation.
  209. *
  210. * If the property is not found, or its a type that can't be converted into
  211. * a VARIANT. then VT_EMPTY is returned.
  212. *
  213. * propid: the propid of the property as a dword
  214. * pvaOut: the variant to fill with the value of the propery
  215. *--(samclem)-----------------------------------------------------------------*/
  216. STDMETHODIMP
  217. CWiaDeviceInfo::GetPropById( WiaDeviceInfoPropertyId Id, VARIANT* pvaOut )
  218. {
  219. PROPVARIANT vaProp;
  220. HRESULT hr;
  221. DWORD dwPropId = (DWORD)Id;
  222. if ( NULL == pvaOut )
  223. return E_POINTER;
  224. hr = THR( GetWiaProperty( m_pWiaStorage, dwPropId, &vaProp ) );
  225. if ( FAILED( hr ) )
  226. return hr;
  227. // Force this to VT_EMPTY if it failed
  228. hr = THR( PropVariantToVariant( &vaProp, pvaOut ) );
  229. if ( FAILED( hr ) )
  230. {
  231. TraceTag((0, "forcing value of property %ld to VT_EMPTY", dwPropId ));
  232. VariantInit( pvaOut );
  233. pvaOut->vt = VT_EMPTY;
  234. }
  235. PropVariantClear( &vaProp );
  236. return S_OK;
  237. }