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.

370 lines
7.0 KiB

  1. #include "procs.hxx"
  2. #pragma hdrstop
  3. #include "macro.h"
  4. HRESULT
  5. PackStringinVariant(
  6. BSTR bstrString,
  7. VARIANT * pvarInputData
  8. )
  9. {
  10. HRESULT hr = S_OK;
  11. if ( bstrString == NULL )
  12. RRETURN(E_FAIL);
  13. VariantInit(pvarInputData);
  14. pvarInputData->vt = VT_BSTR;
  15. if (!bstrString) {
  16. V_BSTR(pvarInputData) = NULL;
  17. RRETURN(S_OK);
  18. }
  19. hr = ADsAllocString(bstrString, &(V_BSTR(pvarInputData)));
  20. RRETURN(hr);
  21. }
  22. HRESULT
  23. UnpackStringfromVariant(
  24. VARIANT varSrcData,
  25. BSTR * pbstrDestString
  26. )
  27. {
  28. HRESULT hr = S_OK;
  29. if( varSrcData.vt != VT_BSTR){
  30. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  31. }
  32. if (!V_BSTR(&varSrcData)) {
  33. *pbstrDestString = NULL;
  34. RRETURN(S_OK);
  35. }
  36. hr = ADsAllocString(V_BSTR(&varSrcData), pbstrDestString);
  37. RRETURN(hr);
  38. }
  39. HRESULT
  40. PackLONGinVariant(
  41. LONG lValue,
  42. VARIANT * pvarInputData
  43. )
  44. {
  45. VariantInit(pvarInputData);
  46. pvarInputData->vt = VT_I4;
  47. V_I4(pvarInputData) = lValue;
  48. RRETURN(S_OK);
  49. }
  50. HRESULT
  51. UnpackLONGfromVariant(
  52. VARIANT varSrcData,
  53. LONG * plValue
  54. )
  55. {
  56. if( varSrcData.vt != VT_I4){
  57. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  58. }
  59. *plValue = V_I4(&varSrcData);
  60. RRETURN(S_OK);
  61. }
  62. HRESULT
  63. PackDATEinVariant(
  64. DATE daValue,
  65. VARIANT * pvarInputData
  66. )
  67. {
  68. VariantInit(pvarInputData);
  69. pvarInputData->vt = VT_DATE;
  70. V_DATE(pvarInputData) = daValue;
  71. RRETURN(S_OK);
  72. }
  73. HRESULT
  74. UnpackDATEfromVariant(
  75. VARIANT varSrcData,
  76. DATE * pdaValue
  77. )
  78. {
  79. if( varSrcData.vt != VT_DATE){
  80. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  81. }
  82. *pdaValue = V_DATE(&varSrcData);
  83. RRETURN(S_OK);
  84. }
  85. HRESULT
  86. PackFILETIMEinVariant(
  87. DATE daValue,
  88. VARIANT * pvarInputData
  89. )
  90. {
  91. IADsLargeInteger *pTime = NULL;
  92. VARIANT var;
  93. SYSTEMTIME systemtime;
  94. FILETIME filetime;
  95. HRESULT hr = S_OK;
  96. if (VariantTimeToSystemTime(daValue,
  97. &systemtime) == 0) {
  98. hr = E_FAIL;
  99. BAIL_ON_FAILURE(hr);
  100. }
  101. if (SystemTimeToFileTime(&systemtime,
  102. &filetime) == 0) {
  103. hr = E_FAIL;
  104. BAIL_ON_FAILURE(hr);
  105. }
  106. if (LocalFileTimeToFileTime(&filetime, &filetime ) == 0) {
  107. hr = E_FAIL;
  108. BAIL_ON_FAILURE(hr);
  109. }
  110. hr = CoCreateInstance(
  111. CLSID_LargeInteger,
  112. NULL,
  113. CLSCTX_ALL,
  114. IID_IADsLargeInteger,
  115. (void**)&pTime
  116. );
  117. BAIL_ON_FAILURE(hr);
  118. hr = pTime->put_HighPart(filetime.dwHighDateTime);
  119. BAIL_ON_FAILURE(hr);
  120. hr = pTime->put_LowPart(filetime.dwLowDateTime);
  121. BAIL_ON_FAILURE(hr);
  122. VariantInit(pvarInputData);
  123. pvarInputData->pdispVal = pTime;
  124. pvarInputData->vt = VT_DISPATCH;
  125. error:
  126. return hr;
  127. }
  128. HRESULT
  129. UnpackFILETIMEfromVariant(
  130. VARIANT varSrcData,
  131. DATE * pdaValue
  132. )
  133. {
  134. IADsLargeInteger *pLarge = NULL;
  135. IDispatch *pDispatch = NULL;
  136. FILETIME filetime;
  137. FILETIME locFiletime;
  138. SYSTEMTIME systemtime;
  139. DATE date;
  140. HRESULT hr = S_OK;
  141. if( varSrcData.vt != VT_DISPATCH){
  142. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  143. }
  144. pDispatch = varSrcData.pdispVal;
  145. hr = pDispatch->QueryInterface(IID_IADsLargeInteger, (VOID **) &pLarge);
  146. BAIL_ON_FAILURE(hr);
  147. hr = pLarge->get_HighPart((long*)&filetime.dwHighDateTime);
  148. BAIL_ON_FAILURE(hr);
  149. hr = pLarge->get_LowPart((long*)&filetime.dwLowDateTime);
  150. BAIL_ON_FAILURE(hr);
  151. //
  152. // time is "0" actually means that either user never logs on or property not known
  153. //
  154. if (filetime.dwLowDateTime == 0 && filetime.dwHighDateTime == 0) {
  155. hr = E_ADS_PROPERTY_NOT_FOUND;
  156. BAIL_ON_FAILURE(hr);
  157. }
  158. if (FileTimeToLocalFileTime(&filetime, &locFiletime) == 0) {
  159. hr = E_FAIL;
  160. BAIL_ON_FAILURE(hr);
  161. }
  162. if (FileTimeToSystemTime(&locFiletime,
  163. &systemtime) == 0) {
  164. hr = E_FAIL;
  165. BAIL_ON_FAILURE(hr);
  166. }
  167. if (SystemTimeToVariantTime(&systemtime,
  168. &date) == 0) {
  169. hr = E_FAIL;
  170. BAIL_ON_FAILURE(hr);
  171. }
  172. *pdaValue = date;
  173. error:
  174. return hr;
  175. }
  176. HRESULT
  177. PackVARIANT_BOOLinVariant(
  178. VARIANT_BOOL fValue,
  179. VARIANT * pvarInputData
  180. )
  181. {
  182. VariantInit(pvarInputData);
  183. pvarInputData->vt = VT_BOOL;
  184. V_BOOL(pvarInputData) = fValue;
  185. RRETURN(S_OK);
  186. }
  187. HRESULT
  188. UnpackVARIANT_BOOLfromVariant(
  189. VARIANT varSrcData,
  190. VARIANT_BOOL * pfValue
  191. )
  192. {
  193. if( varSrcData.vt != VT_BOOL){
  194. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  195. }
  196. *pfValue = V_BOOL(&varSrcData);
  197. RRETURN(S_OK);
  198. }
  199. HRESULT
  200. PackVARIANTinVariant(
  201. VARIANT vaValue,
  202. VARIANT * pvarInputData
  203. )
  204. {
  205. VariantInit(pvarInputData);
  206. pvarInputData->vt = VT_VARIANT;
  207. RRETURN( VariantCopy( pvarInputData, &vaValue ));
  208. }
  209. HRESULT
  210. UnpackVARIANTfromVariant(
  211. VARIANT varSrcData,
  212. VARIANT * pvaValue
  213. )
  214. {
  215. VariantInit( pvaValue );
  216. RRETURN( VariantCopy( pvaValue, &varSrcData ));
  217. }
  218. HRESULT
  219. PackDATEinLONGVariant(
  220. DATE daValue,
  221. VARIANT * pvarInputData
  222. )
  223. {
  224. LONG lValue;
  225. HRESULT hr = S_OK;
  226. SYSTEMTIME stSystemTime;
  227. SYSTEMTIME LocalTime;
  228. FILETIME LocalFileTime;
  229. FILETIME FileTimeCurrent;
  230. DATE date ;
  231. BOOL fRetval;
  232. VariantInit(pvarInputData);
  233. if( hr = ConvertDATEToSYSTEMTIME(daValue,
  234. &LocalTime)
  235. ) {
  236. RRETURN( hr );
  237. }
  238. fRetval = SystemTimeToFileTime(&LocalTime,
  239. &LocalFileTime);
  240. if(!fRetval){
  241. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  242. }
  243. fRetval = LocalFileTimeToFileTime(
  244. &LocalFileTime,
  245. &FileTimeCurrent
  246. );
  247. if(!fRetval){
  248. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  249. }
  250. fRetval = FileTimeToSystemTime(&FileTimeCurrent,
  251. &stSystemTime);
  252. if(!fRetval){
  253. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  254. }
  255. lValue = stSystemTime.wHour * 60 + stSystemTime.wMinute;
  256. pvarInputData->vt = VT_I4;
  257. V_I4(pvarInputData) = lValue;
  258. RRETURN(S_OK);
  259. }
  260. HRESULT
  261. UnpackDATEfromLONGVariant(
  262. VARIANT varSrcData,
  263. DATE * pdaValue
  264. )
  265. {
  266. LONG lValue;
  267. SYSTEMTIME stSystemTime;
  268. SYSTEMTIME LocalTime;
  269. DATE date ;
  270. BOOL fRetval;
  271. HRESULT hr = S_OK;
  272. if( varSrcData.vt != VT_I4){
  273. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  274. }
  275. lValue = V_I4(&varSrcData);
  276. GetSystemTime( &stSystemTime);
  277. stSystemTime.wHour = (WORD)(lValue)/60;
  278. stSystemTime.wMinute = (WORD)(lValue)%60;
  279. stSystemTime.wSecond =0;
  280. stSystemTime.wMilliseconds = 0;
  281. fRetval = SystemTimeToTzSpecificLocalTime(
  282. NULL,
  283. &stSystemTime,
  284. &LocalTime
  285. );
  286. if(!fRetval){
  287. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  288. }
  289. hr = ConvertSystemTimeToDATE (LocalTime,
  290. pdaValue);
  291. //lpVarDestObject->date = date - (DWORD)date;
  292. RRETURN(S_OK);
  293. }