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.

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