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.

96 lines
2.8 KiB

  1. //
  2. // MODULE: VariantBuilder.cpp
  3. //
  4. // PURPOSE: implementation of the CVariantBuilder class. Allows us to construct
  5. // a pair of arrays for the name-value pairs to be passed to RunQuery. This lets
  6. // JScript sanely use a system that was mostly designed for VB Script.
  7. //
  8. // PROJECT: Troubleshooter 99
  9. //
  10. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  11. //
  12. // AUTHOR: Joe Mabel
  13. //
  14. // ORIGINAL DATE: 02.01.99
  15. //
  16. // NOTES:
  17. // Implementation of CTSHOOTCtrl
  18. //
  19. // Version Date By Comments
  20. //--------------------------------------------------------------------
  21. // V3.1 02.01.99 JM
  22. #include "stdafx.h"
  23. #include "VariantBuilder.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CVariantBuilder::CVariantBuilder()
  33. {
  34. VariantInit(&m_varCommands);
  35. VariantInit(&m_varValues);
  36. VariantInit(&m_varCommandsWrap);
  37. VariantInit(&m_varValuesWrap);
  38. V_VT(&m_varCommands) = VT_ARRAY | VT_BYREF | VT_VARIANT;
  39. V_VT(&m_varValues) = VT_ARRAY | VT_BYREF | VT_VARIANT;
  40. V_ARRAYREF(&m_varCommands) = &m_psafearrayCmds;
  41. V_ARRAYREF(&m_varValues) = &m_psafearrayVals;
  42. V_VT(&m_varCommandsWrap) = VT_BYREF | VT_VARIANT;
  43. V_VT(&m_varValuesWrap) = VT_BYREF | VT_VARIANT;
  44. V_VARIANTREF(&m_varCommandsWrap) = &m_varCommands;
  45. V_VARIANTREF(&m_varValuesWrap) = &m_varValues;
  46. SAFEARRAYBOUND sabCmd;
  47. sabCmd.cElements = k_cMaxElements;
  48. sabCmd.lLbound = 0;
  49. SAFEARRAYBOUND sabVal = sabCmd;
  50. // create two vectors of VARIANTs to wrap BSTRs
  51. m_psafearrayCmds = SafeArrayCreate( VT_VARIANT, 1, &sabCmd);
  52. m_psafearrayVals = SafeArrayCreate( VT_VARIANT, 1, &sabVal);
  53. m_cElements = 0;
  54. }
  55. CVariantBuilder::~CVariantBuilder()
  56. {
  57. SafeArrayDestroy(m_psafearrayCmds);
  58. SafeArrayDestroy(m_psafearrayVals);
  59. VariantClear(&m_varCommands);
  60. VariantClear(&m_varValues);
  61. VariantClear(&m_varCommandsWrap);
  62. VariantClear(&m_varValuesWrap);
  63. }
  64. // effectively, add a name-value pair to the arrays.
  65. // If the array is full (which should never happen in the real world) silently fails.
  66. void CVariantBuilder::SetPair(BSTR bstrCmd, BSTR bstrVal)
  67. {
  68. if (m_cElements < k_cMaxElements)
  69. {
  70. VariantInit(&m_pvarCmd[m_cElements]);
  71. VariantInit(&m_pvarVal[m_cElements]);
  72. V_VT(&m_pvarCmd[m_cElements]) = VT_BSTR;
  73. V_VT(&m_pvarVal[m_cElements]) = VT_BSTR;
  74. m_pvarCmd[m_cElements].bstrVal=bstrCmd;
  75. m_pvarVal[m_cElements].bstrVal=bstrVal;
  76. SafeArrayPutElement(m_psafearrayCmds, &m_cElements, &m_pvarCmd[m_cElements]);
  77. SafeArrayPutElement(m_psafearrayVals, &m_cElements, &m_pvarVal[m_cElements]);
  78. ++m_cElements;
  79. }
  80. }