void CLangBarItemButton::CleanUp() { if (_pTooltipText) { delete [] _pTooltipText; _pTooltipText = nullptr; } ITfThreadMgr* pThreadMgr = nullptr; HRESULT hr = CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&pThreadMgr); if (SUCCEEDED(hr)) { _UnregisterCompartment(pThreadMgr); _RemoveItem(pThreadMgr); pThreadMgr->Release(); pThreadMgr = nullptr; } if (_pCompartment) { delete _pCompartment; _pCompartment = nullptr; } if (_pCompartmentEventSink) { delete _pCompartmentEventSink; _pCompartmentEventSink = nullptr; } }
// static HRESULT CDIME::CompartmentCallback(_In_ void *pv, REFGUID guidCompartment) { debugPrint(L"CDIME::CompartmentCallback()\n"); CDIME* fakeThis = (CDIME*)pv; if (nullptr == fakeThis) { return E_INVALIDARG; } ITfThreadMgr* pThreadMgr = nullptr; HRESULT hr = CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&pThreadMgr); if (FAILED(hr) || pThreadMgr == nullptr) { return E_FAIL; } if (IsEqualGUID(guidCompartment, Global::DIMEGuidCompartmentDoubleSingleByte) ) { fakeThis->PrivateCompartmentsUpdated(pThreadMgr); } else if (IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION) || IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_SENTENCE)) { fakeThis->ConversionModeCompartmentUpdated(pThreadMgr); } else if (IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE)|| IsEqualGUID(guidCompartment, Global::DIMEGuidCompartmentIMEMode)) { fakeThis->KeyboardOpenCompartmentUpdated(pThreadMgr, guidCompartment); } pThreadMgr->Release(); pThreadMgr = nullptr; return S_OK; }
HRESULT CCompartmentMonitor::Initialize( const GUID *pguidCompartment, PCOMPARTMENTMONITORPROC pCallback, LPARAM lParam) { if(!IsEqualGUID(m_guidCompartment, GUID_NULL)) { //Initialize() has already been called return E_UNEXPECTED; } m_guidCompartment = *pguidCompartment; m_pCallback = pCallback; m_lParam = lParam; HRESULT hr; ITfThreadMgr *pThreadMgr; //create a thread manager object hr = CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&pThreadMgr); if(SUCCEEDED(hr)) { ITfCompartmentMgr *pCompMgr; //get the global compartment manager hr = pThreadMgr->GetGlobalCompartment(&pCompMgr); if(SUCCEEDED(hr)) { //get the Speech UI compartment hr = pCompMgr->GetCompartment(m_guidCompartment, &m_pCompartment); if(SUCCEEDED(hr)) { ITfSource *pSource; //install the advise sink hr = m_pCompartment->QueryInterface(IID_ITfSource, (LPVOID*)&pSource); if(SUCCEEDED(hr)) { hr = pSource->AdviseSink(IID_ITfCompartmentEventSink, (ITfCompartmentEventSink*)this, &m_dwCookie); } //if something went wrong, release the member interface if(FAILED(hr)) { m_pCompartment->Release(); m_pCompartment = NULL; } } //release the compartment manager pCompMgr->Release(); } //release the thread manager pThreadMgr->Release(); } return hr; }