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.

311 lines
7.5 KiB

  1. #include "cstmprop.h"
  2. #include "hwdev.h"
  3. #include "dtctreg.h"
  4. #include "svcsync.h"
  5. #include "cmmn.h"
  6. #include "str.h"
  7. #include "misc.h"
  8. #include "tfids.h"
  9. #include "dbg.h"
  10. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  11. STDMETHODIMP CHWDeviceCustomPropertiesImpl::InitFromDeviceID(
  12. LPCWSTR pszDeviceID, DWORD dwFlags)
  13. {
  14. HRESULT hr;
  15. if (pszDeviceID && *pszDeviceID)
  16. {
  17. if ((0 == dwFlags) || (HWDEVCUSTOMPROP_USEVOLUMEPROCESSING == dwFlags))
  18. {
  19. if (!_fInited)
  20. {
  21. CHWEventDetectorHelper::CheckDiagnosticAppPresence();
  22. _dwFlags = dwFlags;
  23. if (HWDEVCUSTOMPROP_USEVOLUMEPROCESSING == dwFlags)
  24. {
  25. DIAGNOSTIC((TEXT("[0257]Using HWDEVCUSTOMPROP_USEVOLUMEPROCESSING")));
  26. WCHAR szDeviceIDReal[MAX_DEVICEID];
  27. hr = _GetDeviceID(pszDeviceID, szDeviceIDReal,
  28. ARRAYSIZE(szDeviceIDReal));
  29. if (SUCCEEDED(hr) && (S_FALSE != hr))
  30. {
  31. DIAGNOSTIC((TEXT("[0258]DeviceID converted from %s to %s"), pszDeviceID, szDeviceIDReal));
  32. hr = _GetHWDeviceInstFromVolumeIntfID(szDeviceIDReal,
  33. &_phwdevinst, &_pelemToRelease);
  34. }
  35. }
  36. else
  37. {
  38. DIAGNOSTIC((TEXT("[0258]NOT using HWDEVCUSTOMPROP_USEVOLUMEPROCESSING")));
  39. hr = _GetHWDeviceInstFromDeviceIntfID(pszDeviceID,
  40. &_phwdevinst, &_pelemToRelease);
  41. }
  42. if (SUCCEEDED(hr))
  43. {
  44. if (S_FALSE != hr)
  45. {
  46. DIAGNOSTIC((TEXT("[0259]Custom Property: Initialization SUCCEEDED")));
  47. _fInited = TRUE;
  48. }
  49. else
  50. {
  51. DIAGNOSTIC((TEXT("[0260]Custom Property: Initialization FAILED")));
  52. hr = E_FAIL;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. hr = E_UNEXPECTED;
  59. }
  60. }
  61. else
  62. {
  63. hr = E_INVALIDARG;
  64. }
  65. }
  66. else
  67. {
  68. hr = E_INVALIDARG;
  69. }
  70. return hr;
  71. }
  72. STDMETHODIMP CHWDeviceCustomPropertiesImpl::InitFromDevNode(
  73. LPCWSTR pszDevNode, DWORD dwFlags)
  74. {
  75. HRESULT hr;
  76. if (pszDevNode && *pszDevNode)
  77. {
  78. if ((0 == dwFlags))
  79. {
  80. if (!_fInited)
  81. {
  82. CHWEventDetectorHelper::CheckDiagnosticAppPresence();
  83. _dwFlags = dwFlags;
  84. hr = _GetHWDeviceInstFromDeviceNode(pszDevNode, &_phwdevinst,
  85. &_pelemToRelease);
  86. if (SUCCEEDED(hr))
  87. {
  88. if (S_FALSE != hr)
  89. {
  90. DIAGNOSTIC((TEXT("[0270]Custom Property: Initialization SUCCEEDED")));
  91. _fInited = TRUE;
  92. }
  93. else
  94. {
  95. DIAGNOSTIC((TEXT("[0271]Custom Property: Initialization FAILED")));
  96. hr = E_FAIL;
  97. }
  98. }
  99. }
  100. else
  101. {
  102. hr = E_UNEXPECTED;
  103. }
  104. }
  105. else
  106. {
  107. hr = E_INVALIDARG;
  108. }
  109. }
  110. else
  111. {
  112. hr = E_INVALIDARG;
  113. }
  114. return hr;
  115. }
  116. STDMETHODIMP CHWDeviceCustomPropertiesImpl::GetDWORDProperty(
  117. LPCWSTR pszPropName, DWORD* pdwProp)
  118. {
  119. HRESULT hr;
  120. if (_fInited)
  121. {
  122. *pdwProp = (DWORD)-1;
  123. if (pszPropName && *pszPropName && pdwProp)
  124. {
  125. DWORD dwType;
  126. DWORD dwProp;
  127. hr = _GetDevicePropertyGeneric(_phwdevinst, pszPropName,
  128. FALSE, &dwType, (PBYTE)&dwProp, sizeof(dwProp));
  129. if (SUCCEEDED(hr) && (S_FALSE != hr))
  130. {
  131. if (REG_DWORD == dwType)
  132. {
  133. DIAGNOSTIC((TEXT("[0261]Found Property: '%s'"), pszPropName));
  134. *pdwProp = dwProp;
  135. }
  136. else
  137. {
  138. DIAGNOSTIC((TEXT("[0262]Found Property: '%s', but NOT REG_DWORD type"), pszPropName));
  139. hr = E_FAIL;
  140. }
  141. }
  142. else
  143. {
  144. hr = E_FAIL;
  145. }
  146. }
  147. else
  148. {
  149. hr = E_INVALIDARG;
  150. }
  151. }
  152. else
  153. {
  154. hr = E_UNEXPECTED;
  155. }
  156. return hr;
  157. }
  158. STDMETHODIMP CHWDeviceCustomPropertiesImpl::GetStringProperty(
  159. LPCWSTR pszPropName, LPWSTR* ppszProp)
  160. {
  161. HRESULT hr;
  162. if (_fInited)
  163. {
  164. if (pszPropName && *pszPropName && ppszProp)
  165. {
  166. DWORD dwType;
  167. hr = _GetDevicePropertyStringNoBuf(_phwdevinst, pszPropName,
  168. FALSE, &dwType, ppszProp);
  169. if (SUCCEEDED(hr) && (S_FALSE != hr))
  170. {
  171. if (dwType != REG_SZ)
  172. {
  173. DIAGNOSTIC((TEXT("[0264]Found Property: '%s', but NOT REG_SZ type"), pszPropName));
  174. CoTaskMemFree(*ppszProp);
  175. *ppszProp = NULL;
  176. hr = E_FAIL;
  177. }
  178. else
  179. {
  180. DIAGNOSTIC((TEXT("[0263]Found Property: '%s'"), pszPropName));
  181. }
  182. }
  183. else
  184. {
  185. *ppszProp = NULL;
  186. hr = E_FAIL;
  187. }
  188. }
  189. else
  190. {
  191. hr = E_INVALIDARG;
  192. }
  193. }
  194. else
  195. {
  196. hr = E_UNEXPECTED;
  197. }
  198. return hr;
  199. }
  200. STDMETHODIMP CHWDeviceCustomPropertiesImpl::GetMultiStringProperty(
  201. LPCWSTR pszPropName, BOOL fMergeMultiSz, WORD_BLOB** ppblob)
  202. {
  203. HRESULT hr;
  204. if (_fInited)
  205. {
  206. if (pszPropName && *pszPropName && ppblob)
  207. {
  208. hr = _GetDevicePropertyGenericAsMultiSz(_phwdevinst, pszPropName,
  209. fMergeMultiSz, ppblob);
  210. if (FAILED(hr) || (S_FALSE == hr))
  211. {
  212. *ppblob = NULL;
  213. hr = E_FAIL;
  214. }
  215. }
  216. else
  217. {
  218. hr = E_INVALIDARG;
  219. }
  220. }
  221. else
  222. {
  223. hr = E_UNEXPECTED;
  224. }
  225. return hr;
  226. }
  227. STDMETHODIMP CHWDeviceCustomPropertiesImpl::GetBlobProperty(
  228. LPCWSTR pszPropName, BYTE_BLOB** ppblob)
  229. {
  230. HRESULT hr;
  231. if (_fInited)
  232. {
  233. if (pszPropName && *pszPropName && ppblob)
  234. {
  235. hr = _GetDevicePropertyGenericAsBlob(_phwdevinst, pszPropName,
  236. ppblob);
  237. if (FAILED(hr) || (S_FALSE == hr))
  238. {
  239. *ppblob = NULL;
  240. hr = E_FAIL;
  241. }
  242. }
  243. else
  244. {
  245. hr = E_INVALIDARG;
  246. }
  247. }
  248. else
  249. {
  250. hr = E_UNEXPECTED;
  251. }
  252. return hr;
  253. }
  254. CHWDeviceCustomPropertiesImpl::CHWDeviceCustomPropertiesImpl() :
  255. _fInited(FALSE), _pelemToRelease(NULL), _phwdevinst(NULL), _dwFlags(0)
  256. {
  257. _CompleteShellHWDetectionInitialization();
  258. }
  259. CHWDeviceCustomPropertiesImpl::~CHWDeviceCustomPropertiesImpl()
  260. {
  261. if (_pelemToRelease)
  262. {
  263. _pelemToRelease->RCRelease();
  264. }
  265. }