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.

476 lines
8.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: nw2var.cxx
  7. //
  8. // Contents: Nw312 Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 06/12/96 KrishnaG created.
  13. // cloned off NDS conversion code.
  14. //
  15. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //----------------------------------------------------------------------------
  18. //
  19. // NTType objects copy code
  20. //
  21. #include "nwcompat.hxx"
  22. #pragma hdrstop
  23. void
  24. VarTypeFreeVarObjects(
  25. PVARIANT pVarObject,
  26. DWORD dwNumValues
  27. )
  28. {
  29. DWORD i = 0;
  30. if( !pVarObject){
  31. return;
  32. }
  33. for (i = 0; i < dwNumValues; i++ ) {
  34. VariantClear(pVarObject + i);
  35. }
  36. FreeADsMem(pVarObject);
  37. return;
  38. }
  39. HRESULT
  40. NTTypeToVarTypeCopyBOOL(
  41. PNTOBJECT pNTSrcValue,
  42. PVARIANT lpVarDestObject
  43. )
  44. {
  45. HRESULT hr = S_OK;
  46. if(!lpVarDestObject){
  47. RRETURN(E_POINTER);
  48. }
  49. if(!pNTSrcValue){
  50. RRETURN(E_POINTER);
  51. }
  52. lpVarDestObject->vt = VT_BOOL;
  53. if((pNTSrcValue->NTValue).fValue){
  54. lpVarDestObject->boolVal = VARIANT_TRUE; // notation for TRUE in V_BOOL
  55. } else {
  56. lpVarDestObject->boolVal = VARIANT_FALSE;
  57. }
  58. RRETURN(hr);
  59. }
  60. HRESULT
  61. NTTypeToVarTypeCopySYSTEMTIME(
  62. PNTOBJECT pNTSrcValue,
  63. PVARIANT lpVarDestObject
  64. )
  65. {
  66. HRESULT hr = S_OK;
  67. if(!pNTSrcValue){
  68. RRETURN(E_POINTER);
  69. }
  70. if(!lpVarDestObject){
  71. RRETURN(E_POINTER);
  72. }
  73. lpVarDestObject->vt = VT_DATE;
  74. hr = ConvertSystemTimeToDATE (pNTSrcValue->NTValue.stSystemTimeValue,
  75. &lpVarDestObject->date );
  76. RRETURN(hr);
  77. }
  78. HRESULT
  79. NTTypeToVarTypeCopyDWORD(
  80. PNTOBJECT pNTSrcValue,
  81. PVARIANT lpVarDestObject
  82. )
  83. {
  84. //
  85. // we cast the DWORD to a LONG
  86. //
  87. HRESULT hr = S_OK;
  88. if(!lpVarDestObject){
  89. RRETURN(E_POINTER);
  90. }
  91. if(!pNTSrcValue){
  92. RRETURN(E_POINTER);
  93. }
  94. lpVarDestObject->vt = VT_I4;
  95. lpVarDestObject->lVal = (LONG)(pNTSrcValue->NTValue).dwValue;
  96. RRETURN(hr);
  97. }
  98. HRESULT
  99. NTTypeToVarTypeCopyDATE(
  100. PNTOBJECT pNTSrcValue,
  101. PVARIANT lpVarDestObject
  102. )
  103. {
  104. HRESULT hr = S_OK;
  105. SYSTEMTIME stSystemTime;
  106. SYSTEMTIME LocalTime;
  107. DATE date ;
  108. BOOL fRetval;
  109. GetSystemTime( &stSystemTime);
  110. fRetval = SystemTimeToTzSpecificLocalTime(
  111. NULL,
  112. &stSystemTime,
  113. &LocalTime
  114. );
  115. if(!fRetval){
  116. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  117. }
  118. stSystemTime.wHour = (WORD)(pNTSrcValue->NTValue.dwValue)/60;
  119. stSystemTime.wMinute = (WORD)(pNTSrcValue->NTValue.dwValue)%60;
  120. stSystemTime.wSecond =0;
  121. stSystemTime.wMilliseconds = 0;
  122. if(!lpVarDestObject){
  123. RRETURN(E_POINTER);
  124. }
  125. if(!pNTSrcValue){
  126. RRETURN(E_POINTER);
  127. }
  128. lpVarDestObject->vt = VT_DATE;
  129. hr = ConvertSystemTimeToDATE (stSystemTime,
  130. &date );
  131. lpVarDestObject->date = date - (DWORD)date;
  132. BAIL_ON_FAILURE(hr);
  133. error:
  134. RRETURN(hr);
  135. }
  136. HRESULT
  137. NTTypeToVarTypeCopyNW312DATE(
  138. PNTOBJECT pNTSrcValue,
  139. PVARIANT lpVarDestObject
  140. )
  141. {
  142. HRESULT hr = S_OK;
  143. SYSTEMTIME stSystemTime;
  144. SYSTEMTIME LocalTime;
  145. DATE date ;
  146. BOOL fRetval;
  147. if(!lpVarDestObject){
  148. RRETURN(E_POINTER);
  149. }
  150. if(!pNTSrcValue){
  151. RRETURN(E_POINTER);
  152. }
  153. lpVarDestObject->vt = VT_DATE;
  154. hr = ConvertNW312DateToVariant(
  155. pNTSrcValue->NTValue.Nw312Date,
  156. &lpVarDestObject->date
  157. );
  158. BAIL_ON_FAILURE(hr);
  159. error:
  160. RRETURN(hr);
  161. }
  162. HRESULT
  163. NTTypeToVarTypeCopyOctetString(
  164. PNTOBJECT pNTSrcValue,
  165. PVARIANT lpVarDestObject
  166. )
  167. {
  168. HRESULT hr = S_OK;
  169. if(!lpVarDestObject){
  170. RRETURN(E_POINTER);
  171. }
  172. hr = BinaryToVariant(
  173. (pNTSrcValue->NTValue).octetstring.dwSize,
  174. (pNTSrcValue->NTValue).octetstring.pByte,
  175. lpVarDestObject
  176. );
  177. RRETURN(hr);
  178. }
  179. HRESULT
  180. NTTypeToVarTypeCopyLPTSTR(
  181. PNTOBJECT pNTSrcValue,
  182. PVARIANT lpVarDestObject
  183. )
  184. {
  185. HRESULT hr = S_OK;
  186. if(!lpVarDestObject){
  187. RRETURN(E_POINTER);
  188. }
  189. lpVarDestObject->vt = VT_BSTR;
  190. if(!(pNTSrcValue->NTValue).pszValue){
  191. lpVarDestObject->bstrVal = NULL;
  192. hr = S_OK;
  193. goto error;
  194. }
  195. if(!pNTSrcValue){
  196. lpVarDestObject->bstrVal = NULL;
  197. } else {
  198. hr = ADsAllocString((pNTSrcValue->NTValue).pszValue,
  199. &(lpVarDestObject->bstrVal));
  200. }
  201. error:
  202. RRETURN(hr);
  203. }
  204. HRESULT
  205. NTTypeToVarTypeCopyDelimitedString(
  206. PNTOBJECT pNTSrcValue,
  207. PVARIANT lpVarDestObject
  208. )
  209. {
  210. HRESULT hr = S_OK;
  211. if(!lpVarDestObject){
  212. RRETURN(E_POINTER);
  213. }
  214. if(!pNTSrcValue){
  215. RRETURN(E_POINTER);
  216. } else {
  217. hr = DelimitedStringToVariant((pNTSrcValue->NTValue).pszValue,
  218. lpVarDestObject,
  219. TEXT(',') );
  220. }
  221. RRETURN(hr);
  222. }
  223. HRESULT
  224. NTTypeToVarTypeCopyNulledString(
  225. PNTOBJECT pNTSrcValue,
  226. PVARIANT lpVarDestObject
  227. )
  228. {
  229. HRESULT hr = S_OK;
  230. if(!pNTSrcValue){
  231. RRETURN(E_POINTER);
  232. }
  233. if(!lpVarDestObject){
  234. RRETURN(E_POINTER);
  235. }
  236. if(!(pNTSrcValue->NTValue).pszValue){
  237. RRETURN(E_POINTER);
  238. }
  239. hr = NulledStringToVariant((pNTSrcValue->NTValue).pszValue,
  240. lpVarDestObject );
  241. RRETURN(hr);
  242. }
  243. HRESULT
  244. NtTypeToVarTypeCopy(
  245. PNTOBJECT lpNtSrcObject,
  246. PVARIANT lpVarDestObject
  247. )
  248. {
  249. HRESULT hr = S_OK;
  250. switch (lpNtSrcObject->NTType) {
  251. case NT_SYNTAX_ID_BOOL:
  252. hr = NTTypeToVarTypeCopyBOOL(
  253. lpNtSrcObject,
  254. lpVarDestObject
  255. );
  256. break;
  257. case NT_SYNTAX_ID_SYSTEMTIME:
  258. hr = NTTypeToVarTypeCopySYSTEMTIME(
  259. lpNtSrcObject,
  260. lpVarDestObject
  261. );
  262. break;
  263. case NT_SYNTAX_ID_DWORD:
  264. hr = NTTypeToVarTypeCopyDWORD(
  265. lpNtSrcObject,
  266. lpVarDestObject
  267. );
  268. break;
  269. case NT_SYNTAX_ID_DATE:
  270. hr = NTTypeToVarTypeCopyDATE(
  271. lpNtSrcObject,
  272. lpVarDestObject
  273. );
  274. break;
  275. case NT_SYNTAX_ID_NW312DATE:
  276. hr = NTTypeToVarTypeCopyNW312DATE(
  277. lpNtSrcObject,
  278. lpVarDestObject
  279. );
  280. break;
  281. case NT_SYNTAX_ID_LPTSTR:
  282. hr = NTTypeToVarTypeCopyLPTSTR(
  283. lpNtSrcObject,
  284. lpVarDestObject
  285. );
  286. break;
  287. case NT_SYNTAX_ID_DelimitedString:
  288. hr = NTTypeToVarTypeCopyDelimitedString(
  289. lpNtSrcObject,
  290. lpVarDestObject
  291. );
  292. break;
  293. case NT_SYNTAX_ID_NulledString :
  294. hr = NTTypeToVarTypeCopyNulledString(
  295. lpNtSrcObject,
  296. lpVarDestObject
  297. );
  298. break;
  299. case NT_SYNTAX_ID_OCTETSTRING :
  300. hr = NTTypeToVarTypeCopyOctetString(
  301. lpNtSrcObject,
  302. lpVarDestObject
  303. );
  304. break;
  305. default:
  306. hr = E_FAIL;
  307. break;
  308. }
  309. RRETURN(hr);
  310. }
  311. HRESULT
  312. NtTypeToVarTypeCopyConstruct(
  313. LPNTOBJECT pNtSrcObjects,
  314. DWORD dwNumObjects,
  315. PVARIANT pVarDestObjects
  316. )
  317. {
  318. long i = 0;
  319. HRESULT hr = S_OK;
  320. VariantInit(pVarDestObjects);
  321. //
  322. // The following are for handling are multi-value properties
  323. //
  324. SAFEARRAY *aList = NULL;
  325. SAFEARRAYBOUND aBound;
  326. aBound.lLbound = 0;
  327. aBound.cElements = dwNumObjects;
  328. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  329. if ( aList == NULL )
  330. {
  331. hr = E_OUTOFMEMORY;
  332. BAIL_ON_FAILURE(hr);
  333. }
  334. for ( i = 0; i < (long) dwNumObjects; i++ )
  335. {
  336. VARIANT v;
  337. VariantInit(&v);
  338. hr = NtTypeToVarTypeCopy( pNtSrcObjects + i,
  339. &v );
  340. BAIL_ON_FAILURE(hr);
  341. hr = SafeArrayPutElement( aList, &i, &v );
  342. VariantClear(&v);
  343. BAIL_ON_FAILURE(hr);
  344. }
  345. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  346. V_ARRAY(pVarDestObjects) = aList;
  347. RRETURN(S_OK);
  348. error:
  349. if ( aList )
  350. SafeArrayDestroy( aList );
  351. RRETURN(hr);
  352. }