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.

265 lines
5.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. if (FileTimeToLocalFileTime(&filetime, &locFiletime) == 0) {
  152. hr = E_FAIL;
  153. BAIL_ON_FAILURE(hr);
  154. }
  155. if (FileTimeToSystemTime(&locFiletime,
  156. &systemtime) == 0) {
  157. hr = E_FAIL;
  158. BAIL_ON_FAILURE(hr);
  159. }
  160. if (SystemTimeToVariantTime(&systemtime,
  161. &date) == 0) {
  162. hr = E_FAIL;
  163. BAIL_ON_FAILURE(hr);
  164. }
  165. *pdaValue = date;
  166. error:
  167. return hr;
  168. }
  169. HRESULT
  170. PackVARIANT_BOOLinVariant(
  171. VARIANT_BOOL fValue,
  172. VARIANT * pvarInputData
  173. )
  174. {
  175. VariantInit(pvarInputData);
  176. pvarInputData->vt = VT_BOOL;
  177. V_BOOL(pvarInputData) = fValue;
  178. RRETURN(S_OK);
  179. }
  180. HRESULT
  181. UnpackVARIANT_BOOLfromVariant(
  182. VARIANT varSrcData,
  183. VARIANT_BOOL * pfValue
  184. )
  185. {
  186. if( varSrcData.vt != VT_BOOL){
  187. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  188. }
  189. *pfValue = V_BOOL(&varSrcData);
  190. RRETURN(S_OK);
  191. }
  192. HRESULT
  193. PackVARIANTinVariant(
  194. VARIANT vaValue,
  195. VARIANT * pvarInputData
  196. )
  197. {
  198. VariantInit(pvarInputData);
  199. pvarInputData->vt = VT_VARIANT;
  200. RRETURN( VariantCopy( pvarInputData, &vaValue ));
  201. }
  202. HRESULT
  203. UnpackVARIANTfromVariant(
  204. VARIANT varSrcData,
  205. VARIANT * pvaValue
  206. )
  207. {
  208. VariantInit( pvaValue );
  209. RRETURN( VariantCopy( pvaValue, &varSrcData ));
  210. }