HRESULT CDIME::_InsertAtSelection(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString, _Outptr_ ITfRange **ppCompRange) { debugPrint(L"CDIME::_InsertAtSelection()"); ITfRange* rangeInsert = nullptr; ITfInsertAtSelection* pias = nullptr; HRESULT hr = S_OK; if (ppCompRange == nullptr || pContext == nullptr || pstrAddString == nullptr) { debugPrint(L"CDIME::_InsertAtSelection() failed with null ppCompRange or pContext or pstrAddstring"); hr = E_INVALIDARG; goto Exit; } *ppCompRange = nullptr; hr = pContext->QueryInterface(IID_ITfInsertAtSelection, (void **)&pias); if (FAILED(hr) || pias == nullptr) { debugPrint(L"CDIME::_InsertAtSelection() failed with null pias or QueryInterface failed"); goto Exit; } hr = pias->InsertTextAtSelection(ec, TF_IAS_QUERYONLY, pstrAddString->Get(), (LONG)pstrAddString->GetLength(), &rangeInsert); if ( FAILED(hr) || rangeInsert == nullptr) { debugPrint(L"CDIME::_InsertAtSelection() InsertTextAtSelection failed"); rangeInsert = nullptr; pias->Release(); goto Exit; } WCHAR rangeText[256]; rangeText[0] = NULL; ULONG fetched = 0; hr = rangeInsert->GetText(ec, 0, rangeText, 256, &fetched); if (SUCCEEDED(hr) && rangeText) debugPrint(L"CDIME::_InsertAtSelection() text in range = %s", rangeText); *ppCompRange = rangeInsert; pias->Release(); hr = S_OK; Exit: return hr; }