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.

402 lines
11 KiB

  1. //****************************************************************************
  2. //
  3. // BLObEvnt.cpp
  4. // Messenger integration to OE
  5. // Created 04/20/98 by YST
  6. //
  7. // Copyright (c) Microsoft Corporation 1997-1998
  8. //
  9. #include "pch.hxx"
  10. #include "bactrl.h"
  11. #include "MDispid.h"
  12. #include "BLObEvnt.h"
  13. #include "demand.h"
  14. #include "bllist.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[]=__FILE__;
  18. #define new DEBUG_NEW
  19. #endif
  20. #define ASSERT _ASSERTE
  21. #define STR_MAX 256
  22. //****************************************************************************
  23. //
  24. // CLASS CMsgrObjectEvents
  25. //
  26. //****************************************************************************
  27. //****************************************************************************
  28. //
  29. // Construction/Destruction
  30. //
  31. //****************************************************************************
  32. CMsgrObjectEvents::CMsgrObjectEvents()
  33. {
  34. // m_pBlAbCtrl = NULL;
  35. // lLocalState = MSTATEOE_OFFLINE;
  36. }
  37. CMsgrObjectEvents::~CMsgrObjectEvents()
  38. {
  39. }
  40. //****************************************************************************
  41. //
  42. // Methods from IUnknown
  43. //
  44. //****************************************************************************
  45. //****************************************************************************
  46. //
  47. // STDMETHODIMP_(ULONG) CMsgrObjectEvents::AddRef()
  48. //
  49. // Purpose : increment the object's reference count,
  50. // Entry : None
  51. // Exit : current count
  52. //
  53. //****************************************************************************
  54. STDMETHODIMP_ (ULONG) CMsgrObjectEvents::AddRef()
  55. {
  56. return RefCount::AddRef();
  57. }
  58. //****************************************************************************
  59. //
  60. // STDMETHODIMP_(ULONG) CMsgrObjectEvents::Release()
  61. //
  62. // Purpose : decrement the object's reference count
  63. // Entry : None
  64. // Exit : returns new count
  65. //
  66. //****************************************************************************
  67. STDMETHODIMP_ (ULONG) CMsgrObjectEvents::Release()
  68. {
  69. return RefCount::Release();
  70. }
  71. //****************************************************************************
  72. //
  73. // STDMETHODIMP CMsgrObjectEvents::QueryInterface(REFIID iid, LPVOID *ppv)
  74. //
  75. // returns a pointer to the requested interface on the same object
  76. // Purpose: To retrieve a pointer to requested interface
  77. // Entry : iid -- GUID of requested interface
  78. // Exit : ppv -- pointer to requested interface (if one exists)
  79. // return value : HRESULT
  80. //
  81. //****************************************************************************
  82. STDMETHODIMP CMsgrObjectEvents::QueryInterface (REFIID riid, LPVOID *ppv)
  83. {
  84. *ppv = NULL;
  85. HRESULT hr = E_NOINTERFACE;
  86. if (riid == IID_IUnknown)
  87. *ppv = (LPVOID) this;
  88. else if (riid == DIID_DMsgrOEEvents)
  89. *ppv = (LPVOID) this;
  90. else if (riid == IID_IDispatch)
  91. *ppv = (LPVOID) this;
  92. if (*ppv)
  93. {
  94. ((LPUNKNOWN)*ppv)->AddRef();
  95. hr = S_OK;
  96. }
  97. return hr;
  98. }
  99. //****************************************************************************
  100. //
  101. // IDispatch implementation
  102. //
  103. //****************************************************************************
  104. //****************************************************************************
  105. //
  106. // STDMETHODIMP CMsgrObjectEvents::GetTypeInfoCount(UINT* pcTypeInfo)
  107. //
  108. // Set pcTypeInfo to 0 because we do not support type library
  109. //
  110. //****************************************************************************
  111. STDMETHODIMP CMsgrObjectEvents::GetTypeInfoCount(UINT* pcTypeInfo)
  112. {
  113. // g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfoCount call succeeded"));
  114. *pcTypeInfo = 0 ;
  115. return NOERROR ;
  116. }
  117. //****************************************************************************
  118. //
  119. // STDMETHODIMP CMsgrObjectEvents::GetTypeInfo(
  120. //
  121. // Returns E_NOTIMPL because we do not support type library
  122. //
  123. //****************************************************************************
  124. STDMETHODIMP CMsgrObjectEvents::GetTypeInfo(
  125. UINT iTypeInfo,
  126. LCID, // This object does not support localization.
  127. ITypeInfo** ppITypeInfo)
  128. {
  129. *ppITypeInfo = NULL ;
  130. if(iTypeInfo != 0)
  131. {
  132. // g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfo call failed -- bad iTypeInfo index"));
  133. return DISP_E_BADINDEX ;
  134. }
  135. else
  136. {
  137. //g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfo call succeeded"));
  138. return E_NOTIMPL;
  139. }
  140. }
  141. //****************************************************************************
  142. //
  143. // STDMETHODIMP CMsgrObjectEvents::GetIDsOfNames(
  144. // const IID& iid,
  145. // OLECHAR** arrayNames,
  146. // UINT countNames,
  147. // LCID, // Localization is not supported.
  148. // DISPID* arrayDispIDs)
  149. //
  150. // Returns E_NOTIMPL because we do not support type library
  151. //
  152. //****************************************************************************
  153. STDMETHODIMP CMsgrObjectEvents::GetIDsOfNames(
  154. const IID& iid,
  155. OLECHAR** arrayNames,
  156. UINT countNames,
  157. LCID, // Localization is not supported.
  158. DISPID* arrayDispIDs)
  159. {
  160. HRESULT hr;
  161. if (iid != IID_NULL)
  162. {
  163. // g_AddToLog(LOG_LEVEL_COM, _T("GetIDsOfNames call failed -- bad IID"));
  164. return DISP_E_UNKNOWNINTERFACE ;
  165. }
  166. // g_AddToLog(LOG_LEVEL_COM, _T("GetIDsOfNames call succeeded"));
  167. hr = E_NOTIMPL;
  168. return hr ;
  169. }
  170. // Set BLAB control for CMsgrObjectEvents
  171. STDMETHODIMP CMsgrObjectEvents::SetListOfBuddies(CMsgrList *pList)
  172. {
  173. m_pMsgrList = pList;
  174. return S_OK;
  175. }
  176. // Set BLAB control for CMsgrObjectEvents
  177. STDMETHODIMP CMsgrObjectEvents::DelListOfBuddies()
  178. {
  179. m_pMsgrList = NULL;
  180. return S_OK;
  181. }
  182. //****************************************************************************
  183. //
  184. // STDMETHODIMP CMsgrObjectEvents::Invoke(
  185. // DISPID dispidMember,
  186. // const IID& iid,
  187. // LCID, // Localization is not supported.
  188. // WORD wFlags,
  189. // DISPPARAMS* pDispParams,
  190. // VARIANT* pvarResult,
  191. // EXCEPINFO* pExcepInfo,
  192. // UINT* pArgErr)
  193. //
  194. // Returns E_NOTIMPL because we do not support type library
  195. //
  196. //****************************************************************************
  197. STDMETHODIMP CMsgrObjectEvents::Invoke(
  198. DISPID dispidMember,
  199. const IID& iid,
  200. LCID, // Localization is not supported.
  201. WORD wFlags,
  202. DISPPARAMS* pDispParams,
  203. VARIANT* pvarResult,
  204. EXCEPINFO* pExcepInfo,
  205. UINT* pArgErr)
  206. {
  207. // g_AddToLog(LOG_LEVEL_FUNCTIONS, _T("CMsgrObjectEvents::Invoke entered"));
  208. // g_AddToLog(LOG_LEVEL_NOTIFICATIONS, _T("Dispid passed : %s"), g_GetStringFromDISPID(dispidMember));
  209. HRESULT hr;
  210. HRESULT hrRet;
  211. if (iid != IID_NULL)
  212. {
  213. // g_AddToLog(LOG_LEVEL_COM, _T("Invoke call failed -- bad IID"));
  214. return DISP_E_UNKNOWNINTERFACE ;
  215. }
  216. ::SetErrorInfo(0, NULL) ;
  217. CComPtr<IMsgrUserOE> spUser;
  218. CComPtr<IMsgrUsersOE> spBuddies;
  219. switch (dispidMember)
  220. {
  221. case DISPID_ONLOGONRESULT:
  222. //we should only have one parameter, the result, and that it is a long
  223. ASSERT(pDispParams->cArgs == 1);
  224. ASSERT(pDispParams->rgvarg->vt == VT_I4);
  225. // g_AddToLog(LOG_LEVEL_NOTIFICATIONS, _T("Result passed : %s"), g_GetStringFromLogonResult(pDispParams->rgvarg->lVal));
  226. if(m_pMsgrList)
  227. hrRet = m_pMsgrList->EventLogonResult(pDispParams->rgvarg->lVal);
  228. break;
  229. case DISPID_ONUSERFRIENDLYNAMECHANGERESULT :
  230. _ASSERTE(pDispParams->cArgs == 3);
  231. _ASSERTE(pDispParams->rgvarg[2].vt == VT_I4);
  232. _ASSERTE(pDispParams->rgvarg[1].vt == VT_DISPATCH);
  233. //if(lLocalState >= MSTATEOE_LOCAL_FINDING_SERVER)
  234. // break;
  235. hr = pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IMsgrUserOE, (LPVOID *)&spUser);
  236. if (SUCCEEDED(hr))
  237. {
  238. if(m_pMsgrList)
  239. hrRet = m_pMsgrList->EventUserNameChanged(spUser);
  240. }
  241. break;
  242. case DISPID_ONLOGOFF:
  243. if(m_pMsgrList)
  244. hrRet = m_pMsgrList->EventLogoff();
  245. break;
  246. case DISPID_ONAPPSHUTDOWN:
  247. if(m_pMsgrList)
  248. hrRet = m_pMsgrList->EventAppShutdown();
  249. break;
  250. case DISPID_ONLISTADDRESULT:
  251. // we should have two parameter, HRESULT, and the pMsgrUser
  252. //
  253. // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  254. // The parameters are inversed. This means that the las parameter in the
  255. // prototype of the function is the first one in the array received, and so on
  256. _ASSERTE(pDispParams->cArgs == 2);
  257. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  258. _ASSERTE(pDispParams->rgvarg[0].vt == VT_DISPATCH);
  259. hrRet = V_I4(&pDispParams->rgvarg[1]);
  260. hr = pDispParams->rgvarg[0].pdispVal->QueryInterface(IID_IMsgrUserOE, (LPVOID *)&spUser);
  261. if (SUCCEEDED(hr))
  262. {
  263. if( SUCCEEDED(hrRet) )
  264. {
  265. // g_AddToLog(LOG_LEVEL_COM, _T("User was added sucessfully."));
  266. if(m_pMsgrList)
  267. hrRet = m_pMsgrList->EventUserAdded(spUser);
  268. }
  269. }
  270. else
  271. {
  272. // g_AddToLog(LOG_LEVEL_COM, _T("QueryInterface for IID_IMsgrUserOE failed"));
  273. }
  274. break;
  275. case DISPID_ONLISTREMOVERESULT:
  276. // we should have two parameter, HRESULT, and the pMsgrUser
  277. //
  278. _ASSERTE(pDispParams->cArgs == 2);
  279. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  280. _ASSERTE(pDispParams->rgvarg[0].vt == VT_DISPATCH);
  281. hrRet = V_I4(&pDispParams->rgvarg[1]);
  282. hr = pDispParams->rgvarg[0].pdispVal->QueryInterface(IID_IMsgrUserOE, (LPVOID *)&spUser);
  283. if (SUCCEEDED(hr))
  284. {
  285. if( SUCCEEDED(hrRet) )
  286. {
  287. // g_AddToLog(LOG_LEVEL_COM, _T("User was removed sucessfully."));
  288. if(m_pMsgrList)
  289. hrRet = m_pMsgrList->EventUserRemoved(spUser);
  290. }
  291. else
  292. {
  293. // g_AddToLog(LOG_LEVEL_COM, _T("User was not removed due to error %s."), g_GetErrorString(hrRet));
  294. }
  295. }
  296. else
  297. {
  298. // g_AddToLog(LOG_LEVEL_COM, _T("QueryInterface for IID_IMsgrUserOE failed"));
  299. }
  300. break;
  301. case DISPID_ONUSERSTATECHANGED:
  302. //we should only have two parameters, the previousState and the pMsgrUser
  303. ASSERT(pDispParams->cArgs == 2);
  304. ASSERT(pDispParams->rgvarg[1].vt == VT_DISPATCH);
  305. ASSERT(pDispParams->rgvarg[0].vt == VT_I4);
  306. // if(lLocalState >= MSTATEOE_LOCAL_FINDING_SERVER)
  307. // break;
  308. hr = pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IMsgrUserOE, (LPVOID *)&spUser);
  309. if (SUCCEEDED(hr))
  310. {
  311. if(m_pMsgrList)
  312. hrRet = m_pMsgrList->EventUserStateChanged(spUser);
  313. }
  314. break;
  315. case DISPID_ONLOCALSTATECHANGERESULT:
  316. //we should only have two parameters, hr and the LocalState
  317. #if 0
  318. _ASSERTE(pDispParams->cArgs >== 2);
  319. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  320. _ASSERTE(pDispParams->rgvarg[0].vt == VT_I4);
  321. #endif // 0
  322. // lLocalState = pDispParams->rgvarg[0].lVal;
  323. // hrRet = pBlCLientDlg->EventLocalStateChanged(pDispParams->rgvarg[0].lVal);
  324. break;
  325. }
  326. return NOERROR;
  327. }