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.

272 lines
7.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C C O N V . C P P
  7. //
  8. // Contents: Common routines for dealing with the connections interfaces.
  9. //
  10. // Notes: Pollute this under penalty of death.
  11. //
  12. // Author: shaunco 20 Aug 1998
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ncnetcon.h"
  18. #include "ncconv.h"
  19. HRESULT SysCopyBString(BSTR *bstrDestination, const BSTR bstrSource)
  20. {
  21. HRESULT hr = S_OK;
  22. if (bstrSource)
  23. {
  24. *bstrDestination = SysAllocStringByteLen(reinterpret_cast<LPCSTR>(bstrSource), SysStringByteLen(bstrSource));
  25. if (!*bstrDestination)
  26. {
  27. return E_OUTOFMEMORY;
  28. }
  29. }
  30. else
  31. {
  32. *bstrDestination = SysAllocString(NULL);
  33. }
  34. return hr;
  35. }
  36. HRESULT CPropertiesEx::GetField(IN int nField, OUT VARIANT& varElement)
  37. {
  38. HRESULT hr = S_OK;
  39. WCHAR szGuid[MAX_GUID_STRING_LEN];
  40. switch (nField)
  41. {
  42. case NCP_DWSIZE:
  43. varElement.vt = VT_I4;
  44. varElement.ulVal = m_pPropsEx->dwSize;
  45. break;
  46. case NCP_GUIDID:
  47. if (StringFromGUID2(m_pPropsEx->guidId, szGuid, MAX_GUID_STRING_LEN))
  48. {
  49. varElement.vt = VT_BSTR;
  50. varElement.bstrVal = SysAllocString(szGuid);
  51. if (!varElement.bstrVal)
  52. {
  53. hr = E_OUTOFMEMORY;
  54. }
  55. }
  56. else
  57. {
  58. hr = E_INVALIDARG;
  59. }
  60. break;
  61. case NCP_BSTRNAME:
  62. varElement.vt = VT_BSTR;
  63. hr = SysCopyBString(&varElement.bstrVal, m_pPropsEx->bstrName);
  64. break;
  65. case NCP_BSTRDEVICENAME:
  66. varElement.vt = VT_BSTR;
  67. hr = SysCopyBString(&varElement.bstrVal, m_pPropsEx->bstrDeviceName);
  68. break;
  69. case NCP_NCSTATUS:
  70. varElement.vt = VT_I4;
  71. varElement.ulVal = m_pPropsEx->ncStatus;
  72. break;
  73. case NCP_MEDIATYPE:
  74. varElement.vt = VT_I4;
  75. varElement.ulVal = m_pPropsEx->ncMediaType;
  76. break;
  77. case NCP_SUBMEDIATYPE:
  78. varElement.vt = VT_I4;
  79. varElement.ulVal = m_pPropsEx->ncSubMediaType;
  80. break;
  81. case NCP_DWCHARACTER:
  82. varElement.vt = VT_I4;
  83. varElement.ulVal = m_pPropsEx->dwCharacter;
  84. break;
  85. case NCP_CLSIDTHISOBJECT:
  86. if (StringFromGUID2(m_pPropsEx->clsidThisObject, szGuid, MAX_GUID_STRING_LEN))
  87. {
  88. varElement.vt = VT_BSTR;
  89. varElement.bstrVal = SysAllocString(szGuid);
  90. if (!varElement.bstrVal)
  91. {
  92. hr = E_OUTOFMEMORY;
  93. }
  94. }
  95. else
  96. {
  97. hr = E_INVALIDARG;
  98. }
  99. break;
  100. case NCP_CLSIDUIOBJECT:
  101. if (StringFromGUID2(m_pPropsEx->clsidUiObject, szGuid, MAX_GUID_STRING_LEN))
  102. {
  103. varElement.vt = VT_BSTR;
  104. varElement.bstrVal = SysAllocString(szGuid);
  105. if (!varElement.bstrVal)
  106. {
  107. hr = E_OUTOFMEMORY;
  108. }
  109. }
  110. else
  111. {
  112. hr = E_INVALIDARG;
  113. }
  114. break;
  115. case NCP_BSTRPHONEORHOSTADDRESS:
  116. varElement.vt = VT_BSTR;
  117. hr = SysCopyBString(&varElement.bstrVal, m_pPropsEx->bstrPhoneOrHostAddress);
  118. break;
  119. case NCP_BSTRPERSISTDATA:
  120. varElement.vt = VT_BSTR;
  121. hr = SysCopyBString(&varElement.bstrVal, m_pPropsEx->bstrPersistData);
  122. break;
  123. default:
  124. AssertSz(FALSE, "Field is not in list, have you updated the list?");
  125. }
  126. AssertSz(SUCCEEDED(hr), "Could not GetField");
  127. TraceHr (ttidError, FAL, hr, FALSE, "GetField");
  128. return hr;
  129. }
  130. HRESULT CPropertiesEx::SetField(IN int nField, IN const VARIANT& varElement)
  131. {
  132. HRESULT hr = S_OK;
  133. switch (nField)
  134. {
  135. case NCP_DWSIZE:
  136. if (VT_I4 == varElement.vt)
  137. {
  138. m_pPropsEx->dwSize = varElement.ulVal;
  139. }
  140. else
  141. {
  142. hr = E_INVALIDARG;
  143. }
  144. break;
  145. case NCP_GUIDID:
  146. if (VT_BSTR == varElement.vt)
  147. {
  148. hr = CLSIDFromString(varElement.bstrVal, &m_pPropsEx->guidId);
  149. }
  150. else
  151. {
  152. hr = E_INVALIDARG;
  153. }
  154. break;
  155. case NCP_BSTRNAME:
  156. if (VT_BSTR == varElement.vt)
  157. {
  158. hr = SysCopyBString(&m_pPropsEx->bstrName, varElement.bstrVal);
  159. }
  160. else
  161. {
  162. hr = E_INVALIDARG;
  163. }
  164. break;
  165. case NCP_BSTRDEVICENAME:
  166. if (VT_BSTR == varElement.vt)
  167. {
  168. hr = SysCopyBString(&m_pPropsEx->bstrDeviceName, varElement.bstrVal);
  169. }
  170. else
  171. {
  172. hr = E_INVALIDARG;
  173. }
  174. break;
  175. case NCP_NCSTATUS:
  176. if (VT_I4 == varElement.vt)
  177. {
  178. m_pPropsEx->ncStatus = static_cast<NETCON_STATUS>(varElement.ulVal);
  179. }
  180. else
  181. {
  182. hr = E_INVALIDARG;
  183. }
  184. break;
  185. case NCP_MEDIATYPE:
  186. if (VT_I4 == varElement.vt)
  187. {
  188. m_pPropsEx->ncMediaType = static_cast<NETCON_MEDIATYPE>(varElement.ulVal);
  189. }
  190. else
  191. {
  192. hr = E_INVALIDARG;
  193. }
  194. break;
  195. case NCP_SUBMEDIATYPE:
  196. if (VT_I4 == varElement.vt)
  197. {
  198. m_pPropsEx->ncSubMediaType = static_cast<NETCON_SUBMEDIATYPE>(varElement.ulVal);
  199. }
  200. else
  201. {
  202. hr = E_INVALIDARG;
  203. }
  204. break;
  205. case NCP_DWCHARACTER:
  206. if (VT_I4 == varElement.vt)
  207. {
  208. m_pPropsEx->dwCharacter = varElement.ulVal;
  209. }
  210. else
  211. {
  212. hr = E_INVALIDARG;
  213. }
  214. break;
  215. case NCP_CLSIDTHISOBJECT:
  216. if (VT_BSTR == varElement.vt)
  217. {
  218. hr = CLSIDFromString(varElement.bstrVal, &m_pPropsEx->clsidThisObject);
  219. }
  220. else
  221. {
  222. hr = E_INVALIDARG;
  223. }
  224. break;
  225. case NCP_CLSIDUIOBJECT:
  226. if (VT_BSTR == varElement.vt)
  227. {
  228. hr = CLSIDFromString(varElement.bstrVal, &m_pPropsEx->clsidUiObject);
  229. }
  230. else
  231. {
  232. hr = E_INVALIDARG;
  233. }
  234. break;
  235. case NCP_BSTRPHONEORHOSTADDRESS:
  236. if (VT_BSTR == varElement.vt)
  237. {
  238. hr = SysCopyBString(&m_pPropsEx->bstrPhoneOrHostAddress, varElement.bstrVal);
  239. }
  240. else
  241. {
  242. hr = E_INVALIDARG;
  243. }
  244. break;
  245. case NCP_BSTRPERSISTDATA:
  246. if (VT_BSTR == varElement.vt)
  247. {
  248. hr = SysCopyBString(&m_pPropsEx->bstrPersistData, varElement.bstrVal);
  249. }
  250. else
  251. {
  252. hr = E_INVALIDARG;
  253. }
  254. break;
  255. default:
  256. AssertSz(FALSE, "Field is not in list, have you updated the list?");
  257. }
  258. TraceHr (ttidError, FAL, hr, FALSE, "SetField");
  259. return hr;
  260. }