forked from jrywu/DIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TipCandidateString.cpp
128 lines (105 loc) · 2.34 KB
/
TipCandidateString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
//
// Derived from Microsoft Sample IME by Jeremy '13,7,17
//
//
#include "private.h"
#include "TipCandidateString.h"
HRESULT CTipCandidateString::CreateInstance(_Outptr_ CTipCandidateString **ppobj)
{
if (ppobj == nullptr)
{
return E_INVALIDARG;
}
*ppobj = nullptr;
*ppobj = new (std::nothrow) CTipCandidateString();
if (*ppobj == nullptr)
{
return E_OUTOFMEMORY;
}
return S_OK;
}
HRESULT CTipCandidateString::CreateInstance(REFIID riid, _Outptr_ void **ppvObj)
{
if (ppvObj == nullptr)
{
return E_INVALIDARG;
}
*ppvObj = nullptr;
*ppvObj = new (std::nothrow) CTipCandidateString();
if (*ppvObj == nullptr)
{
return E_OUTOFMEMORY;
}
return ((CTipCandidateString*)(*ppvObj))->QueryInterface(riid, ppvObj);
}
CTipCandidateString::CTipCandidateString(void)
{
_refCount = 0;
_index = 0;
}
CTipCandidateString::~CTipCandidateString()
{
}
// IUnknown methods
STDMETHODIMP CTipCandidateString::QueryInterface(REFIID riid, _Outptr_ void **ppvObj)
{
if (ppvObj == nullptr)
{
return E_POINTER;
}
*ppvObj = nullptr;
if (IsEqualIID(riid, IID_IUnknown))
{
*ppvObj = (CTipCandidateString*)this;
}
else if (IsEqualIID(riid, IID_ITfCandidateString))
{
*ppvObj = (CTipCandidateString*)this;
}
if (*ppvObj == nullptr)
{
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CTipCandidateString::AddRef(void)
{
return (ULONG)InterlockedIncrement((LONG*)&_refCount);
}
STDMETHODIMP_(ULONG) CTipCandidateString::Release(void)
{
ULONG refT = (ULONG)InterlockedDecrement((LONG*)&_refCount);
if (0 < refT)
{
return refT;
}
delete this;
return 0;
}
// ITfCandidateString methods
STDMETHODIMP CTipCandidateString::GetString(BSTR *pbstr)
{
*pbstr = SysAllocString(_candidateStr.c_str());
return S_OK;
}
STDMETHODIMP CTipCandidateString::GetIndex(_Out_ ULONG *pnIndex)
{
if (pnIndex == nullptr)
{
return E_POINTER;
}
*pnIndex = _index;
return S_OK;
}
STDMETHODIMP CTipCandidateString::SetIndex(ULONG uIndex)
{
_index = uIndex;
return S_OK;
}
STDMETHODIMP CTipCandidateString::SetString(_In_ const WCHAR *pch, DWORD_PTR length)
{
_candidateStr.assign(pch, 0, length);
return S_OK;
}