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.

131 lines
2.3 KiB

  1. HRESULT
  2. BuildVariantArrayofStrings(
  3. LPWSTR *lppPathNames,
  4. DWORD dwPathNames,
  5. VARIANT ** ppVar
  6. )
  7. {
  8. VARIANT v;
  9. VARIANT * pVar = NULL;
  10. SAFEARRAYBOUND sabNewArray;
  11. DWORD i;
  12. SAFEARRAY *psa = NULL;
  13. HRESULT hr;
  14. *ppVar = NULL;
  15. sabNewArray.cElements = dwPathNames;
  16. sabNewArray.lLbound = 0;
  17. psa = SafeArrayCreate(VT_VARIANT, 1, &sabNewArray);
  18. if (!psa) {
  19. goto Fail;
  20. }
  21. for (i = 0; i < dwPathNames; i++) {
  22. VariantInit(&v);
  23. V_VT(&v) = VT_BSTR;
  24. V_BSTR(&v) = *(lppPathNames + i);
  25. hr = SafeArrayPutElement(psa,
  26. (long FAR *)&i,
  27. &v
  28. );
  29. }
  30. pVar = (VARIANT *)AllocSplMem(sizeof(VARIANT));
  31. if (!pVar) {
  32. goto Fail;
  33. }
  34. V_VT(pVar) = VT_VARIANT | VT_ARRAY;
  35. V_ARRAY(pVar) = psa;
  36. return(ResultFromScode(S_OK));
  37. Fail:
  38. if (pVar) {
  39. FreeSplMem(pVar);
  40. }
  41. if (psa) {
  42. SafeArrayDestroy(psa);
  43. }
  44. *ppVar = pVar;
  45. return(E_FAIL);
  46. }
  47. HRESULT
  48. BuildVariantArrayofIntegers(
  49. LPDWORD lpdwObjectTypes,
  50. DWORD dwObjectTypes,
  51. VARIANT ** ppVar
  52. )
  53. {
  54. VARIANT v;
  55. VARIANT * pVar = NULL;
  56. SAFEARRAYBOUND sabNewArray;
  57. DWORD i;
  58. SAFEARRAY *psa = NULL;
  59. HRESULT hr;
  60. *ppVar = NULL;
  61. sabNewArray.cElements = dwObjectTypes;
  62. sabNewArray.lLbound = 0;
  63. psa = SafeArrayCreate(VT_VARIANT, 1, &sabNewArray);
  64. if (!psa) {
  65. goto Fail;
  66. }
  67. for (i = 0; i < dwObjectTypes; i++) {
  68. VariantInit(&v);
  69. V_VT(&v) = VT_I4;
  70. V_I4(&v) = *(lpdwObjectTypes + i);
  71. hr = SafeArrayPutElement(psa,
  72. (long FAR *)&i,
  73. &v
  74. );
  75. }
  76. pVar = (VARIANT *)AllocSplMem(sizeof(VARIANT));
  77. if (!pVar) {
  78. goto Fail;
  79. }
  80. V_VT(pVar) = VT_VARIANT | VT_ARRAY;
  81. V_ARRAY(pVar) = psa;
  82. *ppVar = pVar;
  83. return(ResultFromScode(S_OK));
  84. Fail:
  85. if (pVar) {
  86. FreeSplMem(pVar);
  87. }
  88. if (psa) {
  89. SafeArrayDestroy(psa);
  90. }
  91. return(E_FAIL);
  92. }