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.

181 lines
3.5 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. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  16. //
  17. //----------------------------------------------------------------------------
  18. #include "nwcompat.hxx"
  19. #pragma hdrstop
  20. HRESULT
  21. AdsTypeToNTTypeCopyCaseIgnoreString(
  22. PADSVALUE lpAdsSrcValue,
  23. PNTOBJECT lpNtDestObject
  24. )
  25. {
  26. HRESULT hr = S_OK;
  27. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  28. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  29. }
  30. lpNtDestObject->NTType = NT_SYNTAX_ID_LPTSTR;
  31. lpNtDestObject->NTValue.pszValue =
  32. AllocADsStr(
  33. lpAdsSrcValue->CaseIgnoreString
  34. );
  35. RRETURN(hr);
  36. }
  37. HRESULT
  38. AdsTypeToNTTypeCopyBoolean(
  39. PADSVALUE lpAdsSrcValue,
  40. PNTOBJECT lpNtDestObject
  41. )
  42. {
  43. HRESULT hr = S_OK;
  44. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  45. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  46. }
  47. lpNtDestObject->NTType = NT_SYNTAX_ID_BOOL;
  48. lpNtDestObject->NTValue.fValue =
  49. lpAdsSrcValue->Boolean;
  50. RRETURN(hr);
  51. }
  52. HRESULT
  53. AdsTypeToNTTypeCopyInteger(
  54. PADSVALUE lpAdsSrcValue,
  55. PNTOBJECT lpNtDestObject
  56. )
  57. {
  58. HRESULT hr = S_OK;
  59. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  60. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  61. }
  62. lpNtDestObject->NTType = NT_SYNTAX_ID_DWORD;
  63. lpNtDestObject->NTValue.dwValue =
  64. lpAdsSrcValue->Integer;
  65. RRETURN(hr);
  66. }
  67. HRESULT
  68. AdsTypeToNTTypeCopy(
  69. PADSVALUE lpAdsSrcValue,
  70. PNTOBJECT lpNtDestObject
  71. )
  72. {
  73. HRESULT hr = S_OK;
  74. switch (lpAdsSrcValue->dwType){
  75. case ADSTYPE_CASE_IGNORE_STRING:
  76. hr = AdsTypeToNTTypeCopyCaseIgnoreString(
  77. lpAdsSrcValue,
  78. lpNtDestObject
  79. );
  80. break;
  81. case ADSTYPE_BOOLEAN:
  82. hr = AdsTypeToNTTypeCopyBoolean(
  83. lpAdsSrcValue,
  84. lpNtDestObject
  85. );
  86. break;
  87. case ADSTYPE_INTEGER:
  88. hr = AdsTypeToNTTypeCopyInteger(
  89. lpAdsSrcValue,
  90. lpNtDestObject
  91. );
  92. break;
  93. default:
  94. hr = E_FAIL;
  95. break;
  96. }
  97. RRETURN(hr);
  98. }
  99. HRESULT
  100. AdsTypeToNTTypeCopyConstruct(
  101. LPADSVALUE pAdsSrcValues,
  102. DWORD dwNumObjects,
  103. LPNTOBJECT * ppNtDestObjects,
  104. PDWORD pdwNumNdsObjects,
  105. PDWORD pdwNdsSyntaxId
  106. )
  107. {
  108. DWORD i = 0;
  109. LPNTOBJECT pNtDestObjects = NULL;
  110. HRESULT hr = S_OK;
  111. pNtDestObjects = (LPNTOBJECT)AllocADsMem(
  112. dwNumObjects * sizeof(NTOBJECT)
  113. );
  114. if (!pNtDestObjects) {
  115. RRETURN(E_FAIL);
  116. }
  117. for (i = 0; i < dwNumObjects; i++ ) {
  118. hr = AdsTypeToNTTypeCopy(
  119. pAdsSrcValues + i,
  120. pNtDestObjects + i
  121. );
  122. BAIL_ON_FAILURE(hr);
  123. }
  124. *ppNtDestObjects = pNtDestObjects;
  125. *pdwNumNdsObjects = dwNumObjects;
  126. *pdwNdsSyntaxId = pNtDestObjects->NTType;
  127. RRETURN(S_OK);
  128. error:
  129. if (pNtDestObjects) {
  130. NTTypeFreeNTObjects(
  131. pNtDestObjects,
  132. dwNumObjects
  133. );
  134. }
  135. *ppNtDestObjects = NULL;
  136. *pdwNumNdsObjects = 0;
  137. RRETURN(hr);
  138. }
  139.