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.

1751 lines
43 KiB

  1. //depot/lab01_n/windows/Core/ntcon/client/getset.c#5 - integrate change 19598 (text)
  2. /*++
  3. Copyright (c) 1985 - 1999, Microsoft Corporation
  4. Module Name:
  5. getset.c
  6. Abstract:
  7. This module contains the stubs for the console get/set API.
  8. Author:
  9. Therese Stowell (thereses) 14-Nov-1990
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #pragma hdrstop
  15. #if !defined(BUILD_WOW6432)
  16. BOOL
  17. WINAPI
  18. GetConsoleMode(
  19. IN HANDLE hConsoleHandle,
  20. OUT LPDWORD lpMode
  21. )
  22. /*++
  23. Parameters:
  24. hConsoleHandle - Supplies a console input or output handle.
  25. lpMode - Supplies a pointer to a dword in which to store the mode.
  26. Input Mode Flags:
  27. ENABLE_LINE_INPUT - line oriented input is on.
  28. ENABLE_ECHO_INPUT - characters will be written to the screen as they are
  29. read.
  30. ENABLE_WINDOW_INPUT - the caller is windows-aware
  31. Output Mode Flags:
  32. ENABLE_LINE_OUTPUT - line oriented output is on.
  33. ENABLE_WRAP_AT_EOL_OUTPUT - the cursor will move to the
  34. beginning of the next line when the end of the row
  35. is reached.
  36. Return Value:
  37. TRUE - The operation was successful.
  38. FALSE/NULL - The operation failed. Extended error status is available
  39. using GetLastError.
  40. --*/
  41. {
  42. CONSOLE_API_MSG m;
  43. PCONSOLE_MODE_MSG a = &m.u.GetConsoleMode;
  44. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  45. a->Handle = hConsoleHandle;
  46. CsrClientCallServer( (PCSR_API_MSG)&m,
  47. NULL,
  48. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  49. ConsolepGetMode
  50. ),
  51. sizeof( *a )
  52. );
  53. if (NT_SUCCESS( m.ReturnValue )) {
  54. try {
  55. *lpMode = a->Mode;
  56. } except( EXCEPTION_EXECUTE_HANDLER ) {
  57. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  58. return FALSE;
  59. }
  60. return TRUE;
  61. } else {
  62. SET_LAST_NT_ERROR (m.ReturnValue);
  63. return FALSE;
  64. }
  65. }
  66. DWORD
  67. WINAPI
  68. GetNumberOfConsoleFonts(
  69. VOID
  70. )
  71. /*++
  72. Parameters:
  73. none.
  74. Return Value:
  75. NON-NULL - Returns the number of fonts available.
  76. FALSE/NULL - The operation failed.
  77. Extended error status is available using GetLastError.
  78. --*/
  79. {
  80. CONSOLE_API_MSG m;
  81. PCONSOLE_GETNUMBEROFFONTS_MSG a = &m.u.GetNumberOfConsoleFonts;
  82. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  83. CsrClientCallServer( (PCSR_API_MSG)&m,
  84. NULL,
  85. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  86. ConsolepGetNumberOfFonts
  87. ),
  88. sizeof( *a )
  89. );
  90. if (NT_SUCCESS( m.ReturnValue )) {
  91. return a->NumberOfFonts;
  92. } else {
  93. SET_LAST_NT_ERROR (m.ReturnValue);
  94. return FALSE;
  95. }
  96. }
  97. BOOL
  98. WINAPI
  99. GetNumberOfConsoleInputEvents(
  100. IN HANDLE hConsoleInput,
  101. OUT LPDWORD lpNumberOfEvents
  102. )
  103. /*++
  104. Parameters:
  105. hConsoleInput - Supplies an open handle to console input.
  106. lpNumberOfEvents - Pointer to number of events in input buffer.
  107. Return Value:
  108. TRUE - The operation was successful.
  109. FALSE/NULL - The operation failed.
  110. Extended error status is available using GetLastError.
  111. --*/
  112. {
  113. CONSOLE_API_MSG m;
  114. PCONSOLE_GETNUMBEROFINPUTEVENTS_MSG a = &m.u.GetNumberOfConsoleInputEvents;
  115. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  116. a->InputHandle = hConsoleInput;
  117. CsrClientCallServer( (PCSR_API_MSG)&m,
  118. NULL,
  119. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  120. ConsolepGetNumberOfInputEvents
  121. ),
  122. sizeof( *a )
  123. );
  124. if (NT_SUCCESS( m.ReturnValue )) {
  125. try {
  126. *lpNumberOfEvents = a->ReadyEvents;
  127. } except( EXCEPTION_EXECUTE_HANDLER ) {
  128. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  129. return FALSE;
  130. }
  131. return TRUE;
  132. }
  133. else {
  134. SET_LAST_NT_ERROR (m.ReturnValue);
  135. return FALSE;
  136. }
  137. }
  138. COORD
  139. WINAPI
  140. GetLargestConsoleWindowSize(
  141. IN HANDLE hConsoleOutput
  142. )
  143. /*++
  144. Returns largest window possible, given the current font. The return value
  145. does not take the screen buffer size into account.
  146. Parameters:
  147. hConsoleOutput - Supplies an open handle to console output.
  148. Return Value:
  149. The return value is the maximum window size in rows and columns. A size
  150. of zero will be returned if an error occurs. Extended error information
  151. can be retrieved by calling the GetLastError function.
  152. --*/
  153. {
  154. CONSOLE_API_MSG m;
  155. PCONSOLE_GETLARGESTWINDOWSIZE_MSG a = &m.u.GetLargestConsoleWindowSize;
  156. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  157. a->OutputHandle = hConsoleOutput;
  158. CsrClientCallServer( (PCSR_API_MSG)&m,
  159. NULL,
  160. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  161. ConsolepGetLargestWindowSize
  162. ),
  163. sizeof( *a )
  164. );
  165. if (NT_SUCCESS( m.ReturnValue )) {
  166. return a->Size;
  167. } else {
  168. COORD Dummy;
  169. Dummy.X = Dummy.Y = 0;
  170. SET_LAST_NT_ERROR (m.ReturnValue);
  171. return Dummy;
  172. }
  173. }
  174. BOOL
  175. WINAPI
  176. GetConsoleScreenBufferInfo(
  177. IN HANDLE hConsoleOutput,
  178. OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
  179. )
  180. /*++
  181. Parameters:
  182. hConsoleOutput - Supplies an open handle to console output.
  183. lpConsoleScreenBufferInfo - A pointer to a buffer to receive the
  184. requested information.
  185. Return Value:
  186. TRUE - The operation was successful.
  187. FALSE/NULL - The operation failed. Extended error status is available
  188. using GetLastError.
  189. --*/
  190. {
  191. CONSOLE_API_MSG m;
  192. PCONSOLE_GETSCREENBUFFERINFO_MSG a = &m.u.GetConsoleScreenBufferInfo;
  193. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  194. a->OutputHandle = hConsoleOutput;
  195. CsrClientCallServer( (PCSR_API_MSG)&m,
  196. NULL,
  197. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  198. ConsolepGetScreenBufferInfo
  199. ),
  200. sizeof( *a )
  201. );
  202. if (NT_SUCCESS( m.ReturnValue )) {
  203. try {
  204. lpConsoleScreenBufferInfo->dwSize = a->Size;
  205. lpConsoleScreenBufferInfo->dwCursorPosition = a->CursorPosition;
  206. lpConsoleScreenBufferInfo->wAttributes = a->Attributes;
  207. lpConsoleScreenBufferInfo->srWindow.Left = a->ScrollPosition.X;
  208. lpConsoleScreenBufferInfo->srWindow.Top = a->ScrollPosition.Y;
  209. lpConsoleScreenBufferInfo->srWindow.Right = lpConsoleScreenBufferInfo->srWindow.Left + a->CurrentWindowSize.X-1;
  210. lpConsoleScreenBufferInfo->srWindow.Bottom = lpConsoleScreenBufferInfo->srWindow.Top + a->CurrentWindowSize.Y-1;
  211. lpConsoleScreenBufferInfo->dwMaximumWindowSize = a->MaximumWindowSize;
  212. } except( EXCEPTION_EXECUTE_HANDLER ) {
  213. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  214. return FALSE;
  215. }
  216. return TRUE;
  217. } else {
  218. SET_LAST_NT_ERROR (m.ReturnValue);
  219. return FALSE;
  220. }
  221. }
  222. BOOL
  223. WINAPI
  224. GetConsoleCursorInfo(
  225. IN HANDLE hConsoleOutput,
  226. OUT PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
  227. )
  228. /*++
  229. Parameters:
  230. hConsoleOutput - Supplies an open handle to console output.
  231. lpConsoleCursorInfo - A pointer to a buffer to receive the
  232. requested information.
  233. Return Value:
  234. TRUE - The operation was successful.
  235. FALSE/NULL - The operation failed. Extended error status is available
  236. using GetLastError.
  237. --*/
  238. {
  239. CONSOLE_API_MSG m;
  240. PCONSOLE_GETCURSORINFO_MSG a = &m.u.GetConsoleCursorInfo;
  241. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  242. a->OutputHandle = hConsoleOutput;
  243. CsrClientCallServer( (PCSR_API_MSG)&m,
  244. NULL,
  245. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  246. ConsolepGetCursorInfo
  247. ),
  248. sizeof( *a )
  249. );
  250. if (NT_SUCCESS( m.ReturnValue )) {
  251. try {
  252. lpConsoleCursorInfo->dwSize = a->CursorSize;
  253. lpConsoleCursorInfo->bVisible = a->Visible;
  254. } except( EXCEPTION_EXECUTE_HANDLER ) {
  255. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  256. return FALSE;
  257. }
  258. return TRUE;
  259. } else {
  260. SET_LAST_NT_ERROR (m.ReturnValue);
  261. return FALSE;
  262. }
  263. }
  264. BOOL
  265. WINAPI
  266. GetConsoleSelectionInfo(
  267. OUT PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo
  268. )
  269. /*++
  270. Parameters:
  271. lpConsoleSelectionInfo - A pointer to a buffer to receive the
  272. requested information.
  273. Return Value:
  274. TRUE - The operation was successful.
  275. FALSE - The operation failed. Extended error status is available
  276. using GetLastError.
  277. --*/
  278. {
  279. CONSOLE_API_MSG m;
  280. PCONSOLE_GETSELECTIONINFO_MSG a = &m.u.GetConsoleSelectionInfo;
  281. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  282. CsrClientCallServer( (PCSR_API_MSG)&m,
  283. NULL,
  284. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  285. ConsolepGetSelectionInfo
  286. ),
  287. sizeof( *a )
  288. );
  289. if (NT_SUCCESS( m.ReturnValue )) {
  290. try {
  291. *lpConsoleSelectionInfo = a->SelectionInfo;
  292. } except( EXCEPTION_EXECUTE_HANDLER ) {
  293. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  294. return FALSE;
  295. }
  296. return TRUE;
  297. } else {
  298. SET_LAST_NT_ERROR (m.ReturnValue);
  299. return FALSE;
  300. }
  301. }
  302. BOOL
  303. WINAPI
  304. GetNumberOfConsoleMouseButtons(
  305. OUT LPDWORD lpNumberOfMouseButtons
  306. )
  307. /*++
  308. Parameters:
  309. hConsoleInput - Supplies an open handle to console input.
  310. lpNumberOfMouseButtons - pointer to the number of mouse buttons
  311. Return Value:
  312. TRUE - The operation was successful.
  313. FALSE/NULL - The operation failed. Extended error status is available
  314. using GetLastError.
  315. --*/
  316. {
  317. CONSOLE_API_MSG m;
  318. PCONSOLE_GETMOUSEINFO_MSG a = &m.u.GetConsoleMouseInfo;
  319. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  320. CsrClientCallServer( (PCSR_API_MSG)&m,
  321. NULL,
  322. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  323. ConsolepGetMouseInfo
  324. ),
  325. sizeof( *a )
  326. );
  327. if (NT_SUCCESS( m.ReturnValue )) {
  328. try {
  329. *lpNumberOfMouseButtons = a->NumButtons;
  330. } except( EXCEPTION_EXECUTE_HANDLER ) {
  331. SET_LAST_ERROR (ERROR_INVALID_ACCESS);
  332. return FALSE;
  333. }
  334. return TRUE;
  335. } else {
  336. SET_LAST_NT_ERROR (m.ReturnValue);
  337. return FALSE;
  338. }
  339. }
  340. DWORD
  341. WINAPI
  342. GetConsoleFontInfo(
  343. IN HANDLE hConsoleOutput,
  344. IN BOOL bMaximumWindow,
  345. IN DWORD nLength,
  346. OUT PCONSOLE_FONT_INFO lpConsoleFontInfo
  347. )
  348. /*++
  349. Parameters:
  350. hConsoleOutput - Supplies an open handle to console output.
  351. bMaximumWindow - TRUE if caller wants available fonts for the maximum
  352. window size. FALSE if caller wants available fonts for the current
  353. window size.
  354. nLength - Length of buffer in CONSOLE_FONT_INFOs.
  355. lpConsoleFontInfo - A pointer to a buffer to receive the
  356. requested information.
  357. Return Value:
  358. NON-NULL - Returns the number of fonts returned in lpConsoleFontInfo.
  359. FALSE/NULL - The operation failed. Extended error status is available
  360. using GetLastError.
  361. --*/
  362. {
  363. CONSOLE_API_MSG m;
  364. PCONSOLE_GETFONTINFO_MSG a = &m.u.GetConsoleFontInfo;
  365. PCSR_CAPTURE_HEADER CaptureBuffer;
  366. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  367. a->OutputHandle = hConsoleOutput;
  368. a->MaximumWindow = (BOOLEAN) bMaximumWindow;
  369. a->NumFonts = nLength;
  370. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  371. nLength * sizeof(CONSOLE_FONT_INFO)
  372. );
  373. if (CaptureBuffer == NULL) {
  374. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  375. return FALSE;
  376. }
  377. CsrCaptureMessageBuffer( CaptureBuffer,
  378. NULL,
  379. nLength * sizeof(CONSOLE_FONT_INFO),
  380. (PVOID *) &a->BufPtr
  381. );
  382. CsrClientCallServer( (PCSR_API_MSG)&m,
  383. CaptureBuffer,
  384. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  385. ConsolepGetFontInfo
  386. ),
  387. sizeof( *a )
  388. );
  389. if (NT_SUCCESS( m.ReturnValue )) {
  390. try {
  391. RtlCopyMemory( lpConsoleFontInfo, a->BufPtr, a->NumFonts * sizeof(CONSOLE_FONT_INFO));
  392. } except( EXCEPTION_EXECUTE_HANDLER ) {
  393. CsrFreeCaptureBuffer( CaptureBuffer );
  394. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  395. return 0;
  396. }
  397. }
  398. else {
  399. SET_LAST_NT_ERROR (m.ReturnValue);
  400. }
  401. CsrFreeCaptureBuffer( CaptureBuffer );
  402. return a->NumFonts;
  403. }
  404. COORD
  405. WINAPI
  406. GetConsoleFontSize(
  407. IN HANDLE hConsoleOutput,
  408. IN DWORD nFont
  409. )
  410. /*++
  411. Parameters:
  412. hConsoleOutput - Supplies an open handle to console output.
  413. nFont - Supplies the index of the font to return the size of.
  414. Return Value:
  415. The return value is the height and width of each character in the font.
  416. X field contains width. Y field contains height. Font size
  417. is expressed in pixels. If both the x and y sizes are 0, the function
  418. was unsuccessful. Extended error information can be retrieved by calling
  419. the GetLastError function.
  420. --*/
  421. {
  422. CONSOLE_API_MSG m;
  423. PCONSOLE_GETFONTSIZE_MSG a = &m.u.GetConsoleFontSize;
  424. COORD Dummy;
  425. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  426. a->OutputHandle = hConsoleOutput;
  427. a->FontIndex = nFont;
  428. CsrClientCallServer( (PCSR_API_MSG)&m,
  429. NULL,
  430. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  431. ConsolepGetFontSize
  432. ),
  433. sizeof( *a )
  434. );
  435. if (NT_SUCCESS( m.ReturnValue )) {
  436. return a->FontSize;
  437. } else {
  438. SET_LAST_NT_ERROR (m.ReturnValue);
  439. Dummy.X = Dummy.Y = 0;
  440. return Dummy;
  441. }
  442. }
  443. BOOL
  444. WINAPI
  445. GetCurrentConsoleFont(
  446. IN HANDLE hConsoleOutput,
  447. IN BOOL bMaximumWindow,
  448. OUT PCONSOLE_FONT_INFO lpConsoleCurrentFont
  449. )
  450. /*++
  451. Parameters:
  452. hConsoleOutput - Supplies an open handle to console output.
  453. bMaximumWindow - TRUE if caller wants current font for the maximum
  454. window size. FALSE if caller wants current font for the current
  455. window size.
  456. lpConsoleCurrentFont - A pointer to a buffer to receive the
  457. requested information.
  458. Return Value:
  459. TRUE - The operation was successful.
  460. FALSE/NULL - The operation failed. Extended error status is available
  461. using GetLastError.
  462. --*/
  463. {
  464. CONSOLE_API_MSG m;
  465. PCONSOLE_GETCURRENTFONT_MSG a = &m.u.GetCurrentConsoleFont;
  466. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  467. a->OutputHandle = hConsoleOutput;
  468. a->MaximumWindow = (BOOLEAN) bMaximumWindow;
  469. a->OutputHandle = hConsoleOutput;
  470. CsrClientCallServer( (PCSR_API_MSG)&m,
  471. NULL,
  472. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  473. ConsolepGetCurrentFont
  474. ),
  475. sizeof( *a )
  476. );
  477. if (NT_SUCCESS( m.ReturnValue )) {
  478. try {
  479. lpConsoleCurrentFont->dwFontSize = a->FontSize;
  480. lpConsoleCurrentFont->nFont = a->FontIndex;
  481. } except( EXCEPTION_EXECUTE_HANDLER ) {
  482. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  483. return FALSE;
  484. }
  485. return TRUE;
  486. } else {
  487. SET_LAST_NT_ERROR (m.ReturnValue);
  488. return FALSE;
  489. }
  490. }
  491. BOOL
  492. WINAPI
  493. SetConsoleMode(
  494. IN HANDLE hConsoleHandle,
  495. IN DWORD dwMode
  496. )
  497. /*++
  498. Parameters:
  499. hConsoleHandle - Supplies a console input or output handle.
  500. dwMode - Supplies mode.
  501. Input Mode Flags:
  502. ENABLE_LINE_INPUT - line oriented input is on.
  503. ENABLE_ECHO_INPUT - characters will be written to the screen as they are
  504. read.
  505. ENABLE_WINDOW_INPUT - the caller is windows-aware
  506. Output Mode Flags:
  507. ENABLE_LINE_OUTPUT - line oriented output is on.
  508. ENABLE_WRAP_AT_EOL_OUTPUT - the cursor will move to the
  509. beginning of the next line when the end of the row
  510. is reached.
  511. Return Value:
  512. TRUE - The operation was successful.
  513. FALSE/NULL - The operation failed. Extended error status is available
  514. using GetLastError.
  515. --*/
  516. {
  517. CONSOLE_API_MSG m;
  518. PCONSOLE_MODE_MSG a = &m.u.SetConsoleMode;
  519. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  520. a->Handle = hConsoleHandle;
  521. a->Mode = dwMode;
  522. CsrClientCallServer( (PCSR_API_MSG)&m,
  523. NULL,
  524. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  525. ConsolepSetMode
  526. ),
  527. sizeof( *a )
  528. );
  529. if (NT_SUCCESS( m.ReturnValue )) {
  530. return TRUE;
  531. } else {
  532. SET_LAST_NT_ERROR (m.ReturnValue);
  533. return FALSE;
  534. }
  535. }
  536. BOOL
  537. WINAPI
  538. GenerateConsoleCtrlEvent(
  539. IN DWORD dwCtrlEvent,
  540. IN DWORD dwProcessGroupId
  541. )
  542. /*++
  543. Parameters:
  544. dwCtrlEvent - Supplies event(s) to generate.
  545. dwProcessGroupId - Supplies id of process group to generate
  546. event for. Event will be generated in each
  547. process with that id within the console. If 0,
  548. specified event will be generated in all processes
  549. within the console.
  550. Return Value:
  551. TRUE - The operation was successful.
  552. FALSE/NULL - The operation failed. Extended error status is available
  553. using GetLastError.
  554. --*/
  555. {
  556. CONSOLE_API_MSG m;
  557. PCONSOLE_CTRLEVENT_MSG a = &m.u.GenerateConsoleCtrlEvent;
  558. //
  559. // Check for valid Ctrl Events
  560. //
  561. if ((dwCtrlEvent != CTRL_C_EVENT) && (dwCtrlEvent != CTRL_BREAK_EVENT)) {
  562. SET_LAST_ERROR (ERROR_INVALID_PARAMETER);
  563. return(FALSE);
  564. }
  565. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  566. a->CtrlEvent = dwCtrlEvent;
  567. a->ProcessGroupId = dwProcessGroupId;
  568. CsrClientCallServer( (PCSR_API_MSG)&m,
  569. NULL,
  570. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  571. ConsolepGenerateCtrlEvent
  572. ),
  573. sizeof( *a )
  574. );
  575. if (NT_SUCCESS( m.ReturnValue )) {
  576. return TRUE;
  577. } else {
  578. SET_LAST_NT_ERROR (m.ReturnValue);
  579. return FALSE;
  580. }
  581. }
  582. BOOL
  583. WINAPI
  584. SetConsoleActiveScreenBuffer(
  585. IN HANDLE hConsoleOutput
  586. )
  587. /*++
  588. Parameters:
  589. hConsoleOutput - Supplies an open handle to console output. The screen
  590. buffer attached to this handle becomes the displayed screen buffer.
  591. Return Value:
  592. TRUE - The operation was successful.
  593. FALSE/NULL - The operation failed. Extended error status is available
  594. using GetLastError.
  595. --*/
  596. {
  597. CONSOLE_API_MSG m;
  598. PCONSOLE_SETACTIVESCREENBUFFER_MSG a = &m.u.SetConsoleActiveScreenBuffer;
  599. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  600. a->OutputHandle = hConsoleOutput;
  601. CsrClientCallServer( (PCSR_API_MSG)&m,
  602. NULL,
  603. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  604. ConsolepSetActiveScreenBuffer
  605. ),
  606. sizeof( *a )
  607. );
  608. if (NT_SUCCESS( m.ReturnValue )) {
  609. return TRUE;
  610. } else {
  611. SET_LAST_NT_ERROR (m.ReturnValue);
  612. return FALSE;
  613. }
  614. }
  615. BOOL
  616. WINAPI
  617. FlushConsoleInputBuffer(
  618. IN HANDLE hConsoleInput
  619. )
  620. /*++
  621. Parameters:
  622. hConsoleInput - Supplies an open handle to console input.
  623. Return Value:
  624. TRUE - The operation was successful.
  625. FALSE/NULL - The operation failed. Extended error status is available
  626. using GetLastError.
  627. --*/
  628. {
  629. CONSOLE_API_MSG m;
  630. PCONSOLE_FLUSHINPUTBUFFER_MSG a = &m.u.FlushConsoleInputBuffer;
  631. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  632. a->InputHandle = hConsoleInput;
  633. CsrClientCallServer( (PCSR_API_MSG)&m,
  634. NULL,
  635. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  636. ConsolepFlushInputBuffer
  637. ),
  638. sizeof( *a )
  639. );
  640. if (NT_SUCCESS( m.ReturnValue )) {
  641. return TRUE;
  642. } else {
  643. SET_LAST_NT_ERROR (m.ReturnValue);
  644. return FALSE;
  645. }
  646. }
  647. BOOL
  648. WINAPI
  649. SetConsoleScreenBufferSize(
  650. IN HANDLE hConsoleOutput,
  651. IN COORD dwSize
  652. )
  653. /*++
  654. Parameters:
  655. hConsoleInput - Supplies an open handle to console input.
  656. dwSize - New size of screen buffer in rows and columns
  657. Return Value:
  658. TRUE - The operation was successful.
  659. FALSE/NULL - The operation failed. Extended error status is available
  660. using GetLastError.
  661. --*/
  662. {
  663. CONSOLE_API_MSG m;
  664. PCONSOLE_SETSCREENBUFFERSIZE_MSG a = &m.u.SetConsoleScreenBufferSize;
  665. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  666. a->OutputHandle = hConsoleOutput;
  667. a->Size = dwSize;
  668. CsrClientCallServer( (PCSR_API_MSG)&m,
  669. NULL,
  670. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  671. ConsolepSetScreenBufferSize
  672. ),
  673. sizeof( *a )
  674. );
  675. if (NT_SUCCESS( m.ReturnValue )) {
  676. return TRUE;
  677. } else {
  678. SET_LAST_NT_ERROR (m.ReturnValue);
  679. return FALSE;
  680. }
  681. }
  682. BOOL
  683. WINAPI
  684. SetConsoleCursorPosition(
  685. IN HANDLE hConsoleOutput,
  686. IN COORD dwCursorPosition
  687. )
  688. /*++
  689. Parameters:
  690. hConsoleOutput - Supplies an open handle to console output.
  691. dwCursorPosition - Position of cursor in screen buffer
  692. Return Value:
  693. TRUE - The operation was successful.
  694. FALSE/NULL - The operation failed. Extended error status is available
  695. using GetLastError.
  696. --*/
  697. {
  698. CONSOLE_API_MSG m;
  699. PCONSOLE_SETCURSORPOSITION_MSG a = &m.u.SetConsoleCursorPosition;
  700. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  701. a->OutputHandle = hConsoleOutput;
  702. a->CursorPosition = dwCursorPosition;
  703. CsrClientCallServer( (PCSR_API_MSG)&m,
  704. NULL,
  705. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  706. ConsolepSetCursorPosition
  707. ),
  708. sizeof( *a )
  709. );
  710. if (NT_SUCCESS( m.ReturnValue )) {
  711. return TRUE;
  712. } else {
  713. SET_LAST_NT_ERROR (m.ReturnValue);
  714. return FALSE;
  715. }
  716. }
  717. BOOL
  718. WINAPI
  719. SetConsoleCursorInfo(
  720. IN HANDLE hConsoleOutput,
  721. IN CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo
  722. )
  723. /*++
  724. Parameters:
  725. hConsoleOutput - Supplies an open handle to console output.
  726. lpConsoleCursorOrigin - A pointer to a buffer containing the data
  727. to set.
  728. Return Value:
  729. TRUE - The operation was successful.
  730. FALSE/NULL - The operation failed. Extended error status is available
  731. using GetLastError.
  732. --*/
  733. {
  734. CONSOLE_API_MSG m;
  735. PCONSOLE_SETCURSORINFO_MSG a = &m.u.SetConsoleCursorInfo;
  736. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  737. a->OutputHandle = hConsoleOutput;
  738. try {
  739. a->CursorSize = lpConsoleCursorInfo->dwSize;
  740. a->Visible = (BOOLEAN) lpConsoleCursorInfo->bVisible;
  741. } except( EXCEPTION_EXECUTE_HANDLER ) {
  742. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  743. return FALSE;
  744. }
  745. CsrClientCallServer( (PCSR_API_MSG)&m,
  746. NULL,
  747. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  748. ConsolepSetCursorInfo
  749. ),
  750. sizeof( *a )
  751. );
  752. if (NT_SUCCESS( m.ReturnValue )) {
  753. return TRUE;
  754. } else {
  755. SET_LAST_NT_ERROR (m.ReturnValue);
  756. return FALSE;
  757. }
  758. }
  759. BOOL
  760. WINAPI
  761. SetConsoleWindowInfo(
  762. IN HANDLE hConsoleOutput,
  763. IN BOOL bAbsolute,
  764. IN CONST SMALL_RECT *lpConsoleWindow
  765. )
  766. /*++
  767. Parameters:
  768. hConsoleOutput - Supplies an open handle to console output.
  769. lpConsoleWindow - A pointer to a rectangle containing the new
  770. dimensions of the console window in screen buffer coordinates.
  771. Return Value:
  772. TRUE - The operation was successful.
  773. FALSE/NULL - The operation failed. Extended error status is available
  774. using GetLastError.
  775. --*/
  776. {
  777. CONSOLE_API_MSG m;
  778. PCONSOLE_SETWINDOWINFO_MSG a = &m.u.SetConsoleWindowInfo;
  779. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  780. a->OutputHandle = hConsoleOutput;
  781. a->Absolute = bAbsolute;
  782. try {
  783. a->Window = *lpConsoleWindow;
  784. } except( EXCEPTION_EXECUTE_HANDLER ) {
  785. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  786. return FALSE;
  787. }
  788. CsrClientCallServer( (PCSR_API_MSG)&m,
  789. NULL,
  790. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  791. ConsolepSetWindowInfo
  792. ),
  793. sizeof( *a )
  794. );
  795. if (NT_SUCCESS( m.ReturnValue )) {
  796. return TRUE;
  797. } else {
  798. SET_LAST_NT_ERROR (m.ReturnValue);
  799. return FALSE;
  800. }
  801. }
  802. BOOL
  803. APIENTRY
  804. ScrollConsoleScreenBufferInternal(
  805. IN HANDLE hConsoleOutput,
  806. IN CONST SMALL_RECT *lpScrollRectangle,
  807. IN CONST SMALL_RECT *lpClipRectangle,
  808. IN COORD dwDestinationOrigin,
  809. IN CONST CHAR_INFO *lpFill,
  810. IN BOOLEAN Unicode
  811. )
  812. /*++
  813. Parameters:
  814. hConsoleOutput - Supplies an open handle to console output.
  815. lpScrollRectangle - Pointer to region within screen buffer to move.
  816. lpClipRectangle - Pointer to region within screen buffer that may be
  817. affected by this scroll. This pointer may be NULL.
  818. dwDestinationOrigin - Upper left corner of new location of ScrollRectangle
  819. contents.
  820. lpFill - Pointer to structure containing new contents of ScrollRectangle region.
  821. Return Value:
  822. TRUE - The operation was successful.
  823. FALSE/NULL - The operation failed. Extended error status is available
  824. using GetLastError.
  825. --*/
  826. {
  827. CONSOLE_API_MSG m;
  828. PCONSOLE_SCROLLSCREENBUFFER_MSG a = &m.u.ScrollConsoleScreenBuffer;
  829. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  830. a->OutputHandle = hConsoleOutput;
  831. a->Unicode = Unicode;
  832. try {
  833. a->ScrollRectangle = *lpScrollRectangle;
  834. if (lpClipRectangle != NULL) {
  835. a->Clip = TRUE;
  836. a->ClipRectangle = *lpClipRectangle;
  837. }
  838. else {
  839. a->Clip = FALSE;
  840. }
  841. a->Fill = *lpFill;
  842. a->DestinationOrigin = dwDestinationOrigin;
  843. } except( EXCEPTION_EXECUTE_HANDLER ) {
  844. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  845. return FALSE;
  846. }
  847. CsrClientCallServer( (PCSR_API_MSG)&m,
  848. NULL,
  849. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  850. ConsolepScrollScreenBuffer
  851. ),
  852. sizeof( *a )
  853. );
  854. if (NT_SUCCESS( m.ReturnValue )) {
  855. return TRUE;
  856. } else {
  857. SET_LAST_NT_ERROR (m.ReturnValue);
  858. return FALSE;
  859. }
  860. }
  861. #endif //!defined(BUILD_WOW6432)
  862. #if !defined(BUILD_WOW64)
  863. BOOL
  864. APIENTRY
  865. ScrollConsoleScreenBufferA(
  866. HANDLE hConsoleOutput,
  867. CONST SMALL_RECT *lpScrollRectangle,
  868. CONST SMALL_RECT *lpClipRectangle,
  869. COORD dwDestinationOrigin,
  870. CONST CHAR_INFO *lpFill
  871. )
  872. {
  873. return ScrollConsoleScreenBufferInternal(hConsoleOutput,
  874. lpScrollRectangle,
  875. lpClipRectangle,
  876. dwDestinationOrigin,
  877. lpFill,
  878. FALSE);
  879. }
  880. BOOL
  881. APIENTRY
  882. ScrollConsoleScreenBufferW(
  883. HANDLE hConsoleOutput,
  884. CONST SMALL_RECT *lpScrollRectangle,
  885. CONST SMALL_RECT *lpClipRectangle,
  886. COORD dwDestinationOrigin,
  887. CONST CHAR_INFO *lpFill
  888. )
  889. {
  890. return ScrollConsoleScreenBufferInternal(hConsoleOutput,
  891. lpScrollRectangle,
  892. lpClipRectangle,
  893. dwDestinationOrigin,
  894. lpFill,
  895. TRUE);
  896. }
  897. #endif //!defined(BUILD_WOW64)
  898. #if !defined(BUILD_WOW6432)
  899. BOOL
  900. WINAPI
  901. SetConsoleTextAttribute(
  902. IN HANDLE hConsoleOutput,
  903. IN WORD wAttributes
  904. )
  905. /*++
  906. Parameters:
  907. hConsoleOutput - Supplies an open handle to console output.
  908. wAttributes - Character display attributes.
  909. Return Value:
  910. TRUE - The operation was successful.
  911. FALSE/NULL - The operation failed. Extended error status is available
  912. using GetLastError.
  913. --*/
  914. {
  915. CONSOLE_API_MSG m;
  916. PCONSOLE_SETTEXTATTRIBUTE_MSG a = &m.u.SetConsoleTextAttribute;
  917. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  918. a->OutputHandle = hConsoleOutput;
  919. a->Attributes = wAttributes;
  920. CsrClientCallServer( (PCSR_API_MSG)&m,
  921. NULL,
  922. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  923. ConsolepSetTextAttribute
  924. ),
  925. sizeof( *a )
  926. );
  927. if (NT_SUCCESS( m.ReturnValue )) {
  928. return TRUE;
  929. } else {
  930. SET_LAST_NT_ERROR (m.ReturnValue);
  931. return FALSE;
  932. }
  933. }
  934. BOOL
  935. WINAPI
  936. SetConsoleFont(
  937. IN HANDLE hConsoleOutput,
  938. IN DWORD nFont
  939. )
  940. /*++
  941. Parameters:
  942. hConsoleOutput - Supplies an open handle to console output.
  943. nFont - Number of font to set as current font
  944. Return Value:
  945. TRUE - The operation was successful.
  946. FALSE/NULL - The operation failed. Extended error status is available
  947. using GetLastError.
  948. --*/
  949. {
  950. CONSOLE_API_MSG m;
  951. PCONSOLE_SETFONT_MSG a = &m.u.SetConsoleFont;
  952. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  953. a->OutputHandle = hConsoleOutput;
  954. a->FontIndex = nFont;
  955. CsrClientCallServer( (PCSR_API_MSG)&m,
  956. NULL,
  957. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  958. ConsolepSetFont
  959. ),
  960. sizeof( *a )
  961. );
  962. if (NT_SUCCESS( m.ReturnValue )) {
  963. return TRUE;
  964. } else {
  965. SET_LAST_NT_ERROR (m.ReturnValue);
  966. return FALSE;
  967. }
  968. }
  969. BOOL
  970. WINAPI
  971. SetConsoleIcon(
  972. IN HICON hIcon
  973. )
  974. /*++
  975. Parameters:
  976. hIcon - Supplies an icon handle.
  977. Return Value:
  978. TRUE - The operation was successful.
  979. FALSE/NULL - The operation failed. Extended error status is available
  980. using GetLastError.
  981. --*/
  982. {
  983. CONSOLE_API_MSG m;
  984. PCONSOLE_SETICON_MSG a = &m.u.SetConsoleIcon;
  985. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  986. a->hIcon = hIcon;
  987. CsrClientCallServer( (PCSR_API_MSG)&m,
  988. NULL,
  989. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  990. ConsolepSetIcon
  991. ),
  992. sizeof( *a )
  993. );
  994. if (NT_SUCCESS( m.ReturnValue )) {
  995. return TRUE;
  996. } else {
  997. SET_LAST_NT_ERROR (m.ReturnValue);
  998. return FALSE;
  999. }
  1000. }
  1001. #endif //!defined(BUILD_WOW6432)
  1002. #if !defined(BUILD_WOW64)
  1003. BOOL
  1004. APIENTRY
  1005. SetConsoleMaximumWindowSize(
  1006. HANDLE hConsoleOutput,
  1007. COORD dwWindowSize
  1008. )
  1009. {
  1010. UNREFERENCED_PARAMETER(hConsoleOutput);
  1011. UNREFERENCED_PARAMETER(dwWindowSize);
  1012. return TRUE;
  1013. }
  1014. #endif //!defined(BUILD_WOW64)
  1015. #if !defined(BUILD_WOW6432)
  1016. UINT
  1017. WINAPI
  1018. GetConsoleCP( VOID )
  1019. /**++
  1020. Parameters:
  1021. none
  1022. Return Value:
  1023. The code page id of the current console. a null return value
  1024. indicates failure.
  1025. --*/
  1026. {
  1027. CONSOLE_API_MSG m;
  1028. PCONSOLE_GETCP_MSG a = &m.u.GetConsoleCP;
  1029. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1030. a->Output = FALSE;
  1031. CsrClientCallServer( (PCSR_API_MSG)&m,
  1032. NULL,
  1033. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1034. ConsolepGetCP
  1035. ),
  1036. sizeof( *a )
  1037. );
  1038. if (NT_SUCCESS( m.ReturnValue )) {
  1039. return a->wCodePageID;
  1040. } else {
  1041. SET_LAST_NT_ERROR (m.ReturnValue);
  1042. return FALSE;
  1043. }
  1044. }
  1045. BOOL
  1046. WINAPI
  1047. SetConsoleCP(
  1048. IN UINT wCodePageID
  1049. )
  1050. /**++
  1051. Parameters:
  1052. wCodePageID - the code page is to set for the current console.
  1053. Return Value:
  1054. TRUE - The operation was successful.
  1055. FALSE/NULL - The operation failed. Extended error status is available
  1056. using GetLastError.
  1057. --*/
  1058. {
  1059. CONSOLE_API_MSG m;
  1060. PCONSOLE_SETCP_MSG a = &m.u.SetConsoleCP;
  1061. NTSTATUS Status;
  1062. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1063. a->Output = FALSE;
  1064. a->wCodePageID = wCodePageID;
  1065. #if defined(FE_SB)
  1066. Status = NtCreateEvent(&(a->hEvent),
  1067. EVENT_ALL_ACCESS,
  1068. NULL,
  1069. SynchronizationEvent,
  1070. (BOOLEAN)FALSE
  1071. );
  1072. if (!NT_SUCCESS(Status)) {
  1073. SET_LAST_NT_ERROR(Status);
  1074. return FALSE;
  1075. }
  1076. #endif
  1077. CsrClientCallServer( (PCSR_API_MSG)&m,
  1078. NULL,
  1079. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1080. ConsolepSetCP
  1081. ),
  1082. sizeof( *a )
  1083. );
  1084. if (NT_SUCCESS( m.ReturnValue )) {
  1085. #if defined(FE_SB)
  1086. NTSTATUS Status;
  1087. Status = NtWaitForSingleObject(a->hEvent, FALSE, NULL);
  1088. NtClose(a->hEvent);
  1089. if (Status != 0) {
  1090. SET_LAST_NT_ERROR(Status);
  1091. return FALSE;
  1092. }
  1093. #endif
  1094. return TRUE;
  1095. } else {
  1096. #if defined(FE_SB)
  1097. NtClose(a->hEvent);
  1098. #endif
  1099. SET_LAST_NT_ERROR (m.ReturnValue);
  1100. return FALSE;
  1101. }
  1102. }
  1103. UINT
  1104. WINAPI
  1105. GetConsoleOutputCP( VOID )
  1106. /**++
  1107. Parameters:
  1108. none
  1109. Return Value:
  1110. The code page id of the current console output. a null return value
  1111. indicates failure.
  1112. --*/
  1113. {
  1114. CONSOLE_API_MSG m;
  1115. PCONSOLE_GETCP_MSG a = &m.u.GetConsoleCP;
  1116. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1117. a->Output = TRUE;
  1118. CsrClientCallServer( (PCSR_API_MSG)&m,
  1119. NULL,
  1120. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1121. ConsolepGetCP
  1122. ),
  1123. sizeof( *a )
  1124. );
  1125. if (NT_SUCCESS( m.ReturnValue )) {
  1126. return a->wCodePageID;
  1127. } else {
  1128. SET_LAST_NT_ERROR (m.ReturnValue);
  1129. return FALSE;
  1130. }
  1131. }
  1132. NTSTATUS
  1133. APIENTRY
  1134. SetConsoleOutputCPInternal(
  1135. IN UINT wCodePageID
  1136. )
  1137. {
  1138. CONSOLE_API_MSG m;
  1139. PCONSOLE_SETCP_MSG a = &m.u.SetConsoleCP;
  1140. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1141. a->Output = TRUE;
  1142. a->wCodePageID = wCodePageID;
  1143. #if defined(FE_SB)
  1144. a->hEvent = NULL;
  1145. #endif
  1146. CsrClientCallServer( (PCSR_API_MSG)&m,
  1147. NULL,
  1148. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1149. ConsolepSetCP
  1150. ),
  1151. sizeof( *a )
  1152. );
  1153. return m.ReturnValue;
  1154. }
  1155. #endif //!defined(BUILD_WOW6432)
  1156. #if !defined(BUILD_WOW64)
  1157. BOOL
  1158. WINAPI
  1159. SetConsoleOutputCP(
  1160. IN UINT wCodePageID
  1161. )
  1162. /**++
  1163. Parameters:
  1164. wCodePageID - the code page is to set for the current console output.
  1165. Return Value:
  1166. TRUE - The operation was successful.
  1167. FALSE/NULL - The operation failed. Extended error status is available
  1168. using GetLastError.
  1169. --*/
  1170. {
  1171. NTSTATUS Status;
  1172. Status = SetConsoleOutputCPInternal(wCodePageID);
  1173. if(NT_SUCCESS(Status)) {
  1174. SetTEBLangID();
  1175. return TRUE;
  1176. }
  1177. else {
  1178. SET_LAST_NT_ERROR (Status);
  1179. return FALSE;
  1180. }
  1181. }
  1182. #endif //!defined(BUILD_WOW64)
  1183. #if !defined(BUILD_WOW6432)
  1184. BOOL
  1185. APIENTRY
  1186. GetConsoleKeyboardLayoutNameWorker(
  1187. OUT LPSTR pszLayout,
  1188. IN BOOL bAnsi)
  1189. /**++
  1190. Parameters:
  1191. pszLayout - address of buffer of least 9 characters
  1192. bAnsi - TRUE want ANSI (8-bit) chars
  1193. FALSE want Unicode (16-bit) chars
  1194. Return Value:
  1195. TRUE - success
  1196. FALSE - failure
  1197. --*/
  1198. {
  1199. CONSOLE_API_MSG m;
  1200. PCONSOLE_GETKEYBOARDLAYOUTNAME_MSG a = &m.u.GetKeyboardLayoutName;
  1201. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1202. a->bAnsi = bAnsi;
  1203. CsrClientCallServer( (PCSR_API_MSG)&m,
  1204. NULL,
  1205. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1206. ConsolepGetKeyboardLayoutName
  1207. ),
  1208. sizeof( *a )
  1209. );
  1210. if (NT_SUCCESS( m.ReturnValue )) {
  1211. if (bAnsi) {
  1212. strncpy(pszLayout, a->achLayout, 9);
  1213. } else {
  1214. wcsncpy((LPWSTR)pszLayout, a->awchLayout, 9);
  1215. }
  1216. return TRUE;
  1217. } else {
  1218. SET_LAST_NT_ERROR (m.ReturnValue);
  1219. return FALSE;
  1220. }
  1221. }
  1222. #endif //!defined(BUILD_WOW6432)
  1223. #if !defined(BUILD_WOW64)
  1224. BOOL
  1225. GetConsoleKeyboardLayoutNameA(
  1226. LPSTR pszLayout)
  1227. {
  1228. return GetConsoleKeyboardLayoutNameWorker(pszLayout, TRUE);
  1229. }
  1230. BOOL
  1231. GetConsoleKeyboardLayoutNameW(
  1232. LPWSTR pwszLayout)
  1233. {
  1234. return GetConsoleKeyboardLayoutNameWorker((LPSTR)pwszLayout, FALSE);
  1235. }
  1236. #endif // !defined(BUILD_WOW64)
  1237. #if !defined(BUILD_WOW6432)
  1238. HWND
  1239. APIENTRY
  1240. GetConsoleWindow(
  1241. VOID)
  1242. {
  1243. CONSOLE_API_MSG m;
  1244. PCONSOLE_GETCONSOLEWINDOW_MSG a = &m.u.GetConsoleWindow;
  1245. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1246. CsrClientCallServer( (PCSR_API_MSG)&m,
  1247. NULL,
  1248. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1249. ConsolepGetConsoleWindow
  1250. ),
  1251. sizeof( *a )
  1252. );
  1253. if (NT_SUCCESS( m.ReturnValue )) {
  1254. return a->hwnd;
  1255. } else {
  1256. SET_LAST_NT_ERROR (m.ReturnValue);
  1257. return NULL;
  1258. }
  1259. }
  1260. DWORD
  1261. APIENTRY
  1262. GetConsoleProcessList(
  1263. OUT LPDWORD lpdwProcessList,
  1264. IN DWORD dwProcessCount)
  1265. {
  1266. CONSOLE_API_MSG m;
  1267. PCONSOLE_GETCONSOLEPROCESSLIST_MSG a = &m.u.GetConsoleProcessList;
  1268. PCSR_CAPTURE_HEADER CaptureBuffer;
  1269. if (dwProcessCount == 0 || lpdwProcessList == NULL) {
  1270. SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
  1271. return 0;
  1272. }
  1273. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  1274. a->dwProcessCount = dwProcessCount;
  1275. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  1276. dwProcessCount * sizeof(DWORD)
  1277. );
  1278. if (CaptureBuffer == NULL) {
  1279. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  1280. return 0;
  1281. }
  1282. CsrCaptureMessageBuffer( CaptureBuffer,
  1283. NULL,
  1284. dwProcessCount * sizeof(DWORD),
  1285. (PVOID *) &a->lpdwProcessList
  1286. );
  1287. CsrClientCallServer( (PCSR_API_MSG)&m,
  1288. CaptureBuffer,
  1289. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  1290. ConsolepGetConsoleProcessList
  1291. ),
  1292. sizeof( *a )
  1293. );
  1294. if (NT_SUCCESS(m.ReturnValue)) {
  1295. if (dwProcessCount >= a->dwProcessCount) {
  1296. try {
  1297. RtlCopyMemory(lpdwProcessList, a->lpdwProcessList, a->dwProcessCount * sizeof(DWORD));
  1298. } except( EXCEPTION_EXECUTE_HANDLER ) {
  1299. CsrFreeCaptureBuffer( CaptureBuffer );
  1300. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  1301. return 0;
  1302. }
  1303. }
  1304. } else {
  1305. CsrFreeCaptureBuffer( CaptureBuffer );
  1306. SET_LAST_NT_ERROR (m.ReturnValue);
  1307. return 0;
  1308. }
  1309. CsrFreeCaptureBuffer( CaptureBuffer );
  1310. return a->dwProcessCount;
  1311. }
  1312. #endif // !defined(BUILD_WOW6432)