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.

377 lines
7.5 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. if(pLarge)
  175. {
  176. pLarge->Release();
  177. pLarge = NULL;
  178. }
  179. return hr;
  180. }
  181. HRESULT
  182. PackVARIANT_BOOLinVariant(
  183. VARIANT_BOOL fValue,
  184. VARIANT * pvarInputData
  185. )
  186. {
  187. VariantInit(pvarInputData);
  188. pvarInputData->vt = VT_BOOL;
  189. V_BOOL(pvarInputData) = fValue;
  190. RRETURN(S_OK);
  191. }
  192. HRESULT
  193. UnpackVARIANT_BOOLfromVariant(
  194. VARIANT varSrcData,
  195. VARIANT_BOOL * pfValue
  196. )
  197. {
  198. if( varSrcData.vt != VT_BOOL){
  199. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  200. }
  201. *pfValue = V_BOOL(&varSrcData);
  202. RRETURN(S_OK);
  203. }
  204. HRESULT
  205. PackVARIANTinVariant(
  206. VARIANT vaValue,
  207. VARIANT * pvarInputData
  208. )
  209. {
  210. VariantInit(pvarInputData);
  211. pvarInputData->vt = VT_VARIANT;
  212. RRETURN( VariantCopy( pvarInputData, &vaValue ));
  213. }
  214. HRESULT
  215. UnpackVARIANTfromVariant(
  216. VARIANT varSrcData,
  217. VARIANT * pvaValue
  218. )
  219. {
  220. VariantInit( pvaValue );
  221. RRETURN( VariantCopy( pvaValue, &varSrcData ));
  222. }
  223. HRESULT
  224. PackDATEinLONGVariant(
  225. DATE daValue,
  226. VARIANT * pvarInputData
  227. )
  228. {
  229. LONG lValue;
  230. HRESULT hr = S_OK;
  231. SYSTEMTIME stSystemTime;
  232. SYSTEMTIME LocalTime;
  233. FILETIME LocalFileTime;
  234. FILETIME FileTimeCurrent;
  235. DATE date ;
  236. BOOL fRetval;
  237. VariantInit(pvarInputData);
  238. if( hr = ConvertDATEToSYSTEMTIME(daValue,
  239. &LocalTime)
  240. ) {
  241. RRETURN( hr );
  242. }
  243. fRetval = SystemTimeToFileTime(&LocalTime,
  244. &LocalFileTime);
  245. if(!fRetval){
  246. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  247. }
  248. fRetval = LocalFileTimeToFileTime(
  249. &LocalFileTime,
  250. &FileTimeCurrent
  251. );
  252. if(!fRetval){
  253. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  254. }
  255. fRetval = FileTimeToSystemTime(&FileTimeCurrent,
  256. &stSystemTime);
  257. if(!fRetval){
  258. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  259. }
  260. lValue = stSystemTime.wHour * 60 + stSystemTime.wMinute;
  261. pvarInputData->vt = VT_I4;
  262. V_I4(pvarInputData) = lValue;
  263. RRETURN(S_OK);
  264. }
  265. HRESULT
  266. UnpackDATEfromLONGVariant(
  267. VARIANT varSrcData,
  268. DATE * pdaValue
  269. )
  270. {
  271. LONG lValue;
  272. SYSTEMTIME stSystemTime;
  273. SYSTEMTIME LocalTime;
  274. DATE date ;
  275. BOOL fRetval;
  276. HRESULT hr = S_OK;
  277. if( varSrcData.vt != VT_I4){
  278. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  279. }
  280. lValue = V_I4(&varSrcData);
  281. GetSystemTime( &stSystemTime);
  282. stSystemTime.wHour = (WORD)(lValue)/60;
  283. stSystemTime.wMinute = (WORD)(lValue)%60;
  284. stSystemTime.wSecond =0;
  285. stSystemTime.wMilliseconds = 0;
  286. fRetval = SystemTimeToTzSpecificLocalTime(
  287. NULL,
  288. &stSystemTime,
  289. &LocalTime
  290. );
  291. if(!fRetval){
  292. RRETURN(HRESULT_FROM_WIN32(GetLastError()));
  293. }
  294. hr = ConvertSystemTimeToDATE (LocalTime,
  295. pdaValue);
  296. //lpVarDestObject->date = date - (DWORD)date;
  297. RRETURN(hr);
  298. }