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.

198 lines
4.4 KiB

  1. //
  2. // funcprv.cpp
  3. //
  4. #include "private.h"
  5. #include "helpers.h"
  6. #include "immxutil.h"
  7. #include "fnprbase.h"
  8. //////////////////////////////////////////////////////////////////////////////
  9. //
  10. // CFunctionProviderBase
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. //+---------------------------------------------------------------------------
  14. //
  15. // IUnknown
  16. //
  17. //----------------------------------------------------------------------------
  18. STDAPI CFunctionProviderBase::QueryInterface(REFIID riid, void **ppvObj)
  19. {
  20. *ppvObj = NULL;
  21. if (IsEqualIID(riid, IID_IUnknown) ||
  22. IsEqualIID(riid, IID_ITfFunctionProvider))
  23. {
  24. *ppvObj = SAFECAST(this, CFunctionProviderBase *);
  25. }
  26. if (*ppvObj)
  27. {
  28. AddRef();
  29. return S_OK;
  30. }
  31. return E_NOINTERFACE;
  32. }
  33. STDAPI_(ULONG) CFunctionProviderBase::AddRef()
  34. {
  35. return InterlockedIncrement(&_cRef);
  36. }
  37. STDAPI_(ULONG) CFunctionProviderBase::Release()
  38. {
  39. long cr;
  40. cr = InterlockedDecrement(&_cRef);
  41. Assert(cr >= 0);
  42. if (cr == 0)
  43. {
  44. delete this;
  45. }
  46. return cr;
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // ctor
  51. //
  52. //----------------------------------------------------------------------------
  53. CFunctionProviderBase::CFunctionProviderBase(TfClientId tid)
  54. {
  55. _tid = tid;
  56. _cRef = 1;
  57. _bstrDesc = NULL;
  58. _guidType = GUID_NULL;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // dtor
  63. //
  64. //----------------------------------------------------------------------------
  65. CFunctionProviderBase::~CFunctionProviderBase()
  66. {
  67. if (! DllShutdownInProgress())
  68. {
  69. SysFreeString(_bstrDesc);
  70. }
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Init
  75. //
  76. //----------------------------------------------------------------------------
  77. BOOL CFunctionProviderBase::Init(REFGUID guidType, WCHAR *pszDesc)
  78. {
  79. _bstrDesc = SysAllocString(pszDesc);
  80. _guidType = guidType;
  81. if (_bstrDesc)
  82. return TRUE;
  83. else
  84. return FALSE;
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // CFunctionProviderBase::Advise
  89. //
  90. //----------------------------------------------------------------------------
  91. HRESULT CFunctionProviderBase::_Advise(ITfThreadMgr *ptim)
  92. {
  93. HRESULT hr;
  94. ITfSourceSingle *source = NULL;
  95. hr = E_FAIL;
  96. if (FAILED(ptim->QueryInterface(IID_ITfSourceSingle, (void **)&source)))
  97. goto Exit;
  98. if (FAILED(source->AdviseSingleSink(_tid, IID_ITfFunctionProvider, this)))
  99. goto Exit;
  100. hr = S_OK;
  101. Exit:
  102. SafeRelease(source);
  103. return hr;
  104. }
  105. //+---------------------------------------------------------------------------
  106. //
  107. // CFunctionProviderBase::Unadvise
  108. //
  109. //----------------------------------------------------------------------------
  110. HRESULT CFunctionProviderBase::_Unadvise(ITfThreadMgr *ptim)
  111. {
  112. HRESULT hr;
  113. ITfSourceSingle *source = NULL;
  114. hr = E_FAIL;
  115. if (FAILED(ptim->QueryInterface(IID_ITfSourceSingle, (void **)&source)))
  116. goto Exit;
  117. if (FAILED(source->UnadviseSingleSink(_tid, IID_ITfFunctionProvider)))
  118. goto Exit;
  119. hr = S_OK;
  120. Exit:
  121. SafeRelease(source);
  122. return hr;
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // GetType
  127. //
  128. //----------------------------------------------------------------------------
  129. STDAPI CFunctionProviderBase::GetType(GUID *pguid)
  130. {
  131. *pguid = _guidType;
  132. return S_OK;
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // GetDescription
  137. //
  138. //----------------------------------------------------------------------------
  139. STDAPI CFunctionProviderBase::GetDescription(BSTR *pbstrDesc)
  140. {
  141. *pbstrDesc = SysAllocString(_bstrDesc);
  142. if (*pbstrDesc)
  143. return S_OK;
  144. else
  145. return E_OUTOFMEMORY;
  146. }
  147. //+---------------------------------------------------------------------------
  148. //
  149. // GetFunction
  150. //
  151. //----------------------------------------------------------------------------
  152. STDAPI CFunctionProviderBase::GetFunction(REFGUID rguid, REFIID riid, IUnknown **ppunk)
  153. {
  154. *ppunk = NULL;
  155. return S_OK;
  156. }