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.

146 lines
3.1 KiB

  1. //
  2. // pkes.cpp
  3. //
  4. #include "private.h"
  5. #include "pkes.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CPreservedKeyNotifySink
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CPreservedKeyNotifySink::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_ITfPreservedKeyNotifySink))
  22. {
  23. *ppvObj = SAFECAST(this, CPreservedKeyNotifySink *);
  24. }
  25. if (*ppvObj)
  26. {
  27. AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDAPI_(ULONG) CPreservedKeyNotifySink::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CPreservedKeyNotifySink::Release()
  37. {
  38. long cr;
  39. cr = --_cRef;
  40. Assert(cr >= 0);
  41. if (cr == 0)
  42. {
  43. delete this;
  44. }
  45. return cr;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // ctor
  50. //
  51. //----------------------------------------------------------------------------
  52. CPreservedKeyNotifySink::CPreservedKeyNotifySink(PKESCALLBACK pfnCallback, void *pv)
  53. {
  54. Dbg_MemSetThisName(TEXT("CPreservedKeyNotifySink"));
  55. _cRef = 1;
  56. _dwCookie = (DWORD)PKES_INVALID_COOKIE;
  57. _pfnCallback = pfnCallback;
  58. _pv = pv;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // OnUpdated
  63. //
  64. //----------------------------------------------------------------------------
  65. STDAPI CPreservedKeyNotifySink::OnUpdated(const TF_PRESERVEDKEY *pprekey)
  66. {
  67. return _pfnCallback(pprekey, _pv);
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // CPreservedKeyNotifySink::Advise
  72. //
  73. //----------------------------------------------------------------------------
  74. HRESULT CPreservedKeyNotifySink::_Advise(ITfThreadMgr *ptim)
  75. {
  76. HRESULT hr;
  77. ITfSource *source = NULL;
  78. _ptim = NULL;
  79. hr = E_FAIL;
  80. if (FAILED(ptim->QueryInterface(IID_ITfSource, (void **)&source)))
  81. goto Exit;
  82. if (FAILED(source->AdviseSink(IID_ITfPreservedKeyNotifySink, this, &_dwCookie)))
  83. goto Exit;
  84. _ptim = ptim;
  85. _ptim->AddRef();
  86. hr = S_OK;
  87. Exit:
  88. SafeRelease(source);
  89. return hr;
  90. }
  91. //+---------------------------------------------------------------------------
  92. //
  93. // CPreservedKeyNotifySink::Unadvise
  94. //
  95. //----------------------------------------------------------------------------
  96. HRESULT CPreservedKeyNotifySink::_Unadvise()
  97. {
  98. HRESULT hr;
  99. ITfSource *source = NULL;
  100. hr = E_FAIL;
  101. if (_ptim == NULL)
  102. goto Exit;
  103. if (FAILED(_ptim->QueryInterface(IID_ITfSource, (void **)&source)))
  104. goto Exit;
  105. if (FAILED(source->UnadviseSink(_dwCookie)))
  106. goto Exit;
  107. hr = S_OK;
  108. Exit:
  109. SafeRelease(source);
  110. SafeReleaseClear(_ptim);
  111. return hr;
  112. }