1
1
#include " stdafx.h"
2
- #include " Register.h"
2
+ #include " TSFRegister.h"
3
+ #include < WeaselCommon.h>
3
4
#include < VersionHelpers.hpp>
5
+ #include < ComPtr.h>
4
6
5
7
#define CLSID_STRLEN 38 // strlen("{xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}")
6
8
@@ -9,41 +11,69 @@ static const char c_szTipKeyPrefix[] = "Software\\Microsft\\CTF\\TIP\\";
9
11
static const char c_szInProcSvr32[] = " InprocServer32" ;
10
12
static const char c_szModelName[] = " ThreadingModel" ;
11
13
12
- BOOL RegisterProfiles ()
13
- {
14
- WCHAR achIconFile[MAX_PATH];
15
- char achFileNameA[MAX_PATH];
16
- DWORD cchA;
17
- int cchIconFile;
18
- HRESULT hr;
19
-
20
- cchA = GetModuleFileNameA (g_hInst, achFileNameA, ARRAYSIZE (achFileNameA));
21
- cchIconFile = MultiByteToWideChar (CP_ACP, 0 , achFileNameA, cchA, achIconFile, ARRAYSIZE (achIconFile) - 1 );
22
- achIconFile[cchIconFile] = ' \0 ' ;
23
-
24
- ITfInputProcessorProfiles *pInputProcessorProfiles;
25
- hr = CoCreateInstance (CLSID_TF_InputProcessorProfiles, NULL , CLSCTX_INPROC_SERVER,
26
- IID_ITfInputProcessorProfiles, (void **) &pInputProcessorProfiles);
27
- if (hr != S_OK)
28
- return E_FAIL;
14
+ #ifdef WEASEL_USING_OLDER_TSF_SDK
29
15
30
- hr = pInputProcessorProfiles-> Register (c_clsidTextService);
31
- if (hr != S_OK)
32
- goto Exit ;
16
+ /* For Windows 8 */
17
+ const GUID GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT =
18
+ { 0x13A016DF , 0x560B , 0x46CD ,{ 0x94 , 0x7A , 0x4C , 0x3A , 0xF1 , 0xE0 , 0xE3 , 0x5D } } ;
33
19
34
- hr = pInputProcessorProfiles->AddLanguageProfile (
35
- c_clsidTextService,
36
- TEXTSERVICE_LANGID,
37
- c_guidProfile,
38
- TEXTSERVICE_DESC,
39
- (ULONG) wcslen (TEXTSERVICE_DESC),
40
- achIconFile,
41
- cchIconFile,
42
- TEXTSERVICE_ICON_INDEX);
20
+ const GUID GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT =
21
+ { 0x25504FB4 , 0x7BAB , 0x4BC1 ,{ 0x9C , 0x69 , 0xCF , 0x81 , 0x89 , 0x0F , 0x0E , 0xF5 } };
43
22
44
- Exit:
45
- pInputProcessorProfiles->Release ();
46
- return (hr == S_OK);
23
+ #endif
24
+
25
+ BOOL RegisterProfiles (std::wstring filename, HKL hkl)
26
+ {
27
+ HRESULT hr;
28
+
29
+ if (IsWindows8OrGreater ()) {
30
+ ComPtr<ITfInputProcessorProfileMgr> pInputProcessorProfileMgr;
31
+ hr = pInputProcessorProfileMgr.CoCreate (CLSID_TF_InputProcessorProfiles, NULL , CLSCTX_ALL);
32
+ if (FAILED (hr))
33
+ return FALSE ;
34
+
35
+ hr = pInputProcessorProfileMgr->RegisterProfile (
36
+ c_clsidTextService,
37
+ TEXTSERVICE_LANGID,
38
+ c_guidProfile,
39
+ TEXTSERVICE_DESC,
40
+ (ULONG)wcslen (TEXTSERVICE_DESC),
41
+ filename.c_str (),
42
+ filename.size (),
43
+ TEXTSERVICE_ICON_INDEX,
44
+ hkl,
45
+ 0 ,
46
+ TRUE ,
47
+ 0 );
48
+ }
49
+ else {
50
+ ComPtr<ITfInputProcessorProfiles> pInputProcessorProfiles;
51
+ hr = pInputProcessorProfiles.CoCreate (CLSID_TF_InputProcessorProfiles, NULL , CLSCTX_INPROC_SERVER);
52
+ if (FAILED (hr))
53
+ return FALSE ;
54
+
55
+ hr = pInputProcessorProfiles->Register (c_clsidTextService);
56
+ if (FAILED (hr))
57
+ return FALSE ;
58
+
59
+ hr = pInputProcessorProfiles->AddLanguageProfile (
60
+ c_clsidTextService,
61
+ TEXTSERVICE_LANGID,
62
+ c_guidProfile,
63
+ TEXTSERVICE_DESC,
64
+ (ULONG)wcslen (TEXTSERVICE_DESC),
65
+ filename.c_str (),
66
+ filename.size (),
67
+ TEXTSERVICE_ICON_INDEX);
68
+ if (FAILED (hr))
69
+ return FALSE ;
70
+ if (hkl) {
71
+ hr = pInputProcessorProfiles->SubstituteKeyboardLayout (
72
+ c_clsidTextService, TEXTSERVICE_LANGID, c_guidProfile, hkl);
73
+ if (FAILED (hr)) return FALSE ;
74
+ }
75
+ }
76
+ return TRUE ;
47
77
}
48
78
49
79
void UnregisterProfiles ()
@@ -52,10 +82,12 @@ void UnregisterProfiles()
52
82
HRESULT hr;
53
83
54
84
hr = CoCreateInstance (CLSID_TF_InputProcessorProfiles, NULL , CLSCTX_INPROC_SERVER,
55
- IID_ITfInputProcessorProfiles, (void **) &pInputProcessProfiles);
85
+ IID_ITfInputProcessorProfiles, (void **)&pInputProcessProfiles);
56
86
if (FAILED (hr))
57
87
return ;
58
88
89
+ pInputProcessProfiles->SubstituteKeyboardLayout (
90
+ c_clsidTextService, TEXTSERVICE_LANGID, c_guidProfile, NULL );
59
91
pInputProcessProfiles->Unregister (c_clsidTextService);
60
92
pInputProcessProfiles->Release ();
61
93
}
@@ -65,10 +97,10 @@ BOOL RegisterCategories()
65
97
ITfCategoryMgr *pCategoryMgr;
66
98
HRESULT hr;
67
99
68
- hr = CoCreateInstance (CLSID_TF_CategoryMgr, NULL , CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void **) &pCategoryMgr);
100
+ hr = CoCreateInstance (CLSID_TF_CategoryMgr, NULL , CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void **)&pCategoryMgr);
69
101
if (hr != S_OK)
70
102
return FALSE ;
71
-
103
+
72
104
hr = pCategoryMgr->RegisterCategory (c_clsidTextService, GUID_TFCAT_TIP_KEYBOARD, c_clsidTextService);
73
105
if (hr != S_OK)
74
106
goto Exit;
@@ -97,7 +129,7 @@ void UnregisterCategories()
97
129
ITfCategoryMgr *pCategoryMgr;
98
130
HRESULT hr;
99
131
100
- hr = CoCreateInstance (CLSID_TF_CategoryMgr, NULL , CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void **) &pCategoryMgr);
132
+ hr = CoCreateInstance (CLSID_TF_CategoryMgr, NULL , CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void **)&pCategoryMgr);
101
133
if (FAILED (hr))
102
134
return ;
103
135
@@ -107,15 +139,15 @@ void UnregisterCategories()
107
139
108
140
static BOOL CLSIDToStringA (REFGUID refGUID, char *pchA)
109
141
{
110
- static const BYTE GuidMap[] = {3 , 2 , 1 , 0 , ' -' , 5 , 4 , ' -' , 7 , 6 , ' -' ,
111
- 8 , 9 , ' -' , 10 , 11 , 12 , 13 , 14 , 15 };
142
+ static const BYTE GuidMap[] = { 3 , 2 , 1 , 0 , ' -' , 5 , 4 , ' -' , 7 , 6 , ' -' ,
143
+ 8 , 9 , ' -' , 10 , 11 , 12 , 13 , 14 , 15 };
112
144
113
145
static const char szDigits[] = " 0123456789ABCDEF" ;
114
146
115
147
int i;
116
148
char *p = pchA;
117
149
118
- const BYTE *pBytes = (const BYTE *) &refGUID;
150
+ const BYTE *pBytes = (const BYTE *)&refGUID;
119
151
120
152
*p++ = ' {' ;
121
153
for (i = 0 ; i < sizeof (GuidMap); i++)
@@ -158,28 +190,32 @@ static LONG RecurseDeleteKeyA(HKEY hParentKey, LPCSTR lpszKey)
158
190
return lRes == ERROR_SUCCESS ? RegDeleteKeyA (hParentKey, lpszKey) : lRes;
159
191
}
160
192
161
- BOOL RegisterServer ()
193
+ BOOL RegisterServer (std::wstring filename, bool wow64 )
162
194
{
163
195
DWORD dw;
164
196
HKEY hKey;
165
197
HKEY hSubKey;
166
198
BOOL fRet ;
167
199
char achIMEKey[ARRAYSIZE (c_szInfoKeyPrefix) + CLSID_STRLEN];
168
- TCHAR achFileName[MAX_PATH];
200
+ DWORD flags = KEY_WRITE;
201
+ if (wow64) {
202
+ flags |= KEY_WOW64_32KEY;
203
+ }
204
+ // TCHAR achFileName[MAX_PATH];
169
205
170
206
if (!CLSIDToStringA (c_clsidTextService, achIMEKey + ARRAYSIZE (c_szInfoKeyPrefix) - 1 ))
171
207
return FALSE ;
172
208
memcpy (achIMEKey, c_szInfoKeyPrefix, sizeof (c_szInfoKeyPrefix) - 1 );
173
209
174
- if (fRet = RegCreateKeyExA (HKEY_CLASSES_ROOT, achIMEKey, 0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE , NULL , &hKey, &dw) == ERROR_SUCCESS)
210
+ if (fRet = RegCreateKeyExA (HKEY_CLASSES_ROOT, achIMEKey, 0 , NULL , REG_OPTION_NON_VOLATILE, flags , NULL , &hKey, &dw) == ERROR_SUCCESS)
175
211
{
176
- fRet &= RegSetValueExA (hKey, NULL , 0 , REG_SZ, (BYTE *) TEXTSERVICE_DESC_A, (strlen (TEXTSERVICE_DESC_A) + 1 ) * sizeof (TCHAR)) == ERROR_SUCCESS;
177
- if (fRet &= RegCreateKeyExA (hKey, c_szInProcSvr32, 0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE , NULL , &hSubKey, &dw) == ERROR_SUCCESS)
212
+ fRet &= RegSetValueExA (hKey, NULL , 0 , REG_SZ, (BYTE *)TEXTSERVICE_DESC_A, (strlen (TEXTSERVICE_DESC_A) + 1 ) * sizeof (TCHAR)) == ERROR_SUCCESS;
213
+ if (fRet &= RegCreateKeyExA (hKey, c_szInProcSvr32, 0 , NULL , REG_OPTION_NON_VOLATILE, flags , NULL , &hSubKey, &dw) == ERROR_SUCCESS)
178
214
{
179
- dw = GetModuleFileName (g_hInst, achFileName, ARRAYSIZE (achFileName));
215
+ // dw = GetModuleFileName(g_hInst, achFileName, ARRAYSIZE(achFileName));
180
216
181
- fRet &= RegSetValueEx (hSubKey, NULL , 0 , REG_SZ, (BYTE *) achFileName , (lstrlen (achFileName ) + 1 ) * sizeof (TCHAR)) == ERROR_SUCCESS;
182
- fRet &= RegSetValueExA (hSubKey, c_szModelName, 0 , REG_SZ, (BYTE *) TEXTSERVICE_MODEL, (strlen (TEXTSERVICE_MODEL) + 1 )) == ERROR_SUCCESS;
217
+ fRet &= RegSetValueEx (hSubKey, NULL , 0 , REG_SZ, (BYTE *)filename. c_str () , (filename. size ( ) + 1 ) * sizeof (TCHAR)) == ERROR_SUCCESS;
218
+ fRet &= RegSetValueExA (hSubKey, c_szModelName, 0 , REG_SZ, (BYTE *)TEXTSERVICE_MODEL, (strlen (TEXTSERVICE_MODEL) + 1 )) == ERROR_SUCCESS;
183
219
RegCloseKey (hSubKey);
184
220
}
185
221
RegCloseKey (hKey);
0 commit comments