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.

128 lines
4.1 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Standard included stuff for the AudioVBScript engine.
  4. //
  5. #include "stdinc.h"
  6. #include "enginc.h"
  7. const char *g_rgszBuiltInConstants[] = { "true", "false", "nothing" };
  8. const int g_cBuiltInConstants = ARRAY_SIZE(g_rgszBuiltInConstants);
  9. DISPID
  10. GetDispID(IDispatch *pIDispatch, const char *pszBase)
  11. {
  12. SmartRef::WString wstrBase = pszBase;
  13. if (!wstrBase)
  14. return DISPID_UNKNOWN;
  15. DISPID dispid = DISPID_UNKNOWN;
  16. const WCHAR *wszBase = wstrBase;
  17. pIDispatch->GetIDsOfNames(IID_NULL, const_cast<WCHAR**>(&wszBase), 1, lcidUSEnglish, &dispid);
  18. return dispid;
  19. }
  20. // See oleaut.h for more info about why this is necessary.
  21. HRESULT
  22. InvokeAttemptingNotToUseOleAut(
  23. IDispatch *pDisp,
  24. DISPID dispIdMember,
  25. WORD wFlags,
  26. DISPPARAMS *pDispParams,
  27. VARIANT *pVarResult,
  28. EXCEPINFO *pExcepInfo,
  29. UINT *puArgErr)
  30. {
  31. if (g_fUseOleAut)
  32. {
  33. // Engine is set to always use oleaut32.dll.
  34. return pDisp->Invoke(dispIdMember, IID_NULL, lcidUSEnglish, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  35. }
  36. // Try not to use oleaut32.dll.
  37. HRESULT hr = pDisp->Invoke(dispIdMember, g_guidInvokeWithoutOleaut, lcidUSEnglish, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  38. if (hr != DISP_E_UNKNOWNINTERFACE)
  39. return hr;
  40. // It didn't like being called that way. Must be some other scripting language or non-DMusic dispatch interface.
  41. // Use regular oleaut32.dll calling convention.
  42. if (pVarResult)
  43. {
  44. // We need to convert the return into our own kind of variant.
  45. VARIANT var;
  46. DMS_VariantInit(true, &var);
  47. hr = pDisp->Invoke(dispIdMember, IID_NULL, lcidUSEnglish, wFlags, pDispParams, &var, pExcepInfo, puArgErr);
  48. DMS_VariantCopy(false, pVarResult, &var);
  49. DMS_VariantClear(true, &var);
  50. }
  51. else
  52. {
  53. // There's no result so no conversion is necessary.
  54. hr = pDisp->Invoke(dispIdMember, IID_NULL, lcidUSEnglish, wFlags, pDispParams, NULL, pExcepInfo, puArgErr);
  55. }
  56. // If an exception occurred, we need to convert the error strings into our own kind of BSTR.
  57. if (hr == DISP_E_EXCEPTION)
  58. ConvertOleAutExceptionBSTRs(true, false, pExcepInfo);
  59. return hr;
  60. }
  61. HRESULT
  62. SetDispatchProperty(IDispatch *pDisp, DISPID dispid, bool fSetRef, const VARIANT &v, EXCEPINFO *pExcepInfo)
  63. {
  64. DISPID dispidPropPut = DISPID_PROPERTYPUT;
  65. DISPPARAMS dispparams;
  66. dispparams.rgvarg = const_cast<VARIANT*>(&v);
  67. dispparams.rgdispidNamedArgs = &dispidPropPut;
  68. dispparams.cArgs = 1;
  69. dispparams.cNamedArgs = 1;
  70. HRESULT hr = InvokeAttemptingNotToUseOleAut(
  71. pDisp,
  72. dispid,
  73. fSetRef ? DISPATCH_PROPERTYPUTREF : DISPATCH_PROPERTYPUT,
  74. &dispparams,
  75. NULL,
  76. pExcepInfo,
  77. NULL);
  78. return hr;
  79. }
  80. HRESULT
  81. GetDispatchProperty(IDispatch *pDisp, DISPID dispid, VARIANT &v, EXCEPINFO *pExcepInfo)
  82. {
  83. DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  84. HRESULT hr = InvokeAttemptingNotToUseOleAut(
  85. pDisp,
  86. dispid,
  87. DISPATCH_PROPERTYGET | DISPATCH_METHOD,
  88. // DISPATCH_METHOD is also set because in VB syntax a function with no parameters
  89. // can be accessed like a property. Example "x = GetMasterGrooveLevel" is a
  90. // shortcut for "x = GetMasterGrooveLevel()".
  91. &dispparamsNoArgs,
  92. &v,
  93. pExcepInfo,
  94. NULL);
  95. return hr;
  96. }
  97. // If needed, converts the BSTRs in an EXCEPINFO structure between formats using or not using OleAut.
  98. void ConvertOleAutExceptionBSTRs(bool fCurrentlyUsesOleAut, bool fResultUsesOleAut, EXCEPINFO *pExcepInfo)
  99. {
  100. if (pExcepInfo && fCurrentlyUsesOleAut != fResultUsesOleAut)
  101. {
  102. BSTR bstrSource = pExcepInfo->bstrSource;
  103. BSTR bstrDescription = pExcepInfo->bstrDescription;
  104. BSTR bstrHelpFile = pExcepInfo->bstrHelpFile;
  105. pExcepInfo->bstrSource = DMS_SysAllocString(fResultUsesOleAut, bstrSource);
  106. pExcepInfo->bstrDescription = DMS_SysAllocString(fResultUsesOleAut, bstrDescription);
  107. pExcepInfo->bstrHelpFile = DMS_SysAllocString(fResultUsesOleAut, bstrHelpFile);
  108. DMS_SysFreeString(fCurrentlyUsesOleAut, bstrSource);
  109. DMS_SysFreeString(fCurrentlyUsesOleAut, bstrDescription);
  110. DMS_SysFreeString(fCurrentlyUsesOleAut, bstrHelpFile);
  111. }
  112. }