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.

1308 lines
28 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. dbcs.c
  5. Abstract:
  6. Author:
  7. KazuM May.11.1992
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #if defined(FE_SB)
  13. #include "conime.h"
  14. #if !defined(BUILD_WOW6432)
  15. BOOL
  16. APIENTRY
  17. GetConsoleNlsMode(
  18. IN HANDLE hConsoleHandle,
  19. OUT LPDWORD lpNlsMode
  20. )
  21. /*++
  22. Parameters:
  23. hConsoleHandle - Supplies a console input or output handle.
  24. lpNlsMode - Supplies a pointer to the NLS mode.
  25. Return Value:
  26. TRUE - The operation was successful.
  27. FALSE/NULL - The operation failed. Extended error status is available
  28. using GetLastError.
  29. --*/
  30. {
  31. #if defined(FE_IME)
  32. CONSOLE_API_MSG m;
  33. PCONSOLE_NLS_MODE_MSG a = &m.u.GetConsoleNlsMode;
  34. NTSTATUS Status;
  35. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  36. a->Handle = hConsoleHandle;
  37. a->Ready = FALSE;
  38. Status = NtCreateEvent(&(a->hEvent),
  39. EVENT_ALL_ACCESS,
  40. NULL,
  41. SynchronizationEvent,
  42. (BOOLEAN)FALSE
  43. );
  44. if (!NT_SUCCESS(Status)) {
  45. SET_LAST_NT_ERROR(Status);
  46. return FALSE;
  47. }
  48. CsrClientCallServer( (PCSR_API_MSG)&m,
  49. NULL,
  50. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  51. ConsolepGetNlsMode
  52. ),
  53. sizeof( *a )
  54. );
  55. if (NT_SUCCESS( m.ReturnValue )) {
  56. Status = NtWaitForSingleObject(a->hEvent, FALSE, NULL);
  57. if (a->Ready == FALSE)
  58. {
  59. /*
  60. * If not ready conversion status on this console,
  61. * then one more try get status.
  62. */
  63. CsrClientCallServer( (PCSR_API_MSG)&m,
  64. NULL,
  65. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  66. ConsolepGetNlsMode
  67. ),
  68. sizeof( *a )
  69. );
  70. if (! NT_SUCCESS( m.ReturnValue )) {
  71. SET_LAST_NT_ERROR (m.ReturnValue);
  72. NtClose(a->hEvent);
  73. return FALSE;
  74. }
  75. else
  76. {
  77. Status = NtWaitForSingleObject(a->hEvent, FALSE, NULL);
  78. }
  79. }
  80. NtClose(a->hEvent);
  81. try {
  82. *lpNlsMode = a->NlsMode;
  83. } except( EXCEPTION_EXECUTE_HANDLER ) {
  84. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  85. return FALSE;
  86. }
  87. return TRUE;
  88. } else {
  89. SET_LAST_NT_ERROR (m.ReturnValue);
  90. NtClose(a->hEvent);
  91. return FALSE;
  92. }
  93. #else
  94. return FALSE;
  95. #endif
  96. }
  97. BOOL
  98. APIENTRY
  99. SetConsoleNlsMode(
  100. IN HANDLE hConsoleHandle,
  101. IN DWORD dwNlsMode
  102. )
  103. /*++
  104. Parameters:
  105. hConsoleHandle - Supplies a console input or output handle.
  106. dwNlsMode - Supplies NLS mode.
  107. Return Value:
  108. TRUE - The operation was successful.
  109. FALSE/NULL - The operation failed. Extended error status is available
  110. using GetLastError.
  111. --*/
  112. {
  113. #if defined(FE_IME)
  114. CONSOLE_API_MSG m;
  115. PCONSOLE_NLS_MODE_MSG a = &m.u.SetConsoleNlsMode;
  116. NTSTATUS Status;
  117. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  118. a->Handle = hConsoleHandle;
  119. a->NlsMode = dwNlsMode;
  120. Status = NtCreateEvent(&(a->hEvent),
  121. EVENT_ALL_ACCESS,
  122. NULL,
  123. SynchronizationEvent,
  124. (BOOLEAN)FALSE
  125. );
  126. if (!NT_SUCCESS(Status)) {
  127. SET_LAST_NT_ERROR(Status);
  128. return FALSE;
  129. }
  130. CsrClientCallServer( (PCSR_API_MSG)&m,
  131. NULL,
  132. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  133. ConsolepSetNlsMode
  134. ),
  135. sizeof( *a )
  136. );
  137. if (NT_SUCCESS( m.ReturnValue )) {
  138. Status = NtWaitForSingleObject(a->hEvent, FALSE, NULL);
  139. NtClose(a->hEvent);
  140. if (Status != 0) {
  141. SET_LAST_NT_ERROR(Status);
  142. return FALSE;
  143. }
  144. return TRUE;
  145. } else {
  146. SET_LAST_NT_ERROR (m.ReturnValue);
  147. NtClose(a->hEvent);
  148. return FALSE;
  149. }
  150. #else
  151. return FALSE;
  152. #endif
  153. }
  154. BOOL
  155. APIENTRY
  156. GetConsoleCharType(
  157. IN HANDLE hConsoleHandle,
  158. IN COORD coordCheck,
  159. OUT PDWORD pdwType
  160. )
  161. /*++
  162. Parameters:
  163. hConsoleHandle - Supplies a console input or output handle.
  164. coordCheck - set check position to these coordinates
  165. pdwType - receive character type
  166. Return Value:
  167. TRUE - The operation was successful.
  168. FALSE/NULL - The operation failed. Extended error status is available
  169. using GetLastError.
  170. --*/
  171. {
  172. CONSOLE_API_MSG m;
  173. PCONSOLE_CHAR_TYPE_MSG a = &m.u.GetConsoleCharType;
  174. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  175. a->Handle = hConsoleHandle;
  176. a->coordCheck = coordCheck;
  177. CsrClientCallServer( (PCSR_API_MSG)&m,
  178. NULL,
  179. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  180. ConsolepCharType
  181. ),
  182. sizeof( *a )
  183. );
  184. if (NT_SUCCESS( m.ReturnValue )) {
  185. try {
  186. *pdwType = a->dwType;
  187. } except( EXCEPTION_EXECUTE_HANDLER ) {
  188. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  189. return FALSE;
  190. }
  191. return TRUE;
  192. } else {
  193. SET_LAST_NT_ERROR (m.ReturnValue);
  194. return FALSE;
  195. }
  196. }
  197. BOOL
  198. APIENTRY
  199. SetConsoleLocalEUDC(
  200. IN HANDLE hConsoleHandle,
  201. IN WORD wCodePoint,
  202. IN COORD cFontSize,
  203. IN PCHAR lpSB
  204. )
  205. /*++
  206. Parameters:
  207. hConsoleHandle - Supplies a console input or output handle.
  208. wCodePoint - Code point of font by Shift JIS code.
  209. cFontSize - FontSize of Font
  210. lpSB - Pointer of font bitmap Buffer
  211. Return Value:
  212. TRUE - The operation was successful.
  213. FALSE/NULL - The operation failed. Extended error status is available
  214. using GetLastError.
  215. --*/
  216. {
  217. CONSOLE_API_MSG m;
  218. PCONSOLE_LOCAL_EUDC_MSG a = &m.u.SetConsoleLocalEUDC;
  219. PCSR_CAPTURE_HEADER CaptureBuffer;
  220. ULONG DataLength;
  221. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  222. a->Handle = hConsoleHandle;
  223. a->CodePoint = wCodePoint;
  224. a->FontSize = cFontSize;
  225. DataLength = ((cFontSize.X + 7) / 8) * cFontSize.Y;
  226. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  227. DataLength
  228. );
  229. if (CaptureBuffer == NULL) {
  230. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  231. return FALSE;
  232. }
  233. CsrCaptureMessageBuffer( CaptureBuffer,
  234. lpSB,
  235. DataLength,
  236. (PVOID *) &a->FontFace
  237. );
  238. CsrClientCallServer( (PCSR_API_MSG)&m,
  239. CaptureBuffer,
  240. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  241. ConsolepSetLocalEUDC
  242. ),
  243. sizeof( *a )
  244. );
  245. CsrFreeCaptureBuffer( CaptureBuffer );
  246. if (NT_SUCCESS( m.ReturnValue )) {
  247. return TRUE;
  248. } else {
  249. SET_LAST_NT_ERROR (m.ReturnValue);
  250. return FALSE;
  251. }
  252. }
  253. BOOL
  254. APIENTRY
  255. SetConsoleCursorMode(
  256. IN HANDLE hConsoleHandle,
  257. IN BOOL Blink,
  258. IN BOOL DBEnable
  259. )
  260. /*++
  261. Parameters:
  262. hConsoleHandle - Supplies a console input or output handle.
  263. Blink - Blinking enable/disable switch.
  264. DBEnable - Double Byte width enable/disable switch.
  265. Return Value:
  266. TRUE - The operation was successful.
  267. FALSE/NULL - The operation failed. Extended error status is available
  268. using GetLastError.
  269. --*/
  270. {
  271. CONSOLE_API_MSG m;
  272. PCONSOLE_CURSOR_MODE_MSG a = &m.u.SetConsoleCursorMode;
  273. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  274. a->Handle = hConsoleHandle;
  275. a->Blink = Blink;
  276. a->DBEnable = DBEnable;
  277. CsrClientCallServer( (PCSR_API_MSG)&m,
  278. NULL,
  279. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  280. ConsolepSetCursorMode
  281. ),
  282. sizeof( *a )
  283. );
  284. if (NT_SUCCESS( m.ReturnValue )) {
  285. return TRUE;
  286. } else {
  287. SET_LAST_NT_ERROR (m.ReturnValue);
  288. return FALSE;
  289. }
  290. }
  291. BOOL
  292. APIENTRY
  293. GetConsoleCursorMode(
  294. IN HANDLE hConsoleHandle,
  295. OUT PBOOL pbBlink,
  296. OUT PBOOL pbDBEnable
  297. )
  298. /*++
  299. Parameters:
  300. hConsoleHandle - Supplies a console input or output handle.
  301. Blink - Blinking enable/disable switch.
  302. DBEnable - Double Byte width enable/disable switch.
  303. Return Value:
  304. TRUE - The operation was successful.
  305. FALSE/NULL - The operation failed. Extended error status is available
  306. using GetLastError.
  307. --*/
  308. {
  309. CONSOLE_API_MSG m;
  310. PCONSOLE_CURSOR_MODE_MSG a = &m.u.GetConsoleCursorMode;
  311. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  312. a->Handle = hConsoleHandle;
  313. CsrClientCallServer( (PCSR_API_MSG)&m,
  314. NULL,
  315. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  316. ConsolepGetCursorMode
  317. ),
  318. sizeof( *a )
  319. );
  320. if (NT_SUCCESS( m.ReturnValue )) {
  321. try {
  322. *pbBlink = a->Blink;
  323. *pbDBEnable = a->DBEnable;
  324. } except( EXCEPTION_EXECUTE_HANDLER ) {
  325. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  326. return FALSE;
  327. }
  328. return TRUE;
  329. } else {
  330. SET_LAST_NT_ERROR (m.ReturnValue);
  331. return FALSE;
  332. }
  333. }
  334. BOOL
  335. APIENTRY
  336. RegisterConsoleOS2(
  337. IN BOOL fOs2Register
  338. )
  339. /*++
  340. Description:
  341. This routine registers the OS/2 with the console.
  342. Parameters:
  343. Return Value:
  344. TRUE - The operation was successful.
  345. FALSE/NULL - The operation failed. Extended error status is available
  346. using GetLastError.
  347. --*/
  348. {
  349. CONSOLE_API_MSG m;
  350. PCONSOLE_REGISTEROS2_MSG a = &m.u.RegisterConsoleOS2;
  351. NTSTATUS Status;
  352. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  353. a->fOs2Register = fOs2Register;
  354. CsrClientCallServer( (PCSR_API_MSG)&m,
  355. NULL,
  356. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  357. ConsolepRegisterOS2
  358. ),
  359. sizeof( *a )
  360. );
  361. if (!NT_SUCCESS( m.ReturnValue)) {
  362. SET_LAST_NT_ERROR(m.ReturnValue);
  363. return FALSE;
  364. }
  365. else {
  366. return TRUE;
  367. }
  368. }
  369. BOOL
  370. APIENTRY
  371. SetConsoleOS2OemFormat(
  372. IN BOOL fOs2OemFormat
  373. )
  374. /*++
  375. Description:
  376. This routine sets the OS/2 OEM Format with the console.
  377. Parameters:
  378. Return Value:
  379. TRUE - The operation was successful.
  380. FALSE/NULL - The operation failed. Extended error status is available
  381. using GetLastError.
  382. --*/
  383. {
  384. CONSOLE_API_MSG m;
  385. PCONSOLE_SETOS2OEMFORMAT_MSG a = &m.u.SetConsoleOS2OemFormat;
  386. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  387. a->fOs2OemFormat = fOs2OemFormat;
  388. CsrClientCallServer( (PCSR_API_MSG)&m,
  389. NULL,
  390. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  391. ConsolepSetOS2OemFormat
  392. ),
  393. sizeof( *a )
  394. );
  395. if (!NT_SUCCESS( m.ReturnValue)) {
  396. SET_LAST_NT_ERROR(m.ReturnValue);
  397. return FALSE;
  398. }
  399. else {
  400. return TRUE;
  401. }
  402. }
  403. #endif //!defined(BUILD_WOW6432)
  404. #if defined(FE_IME)
  405. #if !defined(BUILD_WOW6432)
  406. BOOL
  407. APIENTRY
  408. RegisterConsoleIMEInternal(
  409. IN HWND hWndConsoleIME,
  410. IN DWORD dwConsoleIMEThreadId,
  411. IN DWORD DesktopLength,
  412. IN LPWSTR Desktop,
  413. OUT DWORD *dwConsoleThreadId
  414. )
  415. {
  416. CONSOLE_API_MSG m;
  417. PCONSOLE_REGISTER_CONSOLEIME_MSG a = &m.u.RegisterConsoleIME;
  418. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  419. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  420. a->hWndConsoleIME = hWndConsoleIME;
  421. a->dwConsoleIMEThreadId = dwConsoleIMEThreadId;
  422. a->DesktopLength = DesktopLength;
  423. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  424. DesktopLength
  425. );
  426. if (CaptureBuffer == NULL) {
  427. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  428. return FALSE;
  429. }
  430. CsrCaptureMessageBuffer( CaptureBuffer,
  431. Desktop,
  432. a->DesktopLength,
  433. (PVOID *) &a->Desktop
  434. );
  435. //
  436. // Connect to the server process
  437. //
  438. CsrClientCallServer( (PCSR_API_MSG)&m,
  439. CaptureBuffer,
  440. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  441. ConsolepRegisterConsoleIME
  442. ),
  443. sizeof( *a )
  444. );
  445. //HS Jan.20 if (CaptureBuffer) {
  446. CsrFreeCaptureBuffer( CaptureBuffer );
  447. //HS Jan.20 }
  448. if (!NT_SUCCESS( m.ReturnValue)) {
  449. SET_LAST_NT_ERROR(m.ReturnValue);
  450. return FALSE;
  451. }
  452. else {
  453. try {
  454. if (dwConsoleThreadId != NULL)
  455. *dwConsoleThreadId = a->dwConsoleThreadId;
  456. } except( EXCEPTION_EXECUTE_HANDLER ) {
  457. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  458. return FALSE;
  459. }
  460. return TRUE;
  461. }
  462. }
  463. #endif //!defined(BUILD_WOW6432)
  464. #if !defined(BUILD_WOW64)
  465. BOOL
  466. APIENTRY
  467. RegisterConsoleIME(
  468. IN HWND hWndConsoleIME,
  469. OUT DWORD *dwConsoleThreadId
  470. )
  471. /*++
  472. Description:
  473. This routine register the Console IME on the current desktop.
  474. Parameters:
  475. Return Value:
  476. TRUE - The operation was successful.
  477. FALSE - The operation failed.
  478. --*/
  479. {
  480. STARTUPINFOW StartupInfo;
  481. DWORD dwDesktopLength;
  482. GetStartupInfoW(&StartupInfo);
  483. if (StartupInfo.lpDesktop != NULL && *StartupInfo.lpDesktop != 0) {
  484. dwDesktopLength = (USHORT)((wcslen(StartupInfo.lpDesktop)+1)*sizeof(WCHAR));
  485. dwDesktopLength = (USHORT)(min(dwDesktopLength,MAX_TITLE_LENGTH));
  486. } else {
  487. dwDesktopLength = 0;
  488. }
  489. return RegisterConsoleIMEInternal(hWndConsoleIME,
  490. GetCurrentThreadId(),
  491. dwDesktopLength,
  492. StartupInfo.lpDesktop,
  493. dwConsoleThreadId);
  494. }
  495. #endif //!defined(BUILD_WOW64)
  496. #if !defined(BUILD_WOW6432)
  497. BOOL
  498. APIENTRY
  499. UnregisterConsoleIMEInternal(
  500. IN DWORD dwConsoleIMEThtreadId
  501. )
  502. {
  503. CONSOLE_API_MSG m;
  504. PCONSOLE_UNREGISTER_CONSOLEIME_MSG a = &m.u.UnregisterConsoleIME;
  505. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  506. a->dwConsoleIMEThreadId = dwConsoleIMEThtreadId;
  507. //
  508. // Connect to the server process
  509. //
  510. CsrClientCallServer( (PCSR_API_MSG)&m,
  511. NULL,
  512. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  513. ConsolepUnregisterConsoleIME
  514. ),
  515. sizeof( *a )
  516. );
  517. if (!NT_SUCCESS( m.ReturnValue)) {
  518. SET_LAST_NT_ERROR(m.ReturnValue);
  519. return FALSE;
  520. }
  521. else {
  522. return TRUE;
  523. }
  524. }
  525. #endif //!defined(BUILD_WOW6432)
  526. #if !defined(BUILD_WOW64)
  527. BOOL
  528. APIENTRY
  529. UnregisterConsoleIME(
  530. )
  531. /*++
  532. Description:
  533. This routine unregister the Console IME on the current desktop.
  534. Parameters:
  535. Return Value:
  536. TRUE - The operation was successful.
  537. FALSE - The operation failed.
  538. --*/
  539. {
  540. return UnregisterConsoleIMEInternal(GetCurrentThreadId());
  541. }
  542. NTSTATUS
  543. MyRegOpenKey(
  544. IN HANDLE hKey,
  545. IN LPWSTR lpSubKey,
  546. OUT PHANDLE phResult
  547. )
  548. {
  549. OBJECT_ATTRIBUTES Obja;
  550. UNICODE_STRING SubKey;
  551. //
  552. // Convert the subkey to a counted Unicode string.
  553. //
  554. RtlInitUnicodeString( &SubKey, lpSubKey );
  555. //
  556. // Initialize the OBJECT_ATTRIBUTES structure and open the key.
  557. //
  558. InitializeObjectAttributes(
  559. &Obja,
  560. &SubKey,
  561. OBJ_CASE_INSENSITIVE,
  562. hKey,
  563. NULL
  564. );
  565. return NtOpenKey(
  566. phResult,
  567. KEY_READ,
  568. &Obja
  569. );
  570. }
  571. NTSTATUS
  572. MyRegQueryValue(
  573. IN HANDLE hKey,
  574. IN LPWSTR lpValueName,
  575. IN DWORD dwValueLength,
  576. OUT LPBYTE lpData
  577. )
  578. {
  579. UNICODE_STRING ValueName;
  580. ULONG BufferLength;
  581. ULONG ResultLength;
  582. PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
  583. NTSTATUS Status;
  584. //
  585. // Convert the subkey to a counted Unicode string.
  586. //
  587. RtlInitUnicodeString( &ValueName, lpValueName );
  588. BufferLength = sizeof(KEY_VALUE_FULL_INFORMATION) + dwValueLength + ValueName.Length;;
  589. KeyValueInformation = LocalAlloc(LPTR,BufferLength);
  590. if (KeyValueInformation == NULL)
  591. return STATUS_NO_MEMORY;
  592. Status = NtQueryValueKey(
  593. hKey,
  594. &ValueName,
  595. KeyValueFullInformation,
  596. KeyValueInformation,
  597. BufferLength,
  598. &ResultLength
  599. );
  600. if (NT_SUCCESS(Status)) {
  601. ASSERT(KeyValueInformation->DataLength <= dwValueLength);
  602. RtlMoveMemory(lpData,
  603. (PBYTE)KeyValueInformation + KeyValueInformation->DataOffset,
  604. KeyValueInformation->DataLength);
  605. if (KeyValueInformation->Type == REG_SZ) {
  606. if (KeyValueInformation->DataLength + sizeof(WCHAR) > dwValueLength) {
  607. KeyValueInformation->DataLength -= sizeof(WCHAR);
  608. }
  609. lpData[KeyValueInformation->DataLength++] = 0;
  610. lpData[KeyValueInformation->DataLength] = 0;
  611. }
  612. }
  613. LocalFree(KeyValueInformation);
  614. return Status;
  615. }
  616. VOID
  617. GetCommandLineString(
  618. IN LPWSTR CommandLine,
  619. IN DWORD dwSize
  620. )
  621. {
  622. NTSTATUS Status;
  623. HANDLE hkRegistry;
  624. WCHAR awchBuffer[ 512 ];
  625. DWORD dwRet;
  626. dwRet = GetSystemDirectoryW(CommandLine, dwSize);
  627. if (dwRet)
  628. {
  629. CommandLine[dwRet++] = L'\\';
  630. CommandLine[dwRet] = L'\0';
  631. dwSize -= dwRet;
  632. }
  633. else
  634. {
  635. CommandLine[0] = L'\0';
  636. }
  637. Status = MyRegOpenKey(NULL,
  638. MACHINE_REGISTRY_CONSOLE,
  639. &hkRegistry);
  640. if (NT_SUCCESS( Status ))
  641. {
  642. Status = MyRegQueryValue(hkRegistry,
  643. MACHINE_REGISTRY_CONSOLEIME,
  644. sizeof(awchBuffer), (PBYTE)&awchBuffer);
  645. if (NT_SUCCESS( Status ))
  646. {
  647. dwRet = wcslen(awchBuffer);
  648. if (dwRet < dwSize)
  649. {
  650. wcscat(CommandLine, awchBuffer);
  651. }
  652. else
  653. {
  654. CommandLine[0] = L'\0';
  655. goto ErrorExit;
  656. }
  657. }
  658. else
  659. {
  660. goto ErrorExit;
  661. }
  662. NtClose(hkRegistry);
  663. }
  664. else
  665. {
  666. goto ErrorExit;
  667. }
  668. return;
  669. ErrorExit:
  670. wcscat(CommandLine, L"conime.exe");
  671. return;
  672. }
  673. DWORD
  674. ConsoleIMERoutine(
  675. IN LPVOID lpThreadParameter
  676. )
  677. /*++
  678. Routine Description:
  679. This thread is created when the create input thread.
  680. It invokes the console IME process.
  681. Arguments:
  682. lpThreadParameter - not use.
  683. Return Value:
  684. STATUS_SUCCESS - function was successful
  685. --*/
  686. {
  687. NTSTATUS Status;
  688. BOOL fRet;
  689. static BOOL fInConIMERoutine = FALSE;
  690. DWORD fdwCreate;
  691. STARTUPINFOW StartupInfo;
  692. STARTUPINFOW StartupInfoConsole;
  693. WCHAR CommandLine[MAX_PATH*2];
  694. PROCESS_INFORMATION ProcessInformation;
  695. HANDLE hEvent;
  696. DWORD dwWait;
  697. Status = STATUS_SUCCESS;
  698. //
  699. // Prevent the user from launching multiple applets attached
  700. // to a single console
  701. //
  702. if (fInConIMERoutine) {
  703. return (ULONG)STATUS_UNSUCCESSFUL;
  704. }
  705. fInConIMERoutine = TRUE;
  706. //
  707. // Create event
  708. //
  709. hEvent = CreateEventW(NULL, // Security attributes
  710. FALSE, // Manual reset
  711. FALSE, // Initial state
  712. CONSOLEIME_EVENT); // Event object name
  713. if (hEvent == NULL)
  714. {
  715. goto ErrorExit;
  716. }
  717. if (GetLastError() == ERROR_ALREADY_EXISTS)
  718. {
  719. goto ErrorExit;
  720. }
  721. //
  722. // Get Console IME process name and event name
  723. //
  724. GetCommandLineString(CommandLine, sizeof(CommandLine)/sizeof(WCHAR));
  725. GetStartupInfoW(&StartupInfoConsole);
  726. RtlZeroMemory(&StartupInfo, sizeof(StartupInfo));
  727. StartupInfo.cb = sizeof(StartupInfo);
  728. StartupInfo.wShowWindow = SW_HIDE;
  729. StartupInfo.dwFlags = STARTF_FORCEONFEEDBACK;
  730. StartupInfo.lpDesktop = StartupInfoConsole.lpDesktop;
  731. //
  732. // create Console IME process
  733. //
  734. fdwCreate = NORMAL_PRIORITY_CLASS | CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP;
  735. fRet = CreateProcessW(NULL, // Application name
  736. CommandLine, // Command line
  737. NULL, // process security attributes
  738. NULL, // thread security attributes
  739. FALSE, // inherit handles
  740. fdwCreate, // create flags
  741. NULL, // environment
  742. NULL, // current directory
  743. &StartupInfo, // Start up information
  744. &ProcessInformation // process information
  745. );
  746. if (! fRet)
  747. {
  748. Status = GetLastError();
  749. }
  750. else
  751. {
  752. dwWait = WaitForSingleObject(hEvent, 10 * 1000); // wait 10 sec for console IME process
  753. if (dwWait == WAIT_TIMEOUT)
  754. {
  755. TerminateProcess(ProcessInformation.hProcess, 0);
  756. }
  757. CloseHandle(ProcessInformation.hThread) ;
  758. CloseHandle(ProcessInformation.hProcess) ;
  759. }
  760. CloseHandle(hEvent);
  761. ErrorExit:
  762. fInConIMERoutine = FALSE;
  763. return Status;
  764. }
  765. #endif //!defined(BUILD_WOW6432)
  766. #endif // FE_IME
  767. #else // FE_SB
  768. // Followings are stub functions for FE Console Support
  769. #if !defined(BUILD_WOW6432)
  770. BOOL
  771. APIENTRY
  772. GetConsoleNlsMode(
  773. IN HANDLE hConsoleHandle,
  774. OUT LPDWORD lpNlsMode
  775. )
  776. /*++
  777. Parameters:
  778. hConsoleHandle - Supplies a console input or output handle.
  779. lpNlsMode - Supplies a pointer to the NLS mode.
  780. Return Value:
  781. TRUE - The operation was successful.
  782. FALSE/NULL - The operation failed. Extended error status is available
  783. using GetLastError.
  784. --*/
  785. {
  786. return FALSE;
  787. }
  788. BOOL
  789. APIENTRY
  790. SetConsoleNlsMode(
  791. IN HANDLE hConsoleHandle,
  792. IN DWORD dwNlsMode
  793. )
  794. /*++
  795. Parameters:
  796. hConsoleHandle - Supplies a console input or output handle.
  797. dwNlsMode - Supplies NLS mode.
  798. Return Value:
  799. TRUE - The operation was successful.
  800. FALSE/NULL - The operation failed. Extended error status is available
  801. using GetLastError.
  802. --*/
  803. {
  804. return FALSE;
  805. }
  806. BOOL
  807. APIENTRY
  808. GetConsoleCharType(
  809. IN HANDLE hConsoleHandle,
  810. IN COORD coordCheck,
  811. OUT PDWORD pdwType
  812. )
  813. /*++
  814. Parameters:
  815. hConsoleHandle - Supplies a console input or output handle.
  816. coordCheck - set check position to these coordinates
  817. pdwType - receive character type
  818. Return Value:
  819. TRUE - The operation was successful.
  820. FALSE/NULL - The operation failed. Extended error status is available
  821. using GetLastError.
  822. --*/
  823. {
  824. return FALSE;
  825. }
  826. BOOL
  827. APIENTRY
  828. SetConsoleLocalEUDC(
  829. IN HANDLE hConsoleHandle,
  830. IN WORD wCodePoint,
  831. IN COORD cFontSize,
  832. IN PCHAR lpSB
  833. )
  834. /*++
  835. Parameters:
  836. hConsoleHandle - Supplies a console input or output handle.
  837. wCodePoint - Code point of font by Shift JIS code.
  838. cFontSize - FontSize of Font
  839. lpSB - Pointer of font bitmap Buffer
  840. Return Value:
  841. TRUE - The operation was successful.
  842. FALSE/NULL - The operation failed. Extended error status is available
  843. using GetLastError.
  844. --*/
  845. {
  846. return FALSE;
  847. }
  848. BOOL
  849. APIENTRY
  850. SetConsoleCursorMode(
  851. IN HANDLE hConsoleHandle,
  852. IN BOOL Blink,
  853. IN BOOL DBEnable
  854. )
  855. /*++
  856. Parameters:
  857. hConsoleHandle - Supplies a console input or output handle.
  858. Blink - Blinking enable/disable switch.
  859. DBEnable - Double Byte width enable/disable switch.
  860. Return Value:
  861. TRUE - The operation was successful.
  862. FALSE/NULL - The operation failed. Extended error status is available
  863. using GetLastError.
  864. --*/
  865. {
  866. return FALSE;
  867. }
  868. BOOL
  869. APIENTRY
  870. GetConsoleCursorMode(
  871. IN HANDLE hConsoleHandle,
  872. OUT PBOOL pbBlink,
  873. OUT PBOOL pbDBEnable
  874. )
  875. /*++
  876. Parameters:
  877. hConsoleHandle - Supplies a console input or output handle.
  878. Blink - Blinking enable/disable switch.
  879. DBEnable - Double Byte width enable/disable switch.
  880. Return Value:
  881. TRUE - The operation was successful.
  882. FALSE/NULL - The operation failed. Extended error status is available
  883. using GetLastError.
  884. --*/
  885. {
  886. return FALSE;
  887. }
  888. BOOL
  889. APIENTRY
  890. RegisterConsoleOS2(
  891. IN BOOL fOs2Register
  892. )
  893. /*++
  894. Description:
  895. This routine registers the OS/2 with the console.
  896. Parameters:
  897. Return Value:
  898. TRUE - The operation was successful.
  899. FALSE/NULL - The operation failed. Extended error status is available
  900. using GetLastError.
  901. --*/
  902. {
  903. return FALSE;
  904. }
  905. BOOL
  906. APIENTRY
  907. SetConsoleOS2OemFormat(
  908. IN BOOL fOs2OemFormat
  909. )
  910. /*++
  911. Description:
  912. This routine sets the OS/2 OEM Format with the console.
  913. Parameters:
  914. Return Value:
  915. TRUE - The operation was successful.
  916. FALSE/NULL - The operation failed. Extended error status is available
  917. using GetLastError.
  918. --*/
  919. {
  920. return FALSE;
  921. }
  922. #endif //!defined(BUILD_WOW6432)
  923. #if defined(FE_IME)
  924. #if !defined(BUILD_WOW64)
  925. BOOL
  926. APIENTRY
  927. RegisterConsoleIME(
  928. IN HWND hWndConsoleIME,
  929. OUT DWORD *dwConsoleThreadId
  930. )
  931. /*++
  932. Description:
  933. This routine register the Console IME on the current desktop.
  934. Parameters:
  935. Return Value:
  936. TRUE - The operation was successful.
  937. FALSE - The operation failed.
  938. --*/
  939. {
  940. return FALSE;
  941. }
  942. BOOL
  943. APIENTRY
  944. UnregisterConsoleIME(
  945. )
  946. /*++
  947. Description:
  948. This routine unregister the Console IME on the current desktop.
  949. Parameters:
  950. Return Value:
  951. TRUE - The operation was successful.
  952. FALSE - The operation failed.
  953. --*/
  954. {
  955. return FALSE;
  956. }
  957. #endif //!defined(BUILD_WOW64)
  958. #endif // FE_IME
  959. #endif // FE_SB