xref: /trunk/main/winaccessibility/inc/act.hxx (revision b0a7a3cf)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef __ACCACT_HXX
23 #define __ACCACT_HXX
24 
25 #include <windows.h>
26 #include <tchar.h>
27 
28 
IsXPOrLater()29 static bool IsXPOrLater()
30 {
31 	OSVERSIONINFO osvi;
32 
33 	ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
34 
35 	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
36 
37 	GetVersionEx(&osvi);
38 	return ((osvi.dwMajorVersion > 5) ||
39 		((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1)));
40 }
41 
42 static HANDLE pActCtx = INVALID_HANDLE_VALUE;
43 static ULONG_PTR lpCookie;
44 
ActivateActContext()45 static bool ActivateActContext()
46 {
47 	if(!IsXPOrLater())
48 		return false;
49 
50 	ACTCTX actctx;
51 
52 	ZeroMemory(&actctx, sizeof(actctx));
53 
54 	actctx.cbSize = sizeof(actctx);
55 
56 	TCHAR szDllDirPath[1024];
57 	::GetCurrentDirectory(1024,szDllDirPath);
58 	LPTSTR szDllPath = szDllDirPath;
59 	lstrcat(szDllPath, _T("\\UAccCOM.dll"));
60 
61 	actctx.lpSource = szDllPath;
62 	actctx.lpResourceName = MAKEINTRESOURCE(97);
63 	actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
64 
65 	HANDLE pActCtx = CreateActCtx(&actctx);
66 
67 	if(pActCtx != INVALID_HANDLE_VALUE)
68 	{
69 		if(ActivateActCtx(pActCtx, &lpCookie))
70 		{
71 			return true;
72 		}
73 	}
74 	pActCtx = INVALID_HANDLE_VALUE;
75 	lpCookie = 0;
76 	return false;
77 }
78 
DeactivateActContext()79 static void DeactivateActContext()
80 {
81 	if(!IsXPOrLater())
82 		return;
83 
84 	if(lpCookie)
85 		DeactivateActCtx(0, lpCookie);
86 
87 	if(pActCtx!=INVALID_HANDLE_VALUE)
88 		ReleaseActCtx(pActCtx);
89 }
90 #endif