Source code of Windows XP (NT5)
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.

390 lines
7.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: var2nw.cxx
  7. //
  8. // Contents:
  9. //
  10. // Functions:
  11. //
  12. // History: 13-June-1996 KrishnaG Created.
  13. //
  14. //
  15. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //----------------------------------------------------------------------------
  18. #include "nwcompat.hxx"
  19. #pragma hdrstop
  20. //
  21. // WinNT objects copy code
  22. //
  23. HRESULT
  24. VarTypeToWinNTTypeCopyBOOL(
  25. PVARIANT lpVarSrcObject,
  26. PNTOBJECT pNTDestValue
  27. )
  28. {
  29. HRESULT hr = S_OK;
  30. if(!lpVarSrcObject){
  31. RRETURN(E_POINTER);
  32. }
  33. if(lpVarSrcObject->vt != VT_BOOL){
  34. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  35. }
  36. pNTDestValue->NTType = NT_SYNTAX_ID_BOOL;
  37. if(lpVarSrcObject->boolVal){
  38. (pNTDestValue->NTValue).fValue = TRUE;
  39. } else {
  40. (pNTDestValue->NTValue).fValue = FALSE;
  41. }
  42. RRETURN(hr);
  43. }
  44. HRESULT
  45. VarTypeToWinNTTypeCopySYSTEMTIME(
  46. PVARIANT lpVarSrcObject,
  47. PNTOBJECT pNTDestValue
  48. )
  49. {
  50. HRESULT hr = S_OK;
  51. if(!lpVarSrcObject){
  52. RRETURN(E_POINTER);
  53. }
  54. if(lpVarSrcObject->vt != VT_DATE){
  55. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  56. }
  57. hr = ConvertDATEToSYSTEMTIME(lpVarSrcObject->date,
  58. &(pNTDestValue->NTValue.stSystemTimeValue) );
  59. RRETURN( hr );
  60. }
  61. HRESULT
  62. VarTypeToWinNTTypeCopyDWORD(
  63. PVARIANT lpVarSrcObject,
  64. PNTOBJECT pNTDestValue
  65. )
  66. {
  67. HRESULT hr = S_OK;
  68. if(lpVarSrcObject->vt != VT_I4){
  69. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  70. }
  71. pNTDestValue->NTType = NT_SYNTAX_ID_DWORD;
  72. (pNTDestValue->NTValue).dwValue = (DWORD)lpVarSrcObject->lVal;
  73. RRETURN(hr);
  74. }
  75. HRESULT
  76. VarTypeToWinNTTypeCopyDATE(
  77. PVARIANT lpVarSrcObject,
  78. PNTOBJECT pNTDestValue
  79. )
  80. {
  81. HRESULT hr = S_OK;
  82. SYSTEMTIME stTime;
  83. if(lpVarSrcObject->vt != VT_DATE){
  84. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  85. }
  86. pNTDestValue->NTType = NT_SYNTAX_ID_DATE;
  87. //
  88. // Note carefully! date is supplied as a value which is < 1 however
  89. // VariantTimeToDosDateTime complains when given a value < 30000.
  90. // (Number of days between 1900 and 1980). So
  91. // we add 35000 to make it a legal value.
  92. //
  93. hr = ConvertDATEToSYSTEMTIME(lpVarSrcObject->date+ 35000,
  94. &stTime);
  95. BAIL_ON_FAILURE(hr);
  96. (pNTDestValue->NTValue).dwValue = stTime.wHour*60 + stTime.wMinute ;
  97. error:
  98. RRETURN(hr);
  99. }
  100. HRESULT
  101. VarTypeToWinNTTypeCopyNW312DATE(
  102. PVARIANT lpVarSrcObject,
  103. PNTOBJECT pNTDestValue
  104. )
  105. {
  106. HRESULT hr = S_OK;
  107. SYSTEMTIME stTime;
  108. if(lpVarSrcObject->vt != VT_DATE){
  109. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  110. }
  111. pNTDestValue->NTType = NT_SYNTAX_ID_NW312DATE;
  112. hr = ConvertVariantToNW312Date(
  113. lpVarSrcObject->date,
  114. pNTDestValue->NTValue.Nw312Date
  115. );
  116. BAIL_ON_FAILURE(hr);
  117. error:
  118. RRETURN(hr);
  119. }
  120. HRESULT
  121. VarTypeToWinNTTypeCopyLPTSTR(
  122. PVARIANT lpVarSrcObject,
  123. PNTOBJECT pNTDestValue
  124. )
  125. {
  126. HRESULT hr = S_OK;
  127. if(lpVarSrcObject->vt != VT_BSTR){
  128. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  129. }
  130. pNTDestValue->NTType = NT_SYNTAX_ID_LPTSTR;
  131. (pNTDestValue->NTValue).pszValue =
  132. AllocADsStr(lpVarSrcObject->bstrVal);
  133. if(!(pNTDestValue->NTValue).pszValue){
  134. hr = E_OUTOFMEMORY;
  135. }
  136. RRETURN(hr);
  137. }
  138. HRESULT
  139. VarTypeToWinNTTypeCopyDelimitedString(
  140. PVARIANT lpVarSrcObject,
  141. PNTOBJECT pNTDestValue
  142. )
  143. {
  144. HRESULT hr = S_OK;
  145. if (!(V_VT(lpVarSrcObject) == (VT_VARIANT|VT_ARRAY))) {
  146. RRETURN(E_FAIL);
  147. }
  148. pNTDestValue->NTType = NT_SYNTAX_ID_DelimitedString;
  149. hr = VariantToDelimitedString(*lpVarSrcObject,
  150. &((pNTDestValue->NTValue).pszValue),
  151. TEXT(','));
  152. RRETURN(hr);
  153. }
  154. HRESULT
  155. VarTypeToWinNTTypeCopyOctetString(
  156. PVARIANT lpVarSrcObject,
  157. PNTOBJECT pNTDestValue
  158. )
  159. {
  160. HRESULT hr = S_OK;
  161. pNTDestValue->NTType = NT_SYNTAX_ID_OCTETSTRING;
  162. hr = VariantToBinary(
  163. lpVarSrcObject,
  164. &(pNTDestValue->NTValue).octetstring.dwSize,
  165. &(pNTDestValue->NTValue).octetstring.pByte);
  166. RRETURN(hr);
  167. }
  168. HRESULT
  169. VarTypeToWinNTTypeCopyNulledString(
  170. PVARIANT lpVarSrcObject,
  171. PNTOBJECT pNTDestValue
  172. )
  173. {
  174. HRESULT hr = S_OK;
  175. if(!(V_VT(lpVarSrcObject) == (VT_VARIANT|VT_ARRAY))) {
  176. RRETURN(E_FAIL);
  177. }
  178. pNTDestValue->NTType = NT_SYNTAX_ID_NulledString;
  179. hr = VariantToNulledString(*lpVarSrcObject,
  180. &((pNTDestValue->NTValue).pszValue) );
  181. RRETURN(hr);
  182. }
  183. HRESULT
  184. VarTypeToNtTypeCopy(
  185. DWORD dwNtType,
  186. PVARIANT lpVarSrcObject,
  187. PNTOBJECT lpNtDestObject
  188. )
  189. {
  190. HRESULT hr = S_OK;
  191. switch (dwNtType){
  192. case NT_SYNTAX_ID_BOOL:
  193. hr = VarTypeToWinNTTypeCopyBOOL(
  194. lpVarSrcObject,
  195. lpNtDestObject
  196. );
  197. break;
  198. case NT_SYNTAX_ID_SYSTEMTIME:
  199. hr = VarTypeToWinNTTypeCopySYSTEMTIME(
  200. lpVarSrcObject,
  201. lpNtDestObject
  202. );
  203. break;
  204. case NT_SYNTAX_ID_DWORD:
  205. hr = VarTypeToWinNTTypeCopyDWORD(
  206. lpVarSrcObject,
  207. lpNtDestObject
  208. );
  209. break;
  210. case NT_SYNTAX_ID_DATE:
  211. hr = VarTypeToWinNTTypeCopyDATE(
  212. lpVarSrcObject,
  213. lpNtDestObject
  214. );
  215. break;
  216. case NT_SYNTAX_ID_NW312DATE:
  217. hr = VarTypeToWinNTTypeCopyNW312DATE(
  218. lpVarSrcObject,
  219. lpNtDestObject
  220. );
  221. break;
  222. case NT_SYNTAX_ID_LPTSTR:
  223. hr = VarTypeToWinNTTypeCopyLPTSTR(
  224. lpVarSrcObject,
  225. lpNtDestObject
  226. );
  227. break;
  228. case NT_SYNTAX_ID_DelimitedString:
  229. hr = VarTypeToWinNTTypeCopyDelimitedString(
  230. lpVarSrcObject,
  231. lpNtDestObject
  232. );
  233. break;
  234. case NT_SYNTAX_ID_NulledString:
  235. hr = VarTypeToWinNTTypeCopyNulledString(
  236. lpVarSrcObject,
  237. lpNtDestObject
  238. );
  239. break;
  240. case NT_SYNTAX_ID_OCTETSTRING:
  241. hr = VarTypeToWinNTTypeCopyOctetString(
  242. lpVarSrcObject,
  243. lpNtDestObject
  244. );
  245. break;
  246. default:
  247. hr = E_FAIL;
  248. break;
  249. }
  250. RRETURN(hr);
  251. }
  252. HRESULT
  253. VarTypeToNtTypeCopyConstruct(
  254. DWORD dwNtType,
  255. LPVARIANT pVarSrcObjects,
  256. DWORD dwNumObjects,
  257. LPNTOBJECT * ppNtDestObjects
  258. )
  259. {
  260. DWORD i = 0;
  261. LPNTOBJECT pNtDestObjects = NULL;
  262. HRESULT hr = S_OK;
  263. pNtDestObjects = (LPNTOBJECT)AllocADsMem(
  264. dwNumObjects * sizeof(NTOBJECT)
  265. );
  266. if (!pNtDestObjects) {
  267. RRETURN(E_FAIL);
  268. }
  269. for (i = 0; i < dwNumObjects; i++ ) {
  270. hr = VarTypeToNtTypeCopy(
  271. dwNtType,
  272. pVarSrcObjects + i,
  273. pNtDestObjects + i
  274. );
  275. BAIL_ON_FAILURE(hr);
  276. }
  277. *ppNtDestObjects = pNtDestObjects;
  278. RRETURN(S_OK);
  279. error:
  280. if (pNtDestObjects) {
  281. FreeADsMem(pNtDestObjects);
  282. }
  283. *ppNtDestObjects = NULL;
  284. RRETURN(hr);
  285. }