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.

184 lines
3.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ods2nw.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "nwcompat.hxx"
  18. #pragma hdrstop
  19. HRESULT
  20. AdsTypeToNTTypeCopyCaseIgnoreString(
  21. PADSVALUE lpAdsSrcValue,
  22. PNTOBJECT lpNtDestObject
  23. )
  24. {
  25. HRESULT hr = S_OK;
  26. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  27. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  28. }
  29. lpNtDestObject->NTType = NT_SYNTAX_ID_LPTSTR;
  30. lpNtDestObject->NTValue.pszValue =
  31. AllocADsStr(
  32. lpAdsSrcValue->CaseIgnoreString
  33. );
  34. if ((!lpNtDestObject->NTValue.pszValue) &&
  35. (lpAdsSrcValue->CaseIgnoreString)) {
  36. RRETURN(E_OUTOFMEMORY);
  37. }
  38. RRETURN(hr);
  39. }
  40. HRESULT
  41. AdsTypeToNTTypeCopyBoolean(
  42. PADSVALUE lpAdsSrcValue,
  43. PNTOBJECT lpNtDestObject
  44. )
  45. {
  46. HRESULT hr = S_OK;
  47. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  48. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  49. }
  50. lpNtDestObject->NTType = NT_SYNTAX_ID_BOOL;
  51. lpNtDestObject->NTValue.fValue =
  52. lpAdsSrcValue->Boolean;
  53. RRETURN(hr);
  54. }
  55. HRESULT
  56. AdsTypeToNTTypeCopyInteger(
  57. PADSVALUE lpAdsSrcValue,
  58. PNTOBJECT lpNtDestObject
  59. )
  60. {
  61. HRESULT hr = S_OK;
  62. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  63. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  64. }
  65. lpNtDestObject->NTType = NT_SYNTAX_ID_DWORD;
  66. lpNtDestObject->NTValue.dwValue =
  67. lpAdsSrcValue->Integer;
  68. RRETURN(hr);
  69. }
  70. HRESULT
  71. AdsTypeToNTTypeCopy(
  72. PADSVALUE lpAdsSrcValue,
  73. PNTOBJECT lpNtDestObject
  74. )
  75. {
  76. HRESULT hr = S_OK;
  77. switch (lpAdsSrcValue->dwType){
  78. case ADSTYPE_CASE_IGNORE_STRING:
  79. hr = AdsTypeToNTTypeCopyCaseIgnoreString(
  80. lpAdsSrcValue,
  81. lpNtDestObject
  82. );
  83. break;
  84. case ADSTYPE_BOOLEAN:
  85. hr = AdsTypeToNTTypeCopyBoolean(
  86. lpAdsSrcValue,
  87. lpNtDestObject
  88. );
  89. break;
  90. case ADSTYPE_INTEGER:
  91. hr = AdsTypeToNTTypeCopyInteger(
  92. lpAdsSrcValue,
  93. lpNtDestObject
  94. );
  95. break;
  96. default:
  97. hr = E_FAIL;
  98. break;
  99. }
  100. RRETURN(hr);
  101. }
  102. HRESULT
  103. AdsTypeToNTTypeCopyConstruct(
  104. LPADSVALUE pAdsSrcValues,
  105. DWORD dwNumObjects,
  106. LPNTOBJECT * ppNtDestObjects,
  107. PDWORD pdwNumNdsObjects,
  108. PDWORD pdwNdsSyntaxId
  109. )
  110. {
  111. DWORD i = 0;
  112. LPNTOBJECT pNtDestObjects = NULL;
  113. HRESULT hr = S_OK;
  114. pNtDestObjects = (LPNTOBJECT)AllocADsMem(
  115. dwNumObjects * sizeof(NTOBJECT)
  116. );
  117. if (!pNtDestObjects) {
  118. RRETURN(E_FAIL);
  119. }
  120. for (i = 0; i < dwNumObjects; i++ ) {
  121. hr = AdsTypeToNTTypeCopy(
  122. pAdsSrcValues + i,
  123. pNtDestObjects + i
  124. );
  125. BAIL_ON_FAILURE(hr);
  126. }
  127. *ppNtDestObjects = pNtDestObjects;
  128. *pdwNumNdsObjects = dwNumObjects;
  129. *pdwNdsSyntaxId = pNtDestObjects->NTType;
  130. RRETURN(S_OK);
  131. error:
  132. if (pNtDestObjects) {
  133. NTTypeFreeNTObjects(
  134. pNtDestObjects,
  135. dwNumObjects
  136. );
  137. }
  138. *ppNtDestObjects = NULL;
  139. *pdwNumNdsObjects = 0;
  140. RRETURN(hr);
  141. }
  142.