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.

105 lines
1.9 KiB

  1. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  2. #include "stdafx.h"
  3. #include "dispexa.h"
  4. HRESULT
  5. CDispExArray::HrGetLength(ULONG* pLength)
  6. {
  7. USES_CONVERSION;
  8. HRESULT hr = S_OK;
  9. VARIANT var;
  10. BSTR bstrName = NULL;
  11. WCHAR* oleStr = NULL;
  12. DISPID dispid;
  13. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  14. if (!m_piDispEx)
  15. return E_UNEXPECTED;
  16. _ASSERTE(pLength);
  17. if (NULL == pLength)
  18. return E_INVALIDARG;
  19. VariantInit(&var);
  20. oleStr = T2OLE(_T("length"));
  21. bstrName = ::SysAllocString(oleStr);
  22. if (FAILED(hr = m_piDispEx->GetDispID(bstrName, fdexNameCaseSensitive, &dispid)))
  23. goto cleanup;
  24. ::SysFreeString(bstrName);
  25. bstrName = NULL; // BUG 597865
  26. hr = m_piDispEx->InvokeEx(dispid, LOCALE_USER_DEFAULT,
  27. DISPATCH_PROPERTYGET, &dispparamsNoArgs,
  28. &var, NULL, NULL);
  29. if (FAILED(hr))
  30. goto cleanup;
  31. if (V_VT(&var) != VT_I4)
  32. goto cleanup;
  33. *pLength = V_I4(&var);
  34. cleanup:
  35. if (FAILED(hr))
  36. {
  37. if (bstrName)
  38. ::SysFreeString(bstrName);
  39. }
  40. return hr;
  41. }
  42. HRESULT
  43. CDispExArray::HrGetElement(ULONG index, LPVARIANT pVar)
  44. {
  45. USES_CONVERSION;
  46. HRESULT hr = S_OK;
  47. VARIANT var;
  48. BSTR bstrName = NULL;
  49. WCHAR* oleStr = NULL;
  50. DISPID dispid = 0;
  51. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  52. char buffer[32];
  53. if (!m_piDispEx)
  54. return E_UNEXPECTED;
  55. _ASSERTE(pVar);
  56. if (NULL == pVar)
  57. return E_INVALIDARG;
  58. VariantInit(&var);
  59. oleStr = A2OLE(_itoa(index, buffer, 10));
  60. bstrName = ::SysAllocString(oleStr);
  61. if (FAILED(hr = m_piDispEx->GetDispID(bstrName, fdexNameCaseSensitive, &dispid)))
  62. goto cleanup;
  63. SysFreeString(bstrName);
  64. bstrName = NULL; // BUG 597865
  65. hr = m_piDispEx->InvokeEx(dispid, LOCALE_USER_DEFAULT,
  66. DISPATCH_PROPERTYGET, &dispparamsNoArgs,
  67. pVar, NULL, NULL);
  68. if (FAILED(hr))
  69. goto cleanup;
  70. cleanup:
  71. if (FAILED(hr))
  72. {
  73. if (bstrName)
  74. ::SysFreeString(bstrName);
  75. }
  76. return hr;
  77. }