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.

159 lines
3.9 KiB

  1. /*
  2. * b a s e d i s p . c p p
  3. *
  4. * Purpose:
  5. *
  6. * History
  7. *
  8. * Copyright (C) Microsoft Corp. 1995, 1996.
  9. */
  10. #include <pch.hxx>
  11. #include "privunk.h"
  12. #include "basedisp.h"
  13. #include "dllmain.h"
  14. CBaseDisp::CBaseDisp(IUnknown *pUnkOuter) : CPrivateUnknown(pUnkOuter)
  15. {
  16. m_pTypeInfo = NULL;
  17. m_pUnkInvoke = NULL;
  18. }
  19. CBaseDisp::~CBaseDisp()
  20. {
  21. ReleaseObj(m_pTypeInfo);
  22. }
  23. HRESULT CBaseDisp::PrivateQueryInterface(REFIID riid, LPVOID *lplpObj)
  24. {
  25. if(!lplpObj)
  26. return E_INVALIDARG;
  27. *lplpObj = NULL;
  28. if (IsEqualIID(riid, IID_IDispatch))
  29. *lplpObj = (LPVOID)(IDispatch *)this;
  30. else
  31. if (IsEqualIID(riid, IID_ISupportErrorInfo))
  32. *lplpObj = (LPVOID)(ISupportErrorInfo *)this;
  33. else
  34. return E_NOINTERFACE;
  35. AddRef();
  36. return NOERROR;
  37. }
  38. HRESULT CBaseDisp::InterfaceSupportsErrorInfo(REFIID riid)
  39. {
  40. return S_FALSE;
  41. }
  42. // *** IDispatch ***
  43. HRESULT CBaseDisp::GetTypeInfoCount(UINT *pctinfo)
  44. {
  45. *pctinfo = 1;
  46. return S_OK;
  47. }
  48. HRESULT CBaseDisp::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  49. {
  50. if (!m_pTypeInfo)
  51. return E_FAIL;
  52. if (itinfo)
  53. return DISP_E_BADINDEX;
  54. m_pTypeInfo->AddRef();
  55. *pptinfo = m_pTypeInfo;
  56. return S_OK;
  57. }
  58. HRESULT CBaseDisp::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
  59. {
  60. if (!m_pTypeInfo)
  61. return E_FAIL;
  62. return DispGetIDsOfNames(m_pTypeInfo, rgszNames, cNames, rgdispid);
  63. }
  64. HRESULT CBaseDisp::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr)
  65. {
  66. if (!m_pTypeInfo)
  67. return E_FAIL;
  68. return DispInvoke(m_pUnkInvoke, m_pTypeInfo, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
  69. }
  70. HRESULT CBaseDisp::EnsureTypeLibrary(LPVOID *pUnkInvoke, REFIID riid)
  71. {
  72. TCHAR szDll[MAX_PATH];
  73. LPWSTR pszW;
  74. HRESULT hr = E_FAIL;
  75. // BUGBUG: this is weird. I want to defer the type library loading inside OE
  76. // until the first MOM object is created. Every MOM object deriving from
  77. // CBaseDisp must call CBaseDisp::EnsureTypeLibrary. This check to see if the
  78. // global ITypeLib object has been created (protected with a CS)
  79. AssertSz(pUnkInvoke, "You need to pass me a this pointer to callback on");
  80. EnterCriticalSection(&g_csOETypeLib);
  81. if (!g_pOETypeLib)
  82. {
  83. GetModuleFileName(g_hInst, szDll, ARRAYSIZE(szDll));
  84. pszW = PszToUnicode(GetACP(), szDll);
  85. if (pszW)
  86. {
  87. LoadTypeLib(pszW, &g_pOETypeLib);
  88. MemFree(pszW);
  89. }
  90. }
  91. if (g_pOETypeLib &&
  92. g_pOETypeLib->GetTypeInfoOfGuid(riid, &m_pTypeInfo)==S_OK)
  93. {
  94. m_pUnkInvoke = pUnkInvoke;
  95. hr = S_OK;
  96. }
  97. LeaveCriticalSection(&g_csOETypeLib);
  98. return hr;
  99. }
  100. HRESULT CBaseDisp::ReportError(REFCLSID rclsid, LONG ids)
  101. {
  102. ICreateErrorInfo *pICEI;
  103. IErrorInfo *pErrInfo;
  104. TCHAR rgch[CCHMAX_STRINGRES];
  105. LPWSTR pszW;
  106. if (CreateErrorInfo(&pICEI)==S_OK)
  107. {
  108. pICEI->SetGUID(rclsid);
  109. pICEI->SetSource(L"OE Mail Object Model");
  110. if (LoadString(g_hLocRes, ids, rgch, ARRAYSIZE(rgch)))
  111. {
  112. pszW = PszToUnicode(GetACP(), rgch);
  113. if (pszW)
  114. {
  115. pICEI->SetDescription(pszW);
  116. MemFree(pszW); // CoTaskMemFree
  117. }
  118. }
  119. if (pICEI->QueryInterface(IID_IErrorInfo, (LPVOID *)&pErrInfo)==S_OK)
  120. {
  121. SetErrorInfo(0, pErrInfo);
  122. pErrInfo->Release();
  123. }
  124. pICEI->Release();
  125. }
  126. return S_OK;
  127. }