Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

iostubs.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1985 - 1999, Microsoft Corporation 00004 00005 Module Name: 00006 00007 iostubs.c 00008 00009 Abstract: 00010 00011 This module contains the stubs for the console I/O API. 00012 00013 Author: 00014 00015 Therese Stowell (thereses) 14-Nov-1990 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #include "precomp.h" 00022 #pragma hdrstop 00023 #pragma hdrstop 00024 00025 #if !defined(BUILD_WOW6432) 00026 00027 BOOL 00028 APIENTRY 00029 GetConsoleInput( 00030 IN HANDLE hConsoleInput, 00031 OUT PINPUT_RECORD lpBuffer, 00032 IN DWORD nLength, 00033 OUT LPDWORD lpNumberOfEventsRead, 00034 IN USHORT wFlags, 00035 IN BOOLEAN Unicode 00036 ) 00037 00038 /*++ 00039 00040 Parameters: 00041 00042 hConsoleInput - Supplies an open handle to CONIN$ that is to be 00043 read. The handle must have been created with GENERIC_READ access. 00044 00045 lpBuffer - Supplies the address of a buffer to receive the data read 00046 from the input buffer. 00047 00048 nLength - Supplies the length of lpBuffer in INPUT_RECORDs. 00049 00050 lpNumberOfEventsRead - Pointer to number of events read. 00051 00052 wFlags - Flags that control how data is read. 00053 00054 Return Value: 00055 00056 TRUE - The operation was successful. 00057 00058 FALSE/NULL - The operation failed. 00059 Extended error status is available using GetLastError. 00060 00061 --*/ 00062 00063 { 00064 PCSR_CAPTURE_HEADER CaptureBuffer; 00065 CONSOLE_API_MSG m; 00066 PCONSOLE_GETCONSOLEINPUT_MSG a = &m.u.GetConsoleInput; 00067 00068 // 00069 // If it's not a well formed handle, don't bother going to the server. 00070 // 00071 00072 if (!CONSOLE_HANDLE(hConsoleInput)) { 00073 try { 00074 *lpNumberOfEventsRead = 0; 00075 SET_LAST_ERROR(ERROR_INVALID_HANDLE); 00076 } except( EXCEPTION_EXECUTE_HANDLER ) { 00077 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00078 } 00079 return FALSE; 00080 } 00081 00082 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00083 a->InputHandle = hConsoleInput; 00084 a->NumRecords = nLength; 00085 a->Flags = wFlags; 00086 a->Unicode = Unicode; 00087 00088 // 00089 // for speed in the case where we're only reading a few records, we have 00090 // a buffer in the msg we pass to the server. this means we don't have to 00091 // allocate a capture buffer. 00092 // 00093 00094 if (nLength > INPUT_RECORD_BUFFER_SIZE) { 00095 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00096 nLength * sizeof(INPUT_RECORD) 00097 ); 00098 if (CaptureBuffer == NULL) { 00099 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00100 return FALSE; 00101 } 00102 CsrCaptureMessageBuffer( CaptureBuffer, 00103 NULL, 00104 nLength * sizeof(INPUT_RECORD), 00105 (PVOID *) &a->BufPtr 00106 ); 00107 00108 } else { 00109 a->BufPtr = a->Record; 00110 CaptureBuffer = NULL; 00111 } 00112 CsrClientCallServer( (PCSR_API_MSG)&m, 00113 CaptureBuffer, 00114 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00115 ConsolepGetConsoleInput 00116 ), 00117 sizeof( *a ) 00118 ); 00119 00120 try { 00121 if (NT_SUCCESS( m.ReturnValue )) { 00122 *lpNumberOfEventsRead = a->NumRecords; 00123 RtlCopyMemory(lpBuffer, a->BufPtr, a->NumRecords * sizeof(INPUT_RECORD)); 00124 } 00125 else { 00126 *lpNumberOfEventsRead = 0; 00127 SET_LAST_NT_ERROR(m.ReturnValue); 00128 } 00129 } except( EXCEPTION_EXECUTE_HANDLER ) { 00130 if (CaptureBuffer != NULL) { 00131 CsrFreeCaptureBuffer( CaptureBuffer ); 00132 } 00133 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00134 return FALSE; 00135 } 00136 if (CaptureBuffer != NULL) { 00137 CsrFreeCaptureBuffer( CaptureBuffer ); 00138 } 00139 00140 return NT_SUCCESS(m.ReturnValue); 00141 00142 } 00143 00144 #endif 00145 00146 #if !defined(BUILD_WOW64) 00147 00148 BOOL 00149 APIENTRY 00150 PeekConsoleInputA( 00151 HANDLE hConsoleInput, 00152 PINPUT_RECORD lpBuffer, 00153 DWORD nLength, 00154 LPDWORD lpNumberOfEventsRead 00155 ) 00156 00157 { 00158 return GetConsoleInput(hConsoleInput, 00159 lpBuffer, 00160 nLength, 00161 lpNumberOfEventsRead, 00162 CONSOLE_READ_NOREMOVE | CONSOLE_READ_NOWAIT, 00163 FALSE); 00164 } 00165 00166 BOOL 00167 APIENTRY 00168 PeekConsoleInputW( 00169 HANDLE hConsoleInput, 00170 PINPUT_RECORD lpBuffer, 00171 DWORD nLength, 00172 LPDWORD lpNumberOfEventsRead 00173 ) 00174 00175 /*++ 00176 00177 Parameters: 00178 00179 hConsoleInput - Supplies an open handle to CONIN$ that is to be 00180 read. The handle must have been created with GENERIC_READ access. 00181 00182 lpBuffer - Supplies the address of a buffer to receive the data read 00183 from the input buffer. 00184 00185 nLength - Supplies the length of lpBuffer in INPUT_RECORDs. 00186 00187 lpNumberOfEventsRead - Pointer to number of events read. 00188 00189 Return Value: 00190 00191 TRUE - The operation was successful. 00192 00193 FALSE/NULL - The operation failed. 00194 Extended error status is available using GetLastError. 00195 00196 --*/ 00197 00198 { 00199 return GetConsoleInput(hConsoleInput, 00200 lpBuffer, 00201 nLength, 00202 lpNumberOfEventsRead, 00203 CONSOLE_READ_NOREMOVE | CONSOLE_READ_NOWAIT, 00204 TRUE); 00205 } 00206 00207 BOOL 00208 APIENTRY 00209 ReadConsoleInputA( 00210 HANDLE hConsoleInput, 00211 PINPUT_RECORD lpBuffer, 00212 DWORD nLength, 00213 LPDWORD lpNumberOfEventsRead 00214 ) 00215 00216 { 00217 return GetConsoleInput(hConsoleInput, 00218 lpBuffer, 00219 nLength, 00220 lpNumberOfEventsRead, 00221 0, 00222 FALSE); 00223 } 00224 00225 BOOL 00226 APIENTRY 00227 ReadConsoleInputW( 00228 HANDLE hConsoleInput, 00229 PINPUT_RECORD lpBuffer, 00230 DWORD nLength, 00231 LPDWORD lpNumberOfEventsRead 00232 ) 00233 00234 /*++ 00235 00236 Parameters: 00237 00238 hConsoleInput - Supplies an open handle to CONIN$ that is to be 00239 read. The handle must have been created with GENERIC_READ access. 00240 00241 lpBuffer - Supplies the address of a buffer to receive the data read 00242 from the input buffer. 00243 00244 nLength - Supplies the length of lpBuffer in INPUT_RECORDs. 00245 00246 lpNumberOfEventsRead - Pointer to number of events read. 00247 00248 Return Value: 00249 00250 TRUE - The operation was successful. 00251 00252 FALSE/NULL - The operation failed. 00253 Extended error status is available using GetLastError. 00254 00255 --*/ 00256 00257 { 00258 return GetConsoleInput(hConsoleInput, 00259 lpBuffer, 00260 nLength, 00261 lpNumberOfEventsRead, 00262 0, 00263 TRUE); 00264 } 00265 00266 BOOL 00267 APIENTRY 00268 ReadConsoleInputExA( 00269 HANDLE hConsoleInput, 00270 PINPUT_RECORD lpBuffer, 00271 DWORD nLength, 00272 LPDWORD lpNumberOfEventsRead, 00273 USHORT wFlags 00274 ) 00275 00276 { 00277 return GetConsoleInput(hConsoleInput, 00278 lpBuffer, 00279 nLength, 00280 lpNumberOfEventsRead, 00281 wFlags, 00282 FALSE); 00283 } 00284 00285 BOOL 00286 APIENTRY 00287 ReadConsoleInputExW( 00288 HANDLE hConsoleInput, 00289 PINPUT_RECORD lpBuffer, 00290 DWORD nLength, 00291 LPDWORD lpNumberOfEventsRead, 00292 USHORT wFlags 00293 ) 00294 00295 /*++ 00296 00297 Parameters: 00298 00299 hConsoleInput - Supplies an open handle to CONIN$ that is to be 00300 read. The handle must have been created with GENERIC_READ access. 00301 00302 lpBuffer - Supplies the address of a buffer to receive the data read 00303 from the input buffer. 00304 00305 nLength - Supplies the length of lpBuffer in INPUT_RECORDs. 00306 00307 lpNumberOfEventsRead - Pointer to number of events read. 00308 00309 wFlags - Flags that control how data is read. 00310 00311 Return Value: 00312 00313 TRUE - The operation was successful. 00314 00315 FALSE/NULL - The operation failed. 00316 Extended error status is available using GetLastError. 00317 00318 --*/ 00319 00320 { 00321 return GetConsoleInput(hConsoleInput, 00322 lpBuffer, 00323 nLength, 00324 lpNumberOfEventsRead, 00325 wFlags, 00326 TRUE); 00327 } 00328 00329 #endif 00330 00331 #if !defined(BUILD_WOW6432) 00332 00333 BOOL 00334 APIENTRY 00335 WriteConsoleInputInternal( 00336 IN HANDLE hConsoleInput, 00337 IN CONST INPUT_RECORD *lpBuffer, 00338 IN DWORD nLength, 00339 OUT LPDWORD lpNumberOfEventsWritten, 00340 IN BOOLEAN Unicode, 00341 IN BOOLEAN Append 00342 ) 00343 00344 /*++ 00345 Parameters: 00346 00347 hConsoleInput - Supplies an open handle to CONIN$ that is to be 00348 written. The handle must have been created with GENERIC_WRITE access. 00349 00350 lpBuffer - Supplies the address of a buffer containing the input records 00351 to write to the input buffer. 00352 00353 nLength - Supplies the length of lpBuffer in INPUT_RECORDs. 00354 00355 lpNumberOfEventsWritten - Pointer to number of events written. 00356 00357 Unicode - TRUE if characters are unicode 00358 00359 Append - TRUE if append to end of input stream. if FALSE, write to the 00360 beginning of the input stream (used by VDM). 00361 00362 Return Value: 00363 00364 TRUE - The operation was successful. 00365 00366 FALSE/NULL - The operation failed. 00367 Extended error status is available using GetLastError. 00368 00369 --*/ 00370 00371 { 00372 PCSR_CAPTURE_HEADER CaptureBuffer; 00373 CONSOLE_API_MSG m; 00374 PCONSOLE_WRITECONSOLEINPUT_MSG a = &m.u.WriteConsoleInput; 00375 00376 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00377 a->InputHandle = hConsoleInput; 00378 a->NumRecords = nLength; 00379 a->Unicode = Unicode; 00380 a->Append = Append; 00381 00382 // 00383 // for speed in the case where we're only writing a few records, we have 00384 // a buffer in the msg we pass to the server. this means we don't have to 00385 // allocate a capture buffer. 00386 // 00387 00388 if (nLength > INPUT_RECORD_BUFFER_SIZE) { 00389 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00390 nLength * sizeof(INPUT_RECORD) 00391 ); 00392 if (CaptureBuffer == NULL) { 00393 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00394 return FALSE; 00395 } 00396 CsrCaptureMessageBuffer( CaptureBuffer, 00397 (PCHAR) lpBuffer, 00398 nLength * sizeof(INPUT_RECORD), 00399 (PVOID *) &a->BufPtr 00400 ); 00401 00402 } else { 00403 a->BufPtr = a->Record; 00404 CaptureBuffer = NULL; 00405 try { 00406 RtlCopyMemory(a->BufPtr, lpBuffer, nLength * sizeof(INPUT_RECORD)); 00407 } except( EXCEPTION_EXECUTE_HANDLER ) { 00408 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00409 return FALSE; 00410 } 00411 } 00412 CsrClientCallServer( (PCSR_API_MSG)&m, 00413 CaptureBuffer, 00414 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00415 ConsolepWriteConsoleInput 00416 ), 00417 sizeof( *a ) 00418 ); 00419 if (CaptureBuffer != NULL) { 00420 CsrFreeCaptureBuffer( CaptureBuffer ); 00421 } 00422 try { 00423 *lpNumberOfEventsWritten = a->NumRecords; 00424 } except( EXCEPTION_EXECUTE_HANDLER ) { 00425 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00426 return FALSE; 00427 } 00428 if (!NT_SUCCESS(m.ReturnValue)) { 00429 SET_LAST_NT_ERROR(m.ReturnValue); 00430 return FALSE; 00431 } 00432 else { 00433 return TRUE; 00434 } 00435 00436 } 00437 00438 #endif 00439 00440 #if !defined(BUILD_WOW64) 00441 00442 BOOL 00443 APIENTRY 00444 WriteConsoleInputA( 00445 HANDLE hConsoleInput, 00446 CONST INPUT_RECORD *lpBuffer, 00447 DWORD nLength, 00448 LPDWORD lpNumberOfEventsWritten 00449 ) 00450 { 00451 return WriteConsoleInputInternal(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten,FALSE,TRUE); 00452 } 00453 00454 BOOL 00455 APIENTRY 00456 WriteConsoleInputW( 00457 HANDLE hConsoleInput, 00458 CONST INPUT_RECORD *lpBuffer, 00459 DWORD nLength, 00460 LPDWORD lpNumberOfEventsWritten 00461 ) 00462 { 00463 return WriteConsoleInputInternal(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten,TRUE,TRUE); 00464 } 00465 00466 00467 #endif 00468 00469 #if !defined(BUILD_WOW6432) 00470 00471 VOID 00472 CopyRectangle( 00473 IN CONST CHAR_INFO *Source, 00474 IN COORD SourceSize, 00475 IN PSMALL_RECT SourceRect, 00476 OUT PCHAR_INFO Target, 00477 IN COORD TargetSize, 00478 IN COORD TargetPoint 00479 ) 00480 00481 /*++ 00482 00483 Routine Description: 00484 00485 This routine copies a rectangular region, doing any necessary clipping. 00486 00487 Arguments: 00488 00489 Source - pointer to source buffer 00490 00491 SourceSize - dimensions of source buffer 00492 00493 SourceRect - rectangle in source buffer to copy 00494 00495 Target - pointer to target buffer 00496 00497 TargetSize - dimensions of target buffer 00498 00499 TargetPoint - upper left coordinates of target rectangle 00500 00501 Return Value: 00502 00503 00504 --*/ 00505 00506 { 00507 00508 #define SCREEN_BUFFER_POINTER(BASE,X,Y,XSIZE,CELLSIZE) ((ULONG_PTR)BASE + ((XSIZE * (Y)) + (X)) * (ULONG)CELLSIZE) 00509 00510 CONST CHAR_INFO *SourcePtr; 00511 PCHAR_INFO TargetPtr; 00512 SHORT i,j; 00513 SHORT XSize,YSize; 00514 BOOLEAN WholeSource,WholeTarget; 00515 00516 XSize = (SHORT)CONSOLE_RECT_SIZE_X(SourceRect); 00517 YSize = (SHORT)CONSOLE_RECT_SIZE_Y(SourceRect); 00518 00519 // do clipping. we only clip for target, not source. 00520 00521 if (XSize > (SHORT)(TargetSize.X - TargetPoint.X + 1)) { 00522 XSize = (SHORT)(TargetSize.X - TargetPoint.X + 1); 00523 } 00524 if (YSize > (SHORT)(TargetSize.Y - TargetPoint.Y + 1)) { 00525 YSize = (SHORT)(TargetSize.Y - TargetPoint.Y + 1); 00526 } 00527 00528 WholeSource = WholeTarget = FALSE; 00529 if (XSize == SourceSize.X) { 00530 ASSERT (SourceRect->Left == 0); 00531 if (SourceRect->Top == 0) { 00532 SourcePtr = Source; 00533 } 00534 else { 00535 SourcePtr = (PCHAR_INFO) SCREEN_BUFFER_POINTER(Source, 00536 SourceRect->Left, 00537 SourceRect->Top, 00538 SourceSize.X, 00539 sizeof(CHAR_INFO)); 00540 } 00541 WholeSource = TRUE; 00542 } 00543 if (XSize == TargetSize.X) { 00544 ASSERT (TargetPoint.X == 0); 00545 if (TargetPoint.Y == 0) { 00546 TargetPtr = Target; 00547 } 00548 else { 00549 TargetPtr = (PCHAR_INFO) SCREEN_BUFFER_POINTER(Target, 00550 TargetPoint.X, 00551 TargetPoint.Y, 00552 TargetSize.X, 00553 sizeof(CHAR_INFO)); 00554 } 00555 WholeTarget = TRUE; 00556 } 00557 if (WholeSource && WholeTarget) { 00558 memmove(TargetPtr,SourcePtr,XSize*YSize*sizeof(CHAR_INFO)); 00559 return; 00560 } 00561 00562 for (i=0;i<YSize;i++) { 00563 if (!WholeTarget) { 00564 TargetPtr = (PCHAR_INFO) SCREEN_BUFFER_POINTER(Target, 00565 TargetPoint.X, 00566 TargetPoint.Y+i, 00567 TargetSize.X, 00568 sizeof(CHAR_INFO)); 00569 } 00570 if (!WholeSource) { 00571 SourcePtr = (PCHAR_INFO) SCREEN_BUFFER_POINTER(Source, 00572 SourceRect->Left, 00573 SourceRect->Top+i, 00574 SourceSize.X, 00575 sizeof(CHAR_INFO)); 00576 } 00577 for (j=0;j<XSize;j++,SourcePtr++,TargetPtr++) { 00578 *TargetPtr = *SourcePtr; 00579 } 00580 } 00581 } 00582 00583 BOOL 00584 APIENTRY 00585 ReadConsoleOutputInternal( 00586 IN HANDLE hConsoleOutput, 00587 OUT PCHAR_INFO lpBuffer, 00588 IN COORD dwBufferSize, 00589 IN COORD dwBufferCoord, 00590 IN OUT PSMALL_RECT lpReadRegion, 00591 IN BOOLEAN Unicode 00592 ) 00593 00594 /*++ 00595 Parameters: 00596 00597 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 00598 that is to be read. The handle must have been created with 00599 GENERIC_READ access. 00600 00601 lpBuffer - Supplies the address of a buffer to receive the data read 00602 from the screen buffer. This pointer is treated as the origin of 00603 a two dimensional array of size dwBufferSize. 00604 00605 dwBufferSize - size of lpBuffer 00606 00607 dwBufferCoord - coordinates of upper left point in buffer to receive 00608 read data. 00609 00610 lpReadRegion - Supplies on input the address of a structure indicating the 00611 rectangle within the screen buffer to read from. The fields in 00612 the structure are column and row coordinates. On output, the fields 00613 contain the actual region read. 00614 00615 Return Value: 00616 00617 TRUE - The operation was successful. 00618 00619 FALSE/NULL - The operation failed. Extended error status is available 00620 using GetLastError. 00621 --*/ 00622 00623 { 00624 PCSR_CAPTURE_HEADER CaptureBuffer; 00625 CONSOLE_API_MSG m; 00626 PCONSOLE_READCONSOLEOUTPUT_MSG a = &m.u.ReadConsoleOutput; 00627 ULONG NumChars; 00628 COORD SourceSize; 00629 00630 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00631 a->OutputHandle = hConsoleOutput; 00632 a->Unicode = Unicode; 00633 00634 // 00635 // clip region to read based on caller's buffer size 00636 // 00637 00638 SourceSize.X = (SHORT)CONSOLE_RECT_SIZE_X(lpReadRegion); 00639 if (SourceSize.X > dwBufferSize.X-dwBufferCoord.X) 00640 SourceSize.X = dwBufferSize.X-dwBufferCoord.X; 00641 SourceSize.Y = (SHORT)CONSOLE_RECT_SIZE_Y(lpReadRegion); 00642 if (SourceSize.Y > dwBufferSize.Y-dwBufferCoord.Y) 00643 SourceSize.Y = dwBufferSize.Y-dwBufferCoord.Y; 00644 00645 a->CharRegion.Left = lpReadRegion->Left; 00646 a->CharRegion.Right = (SHORT)(lpReadRegion->Left + SourceSize.X - 1); 00647 a->CharRegion.Top = lpReadRegion->Top; 00648 a->CharRegion.Bottom = (SHORT)(lpReadRegion->Top + SourceSize.Y - 1); 00649 00650 // 00651 // for speed in the case where we're only reading one character, we have 00652 // a buffer in the msg we pass to the server. this means we don't have to 00653 // allocate a capture buffer. 00654 // 00655 00656 NumChars = SourceSize.X * SourceSize.Y; 00657 if (NumChars > 1) { 00658 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00659 NumChars * sizeof(CHAR_INFO) 00660 ); 00661 if (CaptureBuffer == NULL) { 00662 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00663 return FALSE; 00664 } 00665 CsrCaptureMessageBuffer( CaptureBuffer, 00666 NULL, 00667 NumChars * sizeof(CHAR_INFO), 00668 (PVOID *) &a->BufPtr 00669 ); 00670 } 00671 else { 00672 CaptureBuffer = NULL; 00673 a->BufPtr = &a->Char; 00674 } 00675 CsrClientCallServer( (PCSR_API_MSG)&m, 00676 CaptureBuffer, 00677 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00678 ConsolepReadConsoleOutput 00679 ), 00680 sizeof( *a ) 00681 ); 00682 if (NT_SUCCESS( m.ReturnValue )) { 00683 try { 00684 SMALL_RECT SourceRect; 00685 00686 SourceRect.Left = a->CharRegion.Left - lpReadRegion->Left; 00687 SourceRect.Top = a->CharRegion.Top - lpReadRegion->Top; 00688 SourceRect.Right = SourceRect.Left + 00689 (a->CharRegion.Right - a->CharRegion.Left); 00690 SourceRect.Bottom = SourceRect.Top + 00691 (a->CharRegion.Bottom - a->CharRegion.Top); 00692 dwBufferCoord.X += SourceRect.Left; 00693 dwBufferCoord.Y += SourceRect.Top; 00694 CopyRectangle(a->BufPtr, 00695 SourceSize, 00696 &SourceRect, 00697 lpBuffer, 00698 dwBufferSize, 00699 dwBufferCoord 00700 ); 00701 } except( EXCEPTION_EXECUTE_HANDLER ) { 00702 if (CaptureBuffer != NULL) { 00703 CsrFreeCaptureBuffer( CaptureBuffer ); 00704 } 00705 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00706 return FALSE; 00707 } 00708 } 00709 if (CaptureBuffer != NULL) { 00710 CsrFreeCaptureBuffer( CaptureBuffer ); 00711 } 00712 *lpReadRegion = a->CharRegion; 00713 if (!NT_SUCCESS(m.ReturnValue)) { 00714 SET_LAST_NT_ERROR(m.ReturnValue); 00715 return FALSE; 00716 } 00717 else { 00718 return TRUE; 00719 } 00720 00721 } 00722 00723 #endif 00724 00725 #if !defined(BUILD_WOW64) 00726 00727 BOOL 00728 APIENTRY 00729 ReadConsoleOutputW( 00730 HANDLE hConsoleOutput, 00731 PCHAR_INFO lpBuffer, 00732 COORD dwBufferSize, 00733 COORD dwBufferCoord, 00734 PSMALL_RECT lpReadRegion 00735 ) 00736 { 00737 return ReadConsoleOutputInternal(hConsoleOutput, 00738 lpBuffer, 00739 dwBufferSize, 00740 dwBufferCoord, 00741 lpReadRegion, 00742 TRUE 00743 ); 00744 } 00745 00746 BOOL 00747 APIENTRY 00748 ReadConsoleOutputA( 00749 HANDLE hConsoleOutput, 00750 PCHAR_INFO lpBuffer, 00751 COORD dwBufferSize, 00752 COORD dwBufferCoord, 00753 PSMALL_RECT lpReadRegion 00754 ) 00755 { 00756 return ReadConsoleOutputInternal(hConsoleOutput, 00757 lpBuffer, 00758 dwBufferSize, 00759 dwBufferCoord, 00760 lpReadRegion, 00761 FALSE 00762 ); 00763 } 00764 00765 #endif 00766 00767 #if !defined(BUILD_WOW6432) 00768 00769 BOOL 00770 APIENTRY 00771 WriteConsoleOutputInternal( 00772 IN HANDLE hConsoleOutput, 00773 IN CONST CHAR_INFO *lpBuffer, 00774 IN COORD dwBufferSize, 00775 IN COORD dwBufferCoord, 00776 IN PSMALL_RECT lpWriteRegion, 00777 IN BOOLEAN Unicode 00778 ) 00779 00780 /*++ 00781 Parameters: 00782 00783 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 00784 that is to be written. The handle must have been created with 00785 GENERIC_WRITE access. 00786 00787 lpBuffer - Supplies the address of a buffer containing the data to write 00788 to the screen buffer. This buffer is treated as a two dimensional 00789 array. 00790 00791 dwBufferSize - size of lpBuffer 00792 00793 dwBufferCoord - coordinates of upper left point in buffer to write data 00794 from. 00795 00796 lpWriteRegion - Supplies on input the address of a structure indicating the 00797 rectangle within the screen buffer to write to. The fields in 00798 the structure are column and row coordinates. On output, the fields 00799 contain the actual region written. 00800 00801 Return Value: 00802 00803 TRUE - The operation was successful. 00804 00805 FALSE/NULL - The operation failed. Extended error status is available 00806 using GetLastError. 00807 --*/ 00808 00809 { 00810 00811 PCSR_CAPTURE_HEADER CaptureBuffer; 00812 CONSOLE_API_MSG m; 00813 PCONSOLE_WRITECONSOLEOUTPUT_MSG a = &m.u.WriteConsoleOutput; 00814 ULONG NumChars; 00815 COORD SourceSize; 00816 COORD TargetPoint; 00817 00818 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00819 a->OutputHandle = hConsoleOutput; 00820 a->Unicode = Unicode; 00821 00822 // 00823 // clip region to write based on caller's buffer size 00824 // 00825 00826 SourceSize.X = (SHORT)CONSOLE_RECT_SIZE_X(lpWriteRegion); 00827 if (SourceSize.X > dwBufferSize.X-dwBufferCoord.X) 00828 SourceSize.X = dwBufferSize.X-dwBufferCoord.X; 00829 SourceSize.Y = (SHORT)CONSOLE_RECT_SIZE_Y(lpWriteRegion); 00830 if (SourceSize.Y > dwBufferSize.Y-dwBufferCoord.Y) 00831 SourceSize.Y = dwBufferSize.Y-dwBufferCoord.Y; 00832 00833 if (SourceSize.X <= 0 || 00834 SourceSize.Y <= 0) { 00835 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 00836 return FALSE; 00837 } 00838 00839 a->CharRegion.Left = lpWriteRegion->Left; 00840 a->CharRegion.Right = (SHORT)(lpWriteRegion->Left + SourceSize.X - 1); 00841 a->CharRegion.Top = lpWriteRegion->Top; 00842 a->CharRegion.Bottom = (SHORT)(lpWriteRegion->Top + SourceSize.Y - 1); 00843 00844 // 00845 // for speed in the case where we're only writing one character, we have 00846 // a buffer in the msg we pass to the server. this means we don't have to 00847 // allocate a capture buffer. 00848 // 00849 00850 NumChars = SourceSize.X * SourceSize.Y; 00851 if (NumChars > 1) { 00852 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00853 NumChars * sizeof(CHAR_INFO) 00854 ); 00855 if (CaptureBuffer == NULL) { 00856 a->ReadVM=TRUE; 00857 a->BufPtr = RtlAllocateHeap( RtlProcessHeap(), 0, NumChars * sizeof(CHAR_INFO)); 00858 if (a->BufPtr == NULL) { 00859 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00860 return FALSE; 00861 } 00862 } else { 00863 a->ReadVM=FALSE; 00864 CsrCaptureMessageBuffer( CaptureBuffer, 00865 NULL, 00866 NumChars * sizeof(CHAR_INFO), 00867 (PVOID *) &a->BufPtr 00868 ); 00869 } 00870 } 00871 else { 00872 a->ReadVM=FALSE; 00873 CaptureBuffer = NULL; 00874 a->BufPtr = &a->Char; 00875 } 00876 try { 00877 SMALL_RECT SourceRect; 00878 00879 SourceRect.Left = dwBufferCoord.X; 00880 SourceRect.Top = dwBufferCoord.Y; 00881 SourceRect.Right = (SHORT)(dwBufferCoord.X+SourceSize.X-1); 00882 SourceRect.Bottom = (SHORT)(dwBufferCoord.Y+SourceSize.Y-1); 00883 TargetPoint.X = 0; 00884 TargetPoint.Y = 0; 00885 CopyRectangle(lpBuffer, 00886 dwBufferSize, 00887 &SourceRect, 00888 a->BufPtr, 00889 SourceSize, 00890 TargetPoint 00891 ); 00892 } except( EXCEPTION_EXECUTE_HANDLER ) { 00893 if (CaptureBuffer != NULL) { 00894 CsrFreeCaptureBuffer( CaptureBuffer ); 00895 } else if (a->ReadVM) { 00896 // a->BufPtr was allocated with RtlAllocateHeap. 00897 RtlFreeHeap( RtlProcessHeap(), 0, a->BufPtr); 00898 } 00899 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00900 return FALSE; 00901 } 00902 CsrClientCallServer( (PCSR_API_MSG)&m, 00903 CaptureBuffer, 00904 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00905 ConsolepWriteConsoleOutput 00906 ), 00907 sizeof( *a ) 00908 ); 00909 if (CaptureBuffer != NULL) { 00910 CsrFreeCaptureBuffer( CaptureBuffer ); 00911 } else if (a->ReadVM) { 00912 // a->BufPtr was allocated with RtlAllocateHeap. 00913 RtlFreeHeap(RtlProcessHeap(),0,a->BufPtr); 00914 } 00915 *lpWriteRegion = a->CharRegion; 00916 if (!NT_SUCCESS(m.ReturnValue)) { 00917 SET_LAST_NT_ERROR(m.ReturnValue); 00918 return FALSE; 00919 } 00920 else { 00921 return TRUE; 00922 } 00923 00924 } 00925 00926 #endif 00927 00928 #if !defined(BUILD_WOW64) 00929 00930 BOOL 00931 APIENTRY 00932 WriteConsoleOutputW( 00933 HANDLE hConsoleOutput, 00934 CONST CHAR_INFO *lpBuffer, 00935 COORD dwBufferSize, 00936 COORD dwBufferCoord, 00937 PSMALL_RECT lpWriteRegion 00938 ) 00939 { 00940 return WriteConsoleOutputInternal(hConsoleOutput, 00941 lpBuffer, 00942 dwBufferSize, 00943 dwBufferCoord, 00944 lpWriteRegion, 00945 TRUE 00946 ); 00947 } 00948 00949 BOOL 00950 APIENTRY 00951 WriteConsoleOutputA( 00952 HANDLE hConsoleOutput, 00953 CONST CHAR_INFO *lpBuffer, 00954 COORD dwBufferSize, 00955 COORD dwBufferCoord, 00956 PSMALL_RECT lpWriteRegion 00957 ) 00958 { 00959 return WriteConsoleOutputInternal(hConsoleOutput, 00960 lpBuffer, 00961 dwBufferSize, 00962 dwBufferCoord, 00963 lpWriteRegion, 00964 FALSE 00965 ); 00966 } 00967 00968 #endif //defined(BUILD_WOW64) 00969 00970 #if !defined(BUILD_WOW6432) 00971 00972 BOOL 00973 APIENTRY 00974 ReadConsoleOutputString( 00975 IN HANDLE hConsoleOutput, 00976 OUT LPVOID lpString, 00977 IN DWORD nLength, 00978 IN DWORD nSize, 00979 IN DWORD fFlags, 00980 IN COORD dwReadCoord, 00981 OUT LPDWORD lpNumberOfElementsRead 00982 ) 00983 00984 /*++ 00985 00986 Parameters: 00987 00988 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 00989 that is to be read. The handle must have been created with 00990 GENERIC_READ access. 00991 00992 lpString - Supplies the address of a buffer to receive the character 00993 or attribute string read from the screen buffer. 00994 00995 nLength - Size of lpCharacter buffer in elements. 00996 00997 nSize - Size of element to read. 00998 00999 fFlags - flag indicating what type of string to copy 01000 01001 dwReadCoord - Screen buffer coordinates of string to read. 01002 read data. 01003 01004 lpNumberOfElementsRead - Pointer to number of events read. 01005 01006 Return Value: 01007 01008 TRUE - The operation was successful. 01009 01010 FALSE/NULL - The operation failed. 01011 Extended error status is available using GetLastError. 01012 01013 --*/ 01014 01015 { 01016 PCSR_CAPTURE_HEADER CaptureBuffer; 01017 CONSOLE_API_MSG m; 01018 PCONSOLE_READCONSOLEOUTPUTSTRING_MSG a = &m.u.ReadConsoleOutputString; 01019 ULONG DataLength; 01020 01021 a->ConsoleHandle = GET_CONSOLE_HANDLE; 01022 a->OutputHandle = hConsoleOutput; 01023 a->NumRecords = nLength; 01024 a->StringType = fFlags; 01025 a->ReadCoord = dwReadCoord; 01026 01027 DataLength = nLength*nSize; 01028 01029 // 01030 // for speed in the case where the string is small, we have a buffer 01031 // in the msg we pass to the server. this means we don't have to 01032 // allocate a capture buffer. 01033 // 01034 01035 if (DataLength > sizeof(a->String)) { 01036 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 01037 DataLength 01038 ); 01039 if (CaptureBuffer == NULL) { 01040 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 01041 return FALSE; 01042 } 01043 CsrCaptureMessageBuffer( CaptureBuffer, 01044 NULL, 01045 DataLength, 01046 (PVOID *) &a->BufPtr 01047 ); 01048 01049 } 01050 else { 01051 a->BufPtr = a->String; 01052 CaptureBuffer = NULL; 01053 } 01054 CsrClientCallServer( (PCSR_API_MSG)&m, 01055 CaptureBuffer, 01056 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 01057 ConsolepReadConsoleOutputString 01058 ), 01059 sizeof( *a ) 01060 ); 01061 01062 try { 01063 *lpNumberOfElementsRead = a->NumRecords; 01064 if (NT_SUCCESS( m.ReturnValue )) { 01065 RtlCopyMemory(lpString, a->BufPtr, a->NumRecords * nSize); 01066 } 01067 else { 01068 SET_LAST_NT_ERROR(m.ReturnValue); 01069 } 01070 } except( EXCEPTION_EXECUTE_HANDLER ) { 01071 if (CaptureBuffer != NULL) { 01072 CsrFreeCaptureBuffer( CaptureBuffer ); 01073 } 01074 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01075 return FALSE; 01076 } 01077 if (CaptureBuffer != NULL) { 01078 CsrFreeCaptureBuffer( CaptureBuffer ); 01079 } 01080 return NT_SUCCESS(m.ReturnValue); 01081 } 01082 01083 #endif 01084 01085 #if !defined(BUILD_WOW64) 01086 01087 BOOL 01088 APIENTRY 01089 ReadConsoleOutputCharacterA( 01090 HANDLE hConsoleOutput, 01091 LPSTR lpCharacter, 01092 DWORD nLength, 01093 COORD dwReadCoord, 01094 LPDWORD lpNumberOfCharsRead 01095 ) 01096 01097 /*++ 01098 01099 Parameters: 01100 01101 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01102 that is to be read. The handle must have been created with 01103 GENERIC_READ access. 01104 01105 lpCharacter - Supplies the address of a buffer to receive the character 01106 string read from the screen buffer. 01107 01108 nLength - Size of lpCharacter buffer in characters. 01109 01110 dwReadCoord - Screen buffer coordinates of string to read. 01111 read data. 01112 01113 lpNumberOfCharsRead - Pointer to number of chars read. 01114 01115 Return Value: 01116 01117 TRUE - The operation was successful. 01118 01119 FALSE/NULL - The operation failed. 01120 Extended error status is available using GetLastError. 01121 01122 --*/ 01123 01124 { 01125 return ReadConsoleOutputString(hConsoleOutput, 01126 lpCharacter, 01127 nLength, 01128 sizeof(CHAR), 01129 CONSOLE_ASCII, 01130 dwReadCoord, 01131 lpNumberOfCharsRead 01132 ); 01133 } 01134 01135 01136 BOOL 01137 APIENTRY 01138 ReadConsoleOutputCharacterW( 01139 HANDLE hConsoleOutput, 01140 LPWSTR lpCharacter, 01141 DWORD nLength, 01142 COORD dwReadCoord, 01143 LPDWORD lpNumberOfCharsRead 01144 ) 01145 01146 { 01147 return ReadConsoleOutputString(hConsoleOutput, 01148 lpCharacter, 01149 nLength, 01150 sizeof(WCHAR), 01151 CONSOLE_REAL_UNICODE, 01152 dwReadCoord, 01153 lpNumberOfCharsRead 01154 ); 01155 } 01156 01157 01158 BOOL 01159 APIENTRY 01160 ReadConsoleOutputAttribute( 01161 HANDLE hConsoleOutput, 01162 LPWORD lpAttribute, 01163 DWORD nLength, 01164 COORD dwReadCoord, 01165 LPDWORD lpNumberOfAttrsRead 01166 ) 01167 01168 /*++ 01169 01170 Parameters: 01171 01172 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01173 that is to be read. The handle must have been created with 01174 GENERIC_READ access. 01175 01176 lpAttribute - Supplies the address of a buffer to receive the attribute 01177 string read from the screen buffer. 01178 01179 nLength - Size of lpAttribute buffer in bytes. 01180 01181 dwReadCoord - Screen buffer coordinates of string to read. 01182 read data. 01183 01184 lpNumberOfAttrsRead - Pointer to number of attrs read. 01185 01186 Return Value: 01187 01188 TRUE - The operation was successful. 01189 01190 FALSE/NULL - The operation failed. 01191 Extended error status is available using GetLastError. 01192 01193 --*/ 01194 01195 { 01196 return ReadConsoleOutputString(hConsoleOutput, 01197 lpAttribute, 01198 nLength, 01199 sizeof(WORD), 01200 CONSOLE_ATTRIBUTE, 01201 dwReadCoord, 01202 lpNumberOfAttrsRead 01203 ); 01204 } 01205 01206 #endif 01207 01208 #if !defined(BUILD_WOW6432) 01209 01210 BOOL 01211 APIENTRY 01212 WriteConsoleOutputString( 01213 IN HANDLE hConsoleOutput, 01214 IN CONST VOID *lpString, 01215 IN DWORD nLength, 01216 IN DWORD nSize, 01217 IN DWORD fFlags, 01218 IN COORD dwWriteCoord, 01219 OUT LPDWORD lpNumberOfElementsWritten 01220 ) 01221 01222 /*++ 01223 01224 Parameters: 01225 01226 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01227 that is to be written. The handle must have been created with 01228 GENERIC_WRITE access. 01229 01230 lpString - Supplies the address of a buffer containing the character 01231 or attribute string to write to the screen buffer. 01232 01233 nLength - Length of string to write, in elements. 01234 01235 nSize - Size of element to read. 01236 01237 fFlags - flag indicating what type of string to copy 01238 01239 dwWriteCoord - Screen buffer coordinates to write the string to. 01240 01241 lpNumberOfElementsWritten - Pointer to number of elements written. 01242 01243 Return Value: 01244 01245 TRUE - The operation was successful. 01246 01247 FALSE/NULL - The operation failed. 01248 Extended error status is available using GetLastError. 01249 01250 --*/ 01251 01252 { 01253 01254 PCSR_CAPTURE_HEADER CaptureBuffer; 01255 CONSOLE_API_MSG m; 01256 PCONSOLE_WRITECONSOLEOUTPUTSTRING_MSG a = &m.u.WriteConsoleOutputString; 01257 ULONG DataLength; 01258 01259 a->ConsoleHandle = GET_CONSOLE_HANDLE; 01260 a->OutputHandle = hConsoleOutput; 01261 a->NumRecords = nLength; 01262 a->StringType = fFlags; 01263 a->WriteCoord = dwWriteCoord; 01264 01265 // 01266 // for speed in the case where the string is small, we have a buffer 01267 // in the msg we pass to the server. this means we don't have to 01268 // allocate a capture buffer. 01269 // 01270 01271 DataLength = nLength*nSize; 01272 if (DataLength > sizeof(a->String)) { 01273 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 01274 DataLength 01275 ); 01276 if (CaptureBuffer == NULL) { 01277 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 01278 return FALSE; 01279 } 01280 CsrCaptureMessageBuffer( CaptureBuffer, 01281 (PCHAR) lpString, 01282 DataLength, 01283 (PVOID *) &a->BufPtr 01284 ); 01285 } 01286 else { 01287 a->BufPtr = a->String; 01288 CaptureBuffer = NULL; 01289 01290 try { 01291 RtlCopyMemory(a->BufPtr, lpString, DataLength); 01292 } except( EXCEPTION_EXECUTE_HANDLER ) { 01293 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01294 return FALSE; 01295 } 01296 } 01297 CsrClientCallServer( (PCSR_API_MSG)&m, 01298 CaptureBuffer, 01299 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 01300 ConsolepWriteConsoleOutputString 01301 ), 01302 sizeof( *a ) 01303 ); 01304 if (CaptureBuffer != NULL) { 01305 CsrFreeCaptureBuffer( CaptureBuffer ); 01306 } 01307 try { 01308 *lpNumberOfElementsWritten = a->NumRecords; 01309 } except( EXCEPTION_EXECUTE_HANDLER ) { 01310 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01311 return FALSE; 01312 } 01313 if (!NT_SUCCESS(m.ReturnValue)) { 01314 SET_LAST_NT_ERROR(m.ReturnValue); 01315 return FALSE; 01316 } 01317 else { 01318 return TRUE; 01319 } 01320 01321 } 01322 01323 #endif 01324 01325 #if !defined(BUILD_WOW64) 01326 01327 BOOL 01328 APIENTRY 01329 WriteConsoleOutputCharacterA( 01330 HANDLE hConsoleOutput, 01331 LPCSTR lpCharacter, 01332 DWORD nLength, 01333 COORD dwWriteCoord, 01334 LPDWORD lpNumberOfCharsWritten 01335 ) 01336 01337 /*++ 01338 01339 Parameters: 01340 01341 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01342 that is to be written. The handle must have been created with 01343 GENERIC_WRITE access. 01344 01345 lpCharacter - Supplies the address of a buffer containing the character 01346 string to write to the screen buffer. 01347 01348 nLength - Length of string to write, in characters. 01349 01350 dwWriteCoord - Screen buffer coordinates to write the string to. 01351 01352 lpNumberOfCharsWritten - Pointer to number of chars written. 01353 01354 Return Value: 01355 01356 TRUE - The operation was successful. 01357 01358 FALSE/NULL - The operation failed. 01359 Extended error status is available using GetLastError. 01360 01361 --*/ 01362 01363 { 01364 return WriteConsoleOutputString(hConsoleOutput, 01365 lpCharacter, 01366 nLength, 01367 sizeof(CHAR), 01368 CONSOLE_ASCII, 01369 dwWriteCoord, 01370 lpNumberOfCharsWritten 01371 ); 01372 } 01373 01374 BOOL 01375 APIENTRY 01376 WriteConsoleOutputCharacterW( 01377 HANDLE hConsoleOutput, 01378 LPCWSTR lpCharacter, 01379 DWORD nLength, 01380 COORD dwWriteCoord, 01381 LPDWORD lpNumberOfCharsWritten 01382 ) 01383 01384 { 01385 return WriteConsoleOutputString(hConsoleOutput, 01386 lpCharacter, 01387 nLength, 01388 sizeof(WCHAR), 01389 CONSOLE_REAL_UNICODE, 01390 dwWriteCoord, 01391 lpNumberOfCharsWritten 01392 ); 01393 } 01394 01395 BOOL 01396 APIENTRY 01397 WriteConsoleOutputAttribute( 01398 HANDLE hConsoleOutput, 01399 CONST WORD *lpAttribute, 01400 DWORD nLength, 01401 COORD dwWriteCoord, 01402 LPDWORD lpNumberOfAttrsWritten 01403 ) 01404 01405 /*++ 01406 01407 Parameters: 01408 01409 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01410 that is to be written. The handle must have been created with 01411 GENERIC_WRITE access. 01412 01413 lpAttribute - Supplies the address of a buffer containing the attribute 01414 string to write to the screen buffer. 01415 01416 nLength - Length of string to write. 01417 01418 dwWriteCoord - Screen buffer coordinates to write the string to. 01419 01420 lpNumberOfAttrsWritten - Pointer to number of attrs written. 01421 01422 Return Value: 01423 01424 TRUE - The operation was successful. 01425 01426 FALSE/NULL - The operation failed. 01427 Extended error status is available using GetLastError. 01428 01429 --*/ 01430 01431 { 01432 return WriteConsoleOutputString(hConsoleOutput, 01433 lpAttribute, 01434 nLength, 01435 sizeof(WORD), 01436 CONSOLE_ATTRIBUTE, 01437 dwWriteCoord, 01438 lpNumberOfAttrsWritten 01439 ); 01440 } 01441 01442 #endif 01443 01444 #if !defined(BUILD_WOW6432) 01445 01446 BOOL 01447 APIENTRY 01448 FillConsoleOutput( 01449 IN HANDLE hConsoleOutput, 01450 IN WORD Element, 01451 IN DWORD nLength, 01452 IN DWORD fFlags, 01453 IN COORD dwWriteCoord, 01454 OUT LPDWORD lpNumberOfElementsWritten 01455 ) 01456 01457 /*++ 01458 01459 Parameters: 01460 01461 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01462 that is to be written. The handle must have been created with 01463 GENERIC_WRITE access. 01464 01465 Element - The attribute or character to write. 01466 01467 nLength - Number of times to write the element. 01468 01469 fFlags - flag indicating what type of element to write. 01470 01471 dwWriteCoord - Screen buffer coordinates to write the element to. 01472 01473 lpNumberOfElementsWritten - Pointer to number of elements written. 01474 01475 Return Value: 01476 01477 TRUE - The operation was successful. 01478 01479 FALSE/NULL - The operation failed. 01480 Extended error status is available using GetLastError. 01481 01482 --*/ 01483 01484 { 01485 01486 CONSOLE_API_MSG m; 01487 PCONSOLE_FILLCONSOLEOUTPUT_MSG a = &m.u.FillConsoleOutput; 01488 01489 a->ConsoleHandle = GET_CONSOLE_HANDLE; 01490 a->OutputHandle = hConsoleOutput; 01491 a->Length = nLength; 01492 a->ElementType = fFlags; 01493 a->Element = Element; 01494 a->WriteCoord = dwWriteCoord; 01495 CsrClientCallServer( (PCSR_API_MSG)&m, 01496 NULL, 01497 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 01498 ConsolepFillConsoleOutput 01499 ), 01500 sizeof( *a ) 01501 ); 01502 try { 01503 *lpNumberOfElementsWritten = a->Length; 01504 } except( EXCEPTION_EXECUTE_HANDLER ) { 01505 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01506 return FALSE; 01507 } 01508 if (!NT_SUCCESS(m.ReturnValue)) { 01509 SET_LAST_NT_ERROR(m.ReturnValue); 01510 return FALSE; 01511 } 01512 else { 01513 return TRUE; 01514 } 01515 01516 } 01517 01518 #endif 01519 01520 #if !defined(BUILD_WOW64) 01521 01522 BOOL 01523 APIENTRY 01524 FillConsoleOutputCharacterA( 01525 HANDLE hConsoleOutput, 01526 CHAR cCharacter, 01527 DWORD nLength, 01528 COORD dwWriteCoord, 01529 LPDWORD lpNumberOfCharsWritten 01530 ) 01531 01532 /*++ 01533 01534 Parameters: 01535 01536 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01537 that is to be written. The handle must have been created with 01538 GENERIC_WRITE access. 01539 01540 cCharacter - Supplies the ASCII character to write to the screen buffer. 01541 01542 nLength - Number of times to write the character. 01543 01544 dwWriteCoord - Screen buffer coordinates to begin writing the character 01545 to. 01546 01547 lpNumberOfCharsWritten - Pointer to number of chars written. 01548 01549 Return Value: 01550 01551 TRUE - The operation was successful. 01552 01553 FALSE/NULL - The operation failed. 01554 Extended error status is available using GetLastError. 01555 01556 --*/ 01557 01558 { 01559 return FillConsoleOutput(hConsoleOutput, 01560 (USHORT) cCharacter, 01561 nLength, 01562 CONSOLE_ASCII, 01563 dwWriteCoord, 01564 lpNumberOfCharsWritten 01565 ); 01566 } 01567 01568 BOOL 01569 APIENTRY 01570 FillConsoleOutputCharacterW( 01571 HANDLE hConsoleOutput, 01572 WCHAR cCharacter, 01573 DWORD nLength, 01574 COORD dwWriteCoord, 01575 LPDWORD lpNumberOfCharsWritten 01576 ) 01577 01578 /*++ 01579 01580 Parameters: 01581 01582 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01583 that is to be written. The handle must have been created with 01584 GENERIC_WRITE access. 01585 01586 cCharacter - Supplies the ASCII character to write to the screen buffer. 01587 01588 nLength - Number of times to write the character. 01589 01590 dwWriteCoord - Screen buffer coordinates to begin writing the character 01591 to. 01592 01593 lpNumberOfCharsWritten - Pointer to number of chars written. 01594 01595 Return Value: 01596 01597 TRUE - The operation was successful. 01598 01599 FALSE/NULL - The operation failed. 01600 Extended error status is available using GetLastError. 01601 01602 --*/ 01603 01604 { 01605 return FillConsoleOutput(hConsoleOutput, 01606 (USHORT) cCharacter, 01607 nLength, 01608 CONSOLE_REAL_UNICODE, 01609 dwWriteCoord, 01610 lpNumberOfCharsWritten 01611 ); 01612 } 01613 01614 BOOL 01615 APIENTRY 01616 FillConsoleOutputAttribute( 01617 HANDLE hConsoleOutput, 01618 WORD wAttribute, 01619 DWORD nLength, 01620 COORD dwWriteCoord, 01621 LPDWORD lpNumberOfAttrsWritten 01622 ) 01623 01624 /*++ 01625 01626 Parameters: 01627 01628 hConsoleOutput - Supplies an open handle to the screen buffer (CONOUT$) 01629 that is to be written. The handle must have been created with 01630 GENERIC_WRITE access. 01631 01632 wAttribute - Supplies the attribute to write to the screen buffer. 01633 01634 nLength - Number of times to write the attribute. 01635 01636 dwWriteCoord - Screen buffer coordinates to begin writing the attribute 01637 to. 01638 01639 lpNumberOfAttrsWritten - Pointer to number of attrs written. 01640 01641 Return Value: 01642 01643 TRUE - The operation was successful. 01644 01645 FALSE/NULL - The operation failed. 01646 Extended error status is available using GetLastError. 01647 01648 --*/ 01649 01650 { 01651 return FillConsoleOutput(hConsoleOutput, 01652 wAttribute, 01653 nLength, 01654 CONSOLE_ATTRIBUTE, 01655 dwWriteCoord, 01656 lpNumberOfAttrsWritten 01657 ); 01658 } 01659 01660 #endif 01661 01662 #if !defined(BUILD_WOW6432) 01663 01664 HANDLE 01665 WINAPI 01666 CreateConsoleScreenBuffer( 01667 IN DWORD dwDesiredAccess, 01668 IN DWORD dwShareMode, 01669 IN CONST SECURITY_ATTRIBUTES *lpSecurityAttributes, 01670 IN DWORD dwFlags, 01671 IN PVOID lpScreenBufferData OPTIONAL 01672 ) 01673 { 01674 CONSOLE_API_MSG m; 01675 PCONSOLE_CREATESCREENBUFFER_MSG a = &m.u.CreateConsoleScreenBuffer; 01676 PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo; 01677 PCSR_CAPTURE_HEADER CaptureBuffer=NULL; 01678 01679 if (dwDesiredAccess & ~VALID_ACCESSES || 01680 dwShareMode & ~VALID_SHARE_ACCESSES || 01681 (dwFlags != CONSOLE_TEXTMODE_BUFFER && 01682 dwFlags != CONSOLE_GRAPHICS_BUFFER)) { 01683 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 01684 return (HANDLE) INVALID_HANDLE_VALUE; 01685 } 01686 a->ConsoleHandle = GET_CONSOLE_HANDLE; 01687 a->DesiredAccess = dwDesiredAccess; 01688 if (ARGUMENT_PRESENT(lpSecurityAttributes)) { 01689 a->InheritHandle = lpSecurityAttributes->bInheritHandle; 01690 } 01691 else { 01692 a->InheritHandle = FALSE; 01693 } 01694 a->ShareMode = dwShareMode; 01695 a->Flags = dwFlags; 01696 if (dwFlags == CONSOLE_GRAPHICS_BUFFER) { 01697 if (a->InheritHandle || lpScreenBufferData == NULL) { 01698 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 01699 return (HANDLE) INVALID_HANDLE_VALUE; 01700 } 01701 GraphicsBufferInfo = lpScreenBufferData; 01702 try { 01703 a->GraphicsBufferInfo = *GraphicsBufferInfo; 01704 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 01705 a->GraphicsBufferInfo.dwBitMapInfoLength 01706 ); 01707 if (CaptureBuffer == NULL) { 01708 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 01709 return (HANDLE) INVALID_HANDLE_VALUE; 01710 } 01711 CsrCaptureMessageBuffer( CaptureBuffer, 01712 (PCHAR) GraphicsBufferInfo->lpBitMapInfo, 01713 a->GraphicsBufferInfo.dwBitMapInfoLength, 01714 (PVOID *) &a->GraphicsBufferInfo.lpBitMapInfo 01715 ); 01716 01717 } except( EXCEPTION_EXECUTE_HANDLER ) { 01718 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01719 return (HANDLE) INVALID_HANDLE_VALUE; 01720 } 01721 } 01722 CsrClientCallServer( (PCSR_API_MSG)&m, 01723 CaptureBuffer, 01724 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 01725 ConsolepCreateScreenBuffer 01726 ), 01727 sizeof( *a ) 01728 ); 01729 if (CaptureBuffer != NULL) { 01730 CsrFreeCaptureBuffer( CaptureBuffer ); 01731 } 01732 if (!NT_SUCCESS( m.ReturnValue)) { 01733 SET_LAST_NT_ERROR(m.ReturnValue); 01734 return (HANDLE) INVALID_HANDLE_VALUE; 01735 } 01736 else { 01737 if (dwFlags == CONSOLE_GRAPHICS_BUFFER) { 01738 try { 01739 GraphicsBufferInfo->hMutex = a->hMutex; 01740 GraphicsBufferInfo->lpBitMap = a->lpBitmap; 01741 } except( EXCEPTION_EXECUTE_HANDLER ) { 01742 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01743 return (HANDLE) INVALID_HANDLE_VALUE; 01744 } 01745 } 01746 return a->Handle; 01747 } 01748 } 01749 01750 BOOL 01751 WINAPI 01752 InvalidateConsoleDIBits( 01753 IN HANDLE hConsoleOutput, 01754 IN PSMALL_RECT lpRect 01755 ) 01756 01757 /*++ 01758 01759 Parameters: 01760 01761 hConsoleHandle - Supplies a console input or output handle. 01762 01763 lpRect - the region that needs to be updated to the screen. 01764 01765 Return Value: 01766 01767 TRUE - The operation was successful. 01768 01769 FALSE/NULL - The operation failed. Extended error status is available 01770 using GetLastError. 01771 01772 01773 --*/ 01774 01775 { 01776 CONSOLE_API_MSG m; 01777 PCONSOLE_INVALIDATERECT_MSG a = &m.u.InvalidateConsoleBitmapRect; 01778 01779 a->ConsoleHandle = GET_CONSOLE_HANDLE; 01780 a->OutputHandle = hConsoleOutput; 01781 try { 01782 a->Rect = *lpRect; 01783 } except( EXCEPTION_EXECUTE_HANDLER ) { 01784 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 01785 return ERROR_INVALID_ACCESS; 01786 } 01787 CsrClientCallServer( (PCSR_API_MSG)&m, 01788 NULL, 01789 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 01790 ConsolepInvalidateBitmapRect 01791 ), 01792 sizeof( *a ) 01793 ); 01794 if (NT_SUCCESS( m.ReturnValue )) { 01795 return TRUE; 01796 } else { 01797 SET_LAST_NT_ERROR (m.ReturnValue); 01798 return FALSE; 01799 } 01800 } 01801 01802 #endif

Generated on Sat May 15 19:40:30 2004 for test by doxygen 1.3.7