Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
7.3 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: accrare.c
  3. *
  4. * Copyright (c) 1985-95, Microsoft Corporation
  5. *
  6. * History:
  7. * 12-18-95 a-jimhar Created based on rare.c
  8. \***************************************************************************/
  9. #include "Access.h"
  10. #define REGSTR_PATH_SERIALKEYS __TEXT("Control Panel\\Accessibility\\SerialKeys")
  11. #define REGSTR_VAL_ACTIVEPORT __TEXT("ActivePort")
  12. #define REGSTR_VAL_BAUDRATE __TEXT("BaudRate")
  13. #define REGSTR_VAL_FLAGS __TEXT("Flags")
  14. #define REGSTR_VAL_PORTSTATE __TEXT("PortState")
  15. #define PMAP_STICKYKEYS __TEXT("Control Panel\\Accessibility\\StickyKeys")
  16. #define PMAP_KEYBOARDRESPONSE __TEXT("Control Panel\\Accessibility\\Keyboard Response")
  17. #define PMAP_MOUSEKEYS __TEXT("Control Panel\\Accessibility\\MouseKeys")
  18. #define PMAP_TOGGLEKEYS __TEXT("Control Panel\\Accessibility\\ToggleKeys")
  19. #define PMAP_TIMEOUT __TEXT("Control Panel\\Accessibility\\TimeOut")
  20. #define PMAP_SOUNDSENTRY __TEXT("Control Panel\\Accessibility\\SoundSentry")
  21. #define PMAP_SHOWSOUNDS __TEXT("Control Panel\\Accessibility\\ShowSounds")
  22. #define ISACCESSFLAGSET(s, flag) ((s).dwFlags & flag)
  23. #define SK_SPI_INITUSER -1
  24. typedef int (*PSKEY_SPI)(
  25. UINT uAction,
  26. UINT uParam,
  27. LPSERIALKEYS lpvParam,
  28. BOOL fuWinIni);
  29. /****************************************************************************/
  30. BOOL AccessSKeySystemParametersInfo(
  31. UINT uAction,
  32. UINT uParam,
  33. LPSERIALKEYS psk,
  34. BOOL fu)
  35. {
  36. BOOL fRet = FALSE;
  37. static PSKEY_SPI s_pSKEY_SystemParametersInfo =NULL;
  38. static BOOL s_fSKeySPIAttemptedLoad = FALSE;
  39. #ifdef UNICODE
  40. static BOOL s_fMustConvert = FALSE;
  41. CHAR szActivePort[MAX_PATH];
  42. CHAR szPort[MAX_PATH];
  43. PWSTR pszActivePort = NULL;
  44. PWSTR pszPort = NULL;
  45. Assert(sizeof(szActivePort) == sizeof(g_szActivePort));
  46. Assert(sizeof(szPort) == sizeof(g_szPort));
  47. #endif
  48. if (NULL == s_pSKEY_SystemParametersInfo && !s_fSKeySPIAttemptedLoad)
  49. {
  50. BOOL fRc = FALSE;
  51. HINSTANCE hinst = LoadLibrary(__TEXT("SKDLL.DLL"));
  52. if (NULL != hinst)
  53. {
  54. #ifdef UNICODE
  55. s_pSKEY_SystemParametersInfo = (PSKEY_SPI)GetProcAddress(
  56. (HMODULE)hinst, "SKEY_SystemParametersInfoW");
  57. if (NULL == s_pSKEY_SystemParametersInfo)
  58. {
  59. s_pSKEY_SystemParametersInfo = (PSKEY_SPI)GetProcAddress(
  60. (HMODULE)hinst, "SKEY_SystemParametersInfo");
  61. s_fMustConvert = TRUE;
  62. }
  63. #else
  64. s_pSKEY_SystemParametersInfo = (PSKEY_SPI)GetProcAddress(
  65. (HMODULE)hinst, "SKEY_SystemParametersInfo");
  66. #endif // UNICODE
  67. // We don't bother calling FreeLibrary(hinst), the library will be freed
  68. // when the app terminates
  69. }
  70. s_fSKeySPIAttemptedLoad = TRUE;
  71. }
  72. if (NULL != s_pSKEY_SystemParametersInfo)
  73. {
  74. #ifdef UNICODE
  75. if (s_fMustConvert)
  76. {
  77. memset(szActivePort, 0, sizeof(szActivePort));
  78. memset(szPort, 0, sizeof(szPort));
  79. pszActivePort = psk->lpszActivePort;
  80. pszPort = psk->lpszPort;
  81. if (NULL != psk->lpszActivePort)
  82. {
  83. psk->lpszActivePort = (PTSTR)szActivePort;
  84. }
  85. if (NULL != psk->lpszPort)
  86. {
  87. psk->lpszPort = (PTSTR)szPort;
  88. }
  89. if (SPI_SETSERIALKEYS == uAction)
  90. {
  91. if (NULL != psk->lpszActivePort)
  92. {
  93. WideCharToMultiByte(
  94. CP_ACP, 0, pszActivePort, -1,
  95. (PCHAR)psk->lpszActivePort, MAX_PATH, NULL, NULL);
  96. }
  97. if (NULL != psk->lpszPort)
  98. {
  99. WideCharToMultiByte(
  100. CP_ACP, 0, pszPort, -1,
  101. (PCHAR)psk->lpszPort, MAX_PATH, NULL, NULL);
  102. }
  103. }
  104. }
  105. #endif // UNICODE
  106. fRet = (BOOL)(*s_pSKEY_SystemParametersInfo)(
  107. uAction,
  108. uParam,
  109. psk,
  110. fu);
  111. #ifdef UNICODE
  112. if (s_fMustConvert && SPI_GETSERIALKEYS == uAction)
  113. {
  114. if (NULL != psk->lpszActivePort)
  115. {
  116. MultiByteToWideChar(
  117. CP_ACP, 0, (PCHAR)psk->lpszActivePort, -1,
  118. pszActivePort, MAX_PATH);
  119. }
  120. if (NULL != psk->lpszPort)
  121. {
  122. MultiByteToWideChar(
  123. CP_ACP, 0, (PCHAR)psk->lpszPort, -1,
  124. pszPort, MAX_PATH);
  125. }
  126. }
  127. if (NULL != psk->lpszActivePort)
  128. {
  129. psk->lpszActivePort = pszActivePort;
  130. }
  131. if (NULL != psk->lpszPort)
  132. {
  133. psk->lpszPort = pszPort;
  134. }
  135. #endif // UNICODE
  136. }
  137. return(fRet);
  138. }
  139. /***************************************************************************\
  140. * FixupAndRetrySystemParametersInfo
  141. *
  142. * Used by access but not implemented by NT's SPI:
  143. *
  144. * SPI_GETKEYBOARDPREF
  145. * SPI_SETKEYBOARDPREF
  146. *
  147. * SPI_GETHIGHCONTRAST
  148. * SPI_SETHIGHCONTRAST
  149. *
  150. * SPI_GETSERIALKEYS
  151. * SPI_SETSERIALKEYS
  152. *
  153. *
  154. * History:
  155. * 12-18-95 a-jimhar Created, derived from xxxSystemParametersInfo
  156. * 01-22-95 a-jimhar Removed old code that worked around NT bugs
  157. *
  158. * On NT this function fixes the parameters and calls SystemParametersInfo
  159. *
  160. \***************************************************************************/
  161. static BOOL FixupAndRetrySystemParametersInfo(
  162. UINT wFlag,
  163. DWORD wParam,
  164. PVOID lParam,
  165. UINT flags) // we ignoring this flag
  166. // could add support for SPIF_UPDATEINIFILE and SPIF_SENDCHANGE
  167. {
  168. BOOL fRet = FALSE;
  169. BOOL fCallSpi = FALSE;
  170. BOOL fChanged = FALSE;
  171. if (NULL != (PVOID)lParam)
  172. {
  173. switch (wFlag) {
  174. // Fake support
  175. case SPI_GETKEYBOARDPREF:
  176. {
  177. *(PBOOL) lParam = FALSE;
  178. fRet = TRUE;
  179. fCallSpi = FALSE;
  180. }
  181. break;
  182. case SPI_GETSERIALKEYS:
  183. {
  184. LPSERIALKEYS psk = (LPSERIALKEYS)lParam;
  185. if (NULL != psk &&
  186. (sizeof(*psk) == psk->cbSize || 0 == psk->cbSize))
  187. {
  188. fRet = AccessSKeySystemParametersInfo(
  189. wFlag,
  190. 0,
  191. psk,
  192. TRUE);
  193. }
  194. fCallSpi = FALSE;
  195. }
  196. break;
  197. case SPI_SETSERIALKEYS:
  198. {
  199. LPSERIALKEYS psk = (LPSERIALKEYS)lParam;
  200. if (NULL != psk &&
  201. (sizeof(*psk) == psk->cbSize || 0 == psk->cbSize))
  202. {
  203. fRet = AccessSKeySystemParametersInfo(
  204. wFlag,
  205. 0,
  206. psk,
  207. TRUE);
  208. fChanged = TRUE;
  209. }
  210. fCallSpi = FALSE;
  211. }
  212. break;
  213. default:
  214. // This function is only for fix-up and second chance calls.
  215. // We didn't fix anything, don't call SPI.
  216. fCallSpi = FALSE;
  217. fRet = FALSE;
  218. break;
  219. }
  220. }
  221. if (fCallSpi)
  222. {
  223. fRet = SystemParametersInfo(wFlag, wParam, lParam, flags);
  224. }
  225. else if (fChanged && (flags & SPIF_SENDCHANGE))
  226. {
  227. DWORD_PTR dwResult;
  228. SendMessageTimeout(
  229. HWND_BROADCAST,
  230. WM_WININICHANGE,
  231. wFlag,
  232. (LONG_PTR)NULL,
  233. SMTO_NORMAL,
  234. 100,
  235. &dwResult);
  236. }
  237. return(fRet);
  238. }
  239. /***************************************************************************\
  240. * AccessSystemParametersInfo
  241. *
  242. * History:
  243. * 12-18-95 a-jimhar Created.
  244. \***************************************************************************/
  245. BOOL AccessSystemParametersInfo(
  246. UINT wFlag,
  247. DWORD wParam,
  248. PVOID lParam,
  249. UINT flags)
  250. {
  251. BOOL fRet;
  252. // first give the system SPI a chance
  253. fRet = SystemParametersInfo(wFlag, wParam, lParam, flags);
  254. if (!fRet && g_fWinNT)
  255. {
  256. // the system SPI failed, fixup the params and try again
  257. fRet = FixupAndRetrySystemParametersInfo(wFlag, wParam, lParam, flags);
  258. }
  259. return(fRet);
  260. }