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

stream.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1985 - 1999, Microsoft Corporation 00004 00005 Module Name: 00006 00007 stream.c 00008 00009 Abstract: 00010 00011 This module contains the stubs for the console stream API. 00012 00013 Author: 00014 00015 Therese Stowell (thereses) 3-Dec-1990 00016 00017 Revision History: 00018 00019 00020 00021 --*/ 00022 00023 #include "precomp.h" 00024 #pragma hdrstop 00025 #pragma hdrstop 00026 00027 #if !defined(BUILD_WOW64) 00028 00029 HANDLE InputWaitHandle = (HANDLE)-1; 00030 00031 HANDLE 00032 APIENTRY 00033 GetConsoleInputWaitHandle( VOID ) 00034 { 00035 return InputWaitHandle; 00036 } 00037 00038 #endif 00039 00040 #if !defined(BUILD_WOW6432) 00041 00042 HANDLE 00043 APIENTRY 00044 OpenConsoleWInternal( 00045 IN ULONG HandleType, 00046 IN ULONG DesiredAccess, 00047 IN BOOL InheritHandle, 00048 IN ULONG ShareMode 00049 ) 00050 /*++ 00051 00052 Routine Description: 00053 00054 Marshels parameters for the ConsolepOpenConsole command. 00055 00056 Arguments: 00057 00058 See the CONSOLE_OPENCONSOLE_MSG structure and OpenConsoleW. 00059 00060 Return Value: 00061 00062 INVALID_HANDLE_VALUE - An error occured. 00063 00064 --*/ 00065 { 00066 00067 CONSOLE_API_MSG m; 00068 PCONSOLE_OPENCONSOLE_MSG a = &m.u.OpenConsole; 00069 00070 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00071 a->HandleType = HandleType; 00072 a->DesiredAccess = DesiredAccess; 00073 a->InheritHandle = InheritHandle; 00074 a->ShareMode= ShareMode; 00075 CsrClientCallServer( (PCSR_API_MSG)&m, 00076 NULL, 00077 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00078 ConsolepOpenConsole 00079 ), 00080 sizeof( *a ) 00081 ); 00082 if (!NT_SUCCESS( m.ReturnValue)) { 00083 SET_LAST_NT_ERROR(m.ReturnValue); 00084 return (HANDLE) INVALID_HANDLE_VALUE; 00085 } 00086 else { 00087 return a->Handle; 00088 } 00089 00090 } 00091 00092 #endif // !defined(BUILD_WOW6432) 00093 00094 #if !defined(BUILD_WOW64) 00095 00096 HANDLE 00097 APIENTRY 00098 OpenConsoleW( 00099 IN LPWSTR lpConsoleDevice, 00100 IN DWORD dwDesiredAccess, 00101 IN BOOL bInheritHandle, 00102 IN DWORD dwShareMode 00103 ) 00104 00105 /*++ 00106 00107 Parameters: 00108 00109 lpConsoleDevice - Supplies the console device name to open. "CONIN$" 00110 indicates console input. "CONOUT$" indicates console output. The 00111 caller must have appropriate access to the console for this call to 00112 succeed. 00113 00114 dwDesiredAccess - Supplies the caller's desired access to the console 00115 device. 00116 00117 DesiredAccess Flags: 00118 00119 GENERIC_READ - Read access to the console device is requested. This 00120 allows data to be read from the console device. 00121 00122 GENERIC_WRITE - Write access to the console device is requested. This 00123 allows data to be written to the console device. 00124 00125 bInheritHandle - Supplies a flag that indicates whether or not the 00126 returned handle is to be inherited by a new process 00127 during a CreateProcess. A value of TRUE indicates that the 00128 new process will inherit the handle. 00129 00130 dwShareMode - Supplies a set of flags that indicates how this console 00131 device is to be shared with other openers of the console device. A 00132 value of zero for this parameter indicates no sharing of the console, 00133 or exclusive access to the console is to occur. 00134 00135 ShareMode Flags: 00136 00137 FILE_SHARE_READ - Other open operations may be performed on the 00138 console device for read access. 00139 00140 FILE_SHARE_WRITE - Other open operations may be performed on the 00141 console device for write access. 00142 00143 Return Value: 00144 00145 Not -1 - Returns an open handle to the specified console device. 00146 Subsequent access to the file is controlled by the DesiredAccess 00147 parameter. 00148 00149 0xffffffff - The operation failed. Extended error status is available 00150 using GetLastError. 00151 --*/ 00152 00153 { 00154 ULONG HandleType; 00155 00156 try { 00157 if (!lstrcmpiW(CONSOLE_INPUT_STRING,lpConsoleDevice)) { 00158 HandleType = CONSOLE_INPUT_HANDLE; 00159 } 00160 else if (!lstrcmpiW(CONSOLE_OUTPUT_STRING,lpConsoleDevice)) { 00161 HandleType = CONSOLE_OUTPUT_HANDLE; 00162 } 00163 else { 00164 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 00165 return (HANDLE) INVALID_HANDLE_VALUE; 00166 } 00167 } except( EXCEPTION_EXECUTE_HANDLER ) { 00168 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00169 return (HANDLE) INVALID_HANDLE_VALUE; 00170 } 00171 if (dwDesiredAccess & ~VALID_ACCESSES || 00172 dwShareMode & ~VALID_SHARE_ACCESSES) { 00173 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 00174 return (HANDLE) INVALID_HANDLE_VALUE; 00175 } 00176 00177 return OpenConsoleWInternal(HandleType, 00178 dwDesiredAccess, 00179 bInheritHandle, 00180 dwShareMode 00181 ); 00182 00183 } 00184 00185 #endif // !defined(BUILD_WOW64) 00186 00187 #if !defined(BUILD_WOW6432) 00188 00189 BOOL 00190 APIENTRY 00191 ReadConsoleInternal( 00192 IN HANDLE hConsoleInput, 00193 OUT LPVOID lpBuffer, 00194 IN DWORD nNumberOfCharsToRead, 00195 OUT LPDWORD lpNumberOfCharsRead, 00196 IN OUT LPVOID lpReserved, 00197 IN BOOLEAN Unicode, 00198 IN USHORT ExeNameLength, 00199 IN LPWSTR ExeName 00200 ) 00201 /*++ 00202 Parameters: 00203 00204 hConsoleInput - Supplies an open handle to "CONIN$" open for GENERIC_READ 00205 or the StdIn handle. 00206 00207 lpBuffer - Supplies the address of a buffer to receive the data read 00208 from the console input. 00209 00210 nNumberOfBytesToRead - Supplies the number of bytes to read from the 00211 input buffer. 00212 00213 lpReserved - Ignore unless 4.0 application, in which case it points 00214 to a CONSOLE_READCONSOLE_CONTROL data structure. UNICODE only. 00215 If !Unicode, then call fails if this parameter is non-NULL 00216 00217 Unicode - TRUE if call from ReadConsoleW, FALSE if ReadConsoleA 00218 00219 00220 Return Value: 00221 00222 NON-NULL - Returns the number of bytes actually read from the input buffer. 00223 00224 FALSE/NULL - The operation failed. 00225 Extended error status is available using GetLastError. 00226 --*/ 00227 00228 { 00229 PCSR_CAPTURE_HEADER CaptureBuffer; 00230 CONSOLE_API_MSG m; 00231 PCONSOLE_READCONSOLE_MSG a = &m.u.ReadConsole; 00232 BOOLEAN Dummy; 00233 PCONSOLE_READCONSOLE_CONTROL pInputControl; 00234 NTSTATUS Status; 00235 00236 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00237 a->InputHandle = hConsoleInput; 00238 a->ExeNameLength = ExeNameLength; 00239 RtlCopyMemory(a->Buffer, ExeName, ExeNameLength); 00240 a->Unicode = Unicode; 00241 00242 // 00243 // if ansi, make capture buffer large enough to hold translated 00244 // string. this will make server side code much simpler. 00245 // 00246 00247 a->CaptureBufferSize = a->NumBytes = nNumberOfCharsToRead * sizeof(WCHAR); 00248 if (a->CaptureBufferSize > BUFFER_SIZE) { 00249 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00250 a->CaptureBufferSize 00251 ); 00252 if (CaptureBuffer == NULL) { 00253 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00254 return FALSE; 00255 } 00256 CsrCaptureMessageBuffer( CaptureBuffer, 00257 NULL, 00258 a->CaptureBufferSize, 00259 (PVOID *) &a->BufPtr 00260 ); 00261 00262 } 00263 else { 00264 a->BufPtr = a->Buffer; 00265 CaptureBuffer = NULL; 00266 } 00267 00268 00269 pInputControl = (PCONSOLE_READCONSOLE_CONTROL)lpReserved; 00270 a->InitialNumBytes = 0; 00271 a->CtrlWakeupMask = 0; 00272 a->ControlKeyState = 0; 00273 Status = STATUS_SUCCESS; 00274 try { 00275 if (Unicode && 00276 ARGUMENT_PRESENT(lpReserved) && 00277 NtCurrentPeb()->ImageSubsystemMajorVersion >= 4 && 00278 pInputControl->nLength == sizeof(*pInputControl) 00279 ) { 00280 if ((pInputControl->nInitialChars > nNumberOfCharsToRead)) { 00281 Status = STATUS_INVALID_PARAMETER; 00282 } else { 00283 a->InitialNumBytes = pInputControl->nInitialChars * sizeof(WCHAR); 00284 if (pInputControl->nInitialChars != 0) { 00285 RtlCopyMemory( a->BufPtr, lpBuffer, a->InitialNumBytes ); 00286 } 00287 a->CtrlWakeupMask = pInputControl->dwCtrlWakeupMask; 00288 } 00289 } else { 00290 pInputControl = NULL; 00291 } 00292 } except( EXCEPTION_EXECUTE_HANDLER ) { 00293 Status = GetExceptionCode(); 00294 } 00295 00296 if (!NT_SUCCESS(Status) && pInputControl != NULL) { 00297 if (CaptureBuffer != NULL) { 00298 CsrFreeCaptureBuffer( CaptureBuffer ); 00299 } 00300 SET_LAST_NT_ERROR(Status); 00301 return FALSE; 00302 } 00303 00304 CsrClientCallServer( (PCSR_API_MSG)&m, 00305 CaptureBuffer, 00306 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00307 ConsolepReadConsole 00308 ), 00309 sizeof( *a ) 00310 ); 00311 if (NT_SUCCESS( m.ReturnValue )) { 00312 try { 00313 *lpNumberOfCharsRead = a->NumBytes; 00314 if (Unicode) { 00315 *lpNumberOfCharsRead /= sizeof(WCHAR); 00316 if (pInputControl != NULL) { 00317 pInputControl->dwControlKeyState = a->ControlKeyState; 00318 } 00319 } 00320 RtlCopyMemory( lpBuffer, a->BufPtr, a->NumBytes ); 00321 } except( EXCEPTION_EXECUTE_HANDLER ) { 00322 if (CaptureBuffer != NULL) { 00323 CsrFreeCaptureBuffer( CaptureBuffer ); 00324 } 00325 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00326 return FALSE; 00327 } 00328 } 00329 if (CaptureBuffer != NULL) { 00330 CsrFreeCaptureBuffer( CaptureBuffer ); 00331 } 00332 if (!NT_SUCCESS( m.ReturnValue )) { 00333 SET_LAST_NT_ERROR(m.ReturnValue); 00334 return FALSE; 00335 } else if (m.ReturnValue == STATUS_ALERTED) { 00336 // ctrl-c or ctrl-break 00337 NtYieldExecution(); 00338 SET_LAST_ERROR(ERROR_OPERATION_ABORTED); 00339 } 00340 return TRUE; 00341 } 00342 00343 #endif 00344 00345 #if !defined(BUILD_WOW64) 00346 00347 BOOL 00348 APIENTRY 00349 ReadConsoleA( 00350 IN HANDLE hConsoleInput, 00351 OUT LPVOID lpBuffer, 00352 IN DWORD nNumberOfCharsToRead, 00353 OUT LPDWORD lpNumberOfCharsRead, 00354 IN OUT LPVOID lpReserved 00355 ) 00356 { 00357 00358 WCHAR ExeName[BUFFER_SIZE/2]; 00359 USHORT ExeNameLength; 00360 00361 ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName)); 00362 00363 return ReadConsoleInternal(hConsoleInput, 00364 lpBuffer, 00365 nNumberOfCharsToRead, 00366 lpNumberOfCharsRead, 00367 NULL, 00368 FALSE, 00369 ExeNameLength, 00370 ExeName 00371 ); 00372 UNREFERENCED_PARAMETER(lpReserved); 00373 } 00374 00375 BOOL 00376 APIENTRY 00377 ReadConsoleW( 00378 IN HANDLE hConsoleInput, 00379 OUT LPVOID lpBuffer, 00380 IN DWORD nNumberOfCharsToRead, 00381 OUT LPDWORD lpNumberOfCharsRead, 00382 IN OUT LPVOID lpReserved 00383 ) 00384 { 00385 WCHAR ExeName[BUFFER_SIZE/2]; 00386 USHORT ExeNameLength; 00387 00388 ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName)); 00389 00390 return ReadConsoleInternal(hConsoleInput, 00391 lpBuffer, 00392 nNumberOfCharsToRead, 00393 lpNumberOfCharsRead, 00394 lpReserved, 00395 TRUE, 00396 ExeNameLength, 00397 ExeName 00398 ); 00399 UNREFERENCED_PARAMETER(lpReserved); 00400 } 00401 00402 #endif 00403 00404 #if !defined(BUILD_WOW6432) 00405 00406 BOOL 00407 APIENTRY 00408 WriteConsoleInternal( 00409 IN HANDLE hConsoleOutput, 00410 IN CONST VOID *lpBuffer, 00411 IN DWORD nNumberOfCharsToWrite, 00412 OUT LPDWORD lpNumberOfCharsWritten, 00413 IN BOOLEAN Unicode 00414 ) 00415 00416 /*++ 00417 Parameters: 00418 00419 hFile - Supplies an open handle to to "CONOUT$" open for GENERIC_WRITE 00420 or the StdOut or StdErr handle. 00421 00422 lpBuffer - Supplies the address of the data that is to be written to 00423 the console output. 00424 00425 nNumberOfBytesToWrite - Supplies the number of bytes to write to the 00426 console output. 00427 00428 Return Value: 00429 00430 NON-NULL - Returns the number of bytes actually written to the device. 00431 00432 FALSE/NULL - The operation failed. 00433 Extended error status is available using GetLastError. 00434 --*/ 00435 00436 { 00437 00438 PCSR_CAPTURE_HEADER CaptureBuffer; 00439 CONSOLE_API_MSG m; 00440 PCONSOLE_WRITECONSOLE_MSG a = &m.u.WriteConsole; 00441 00442 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00443 a->OutputHandle = hConsoleOutput; 00444 00445 if (Unicode) { 00446 a->NumBytes = nNumberOfCharsToWrite * sizeof(WCHAR); 00447 } else { 00448 a->NumBytes = nNumberOfCharsToWrite; 00449 } 00450 00451 a->Unicode = Unicode; 00452 if (a->NumBytes > BUFFER_SIZE) { 00453 CaptureBuffer = CsrAllocateCaptureBuffer( 1, 00454 a->NumBytes 00455 ); 00456 if (CaptureBuffer == NULL) { 00457 SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY); 00458 return FALSE; 00459 } 00460 CsrCaptureMessageBuffer( CaptureBuffer, 00461 (PCHAR) lpBuffer, 00462 a->NumBytes, 00463 (PVOID *) &a->BufPtr 00464 ); 00465 a->BufferInMessage = FALSE; 00466 } 00467 else { 00468 a->BufPtr = a->Buffer; 00469 try { 00470 RtlCopyMemory( a->BufPtr, lpBuffer, a->NumBytes); 00471 } except( EXCEPTION_EXECUTE_HANDLER ) { 00472 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00473 return FALSE; 00474 } 00475 CaptureBuffer = NULL; 00476 a->BufferInMessage = TRUE; 00477 } 00478 CsrClientCallServer( (PCSR_API_MSG)&m, 00479 CaptureBuffer, 00480 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00481 ConsolepWriteConsole 00482 ), 00483 sizeof( *a ) 00484 ); 00485 if (CaptureBuffer != NULL) { 00486 CsrFreeCaptureBuffer( CaptureBuffer ); 00487 } 00488 if (!NT_SUCCESS( m.ReturnValue )) { 00489 SET_LAST_NT_ERROR(m.ReturnValue); 00490 return FALSE; 00491 } 00492 try { 00493 *lpNumberOfCharsWritten = a->NumBytes; 00494 if (Unicode) { 00495 *lpNumberOfCharsWritten /= sizeof(WCHAR); 00496 } 00497 } except( EXCEPTION_EXECUTE_HANDLER ) { 00498 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00499 return FALSE; 00500 } 00501 return TRUE; 00502 00503 } 00504 00505 #endif 00506 00507 #if !defined(BUILD_WOW64) 00508 00509 BOOL 00510 APIENTRY 00511 WriteConsoleA( 00512 IN HANDLE hConsoleOutput, 00513 IN CONST VOID *lpBuffer, 00514 IN DWORD nNumberOfCharsToWrite, 00515 OUT LPDWORD lpNumberOfCharsWritten, 00516 IN OUT LPVOID lpReserved 00517 ) 00518 { 00519 return WriteConsoleInternal(hConsoleOutput, 00520 lpBuffer, 00521 nNumberOfCharsToWrite, 00522 lpNumberOfCharsWritten, 00523 FALSE 00524 ); 00525 UNREFERENCED_PARAMETER(lpReserved); 00526 } 00527 00528 BOOL 00529 APIENTRY 00530 WriteConsoleW( 00531 IN HANDLE hConsoleOutput, 00532 IN CONST VOID *lpBuffer, 00533 IN DWORD nNumberOfCharsToWrite, 00534 OUT LPDWORD lpNumberOfCharsWritten, 00535 IN OUT LPVOID lpReserved 00536 ) 00537 { 00538 return WriteConsoleInternal(hConsoleOutput, 00539 lpBuffer, 00540 nNumberOfCharsToWrite, 00541 lpNumberOfCharsWritten, 00542 TRUE 00543 ); 00544 UNREFERENCED_PARAMETER(lpReserved); 00545 } 00546 00547 #endif 00548 00549 #if !defined(BUILD_WOW6432) 00550 00551 BOOL 00552 APIENTRY 00553 CloseConsoleHandle( 00554 IN HANDLE hConsole 00555 ) 00556 00557 /*++ 00558 00559 Parameters: 00560 00561 hConsole - An open handle to console input or output. 00562 00563 Return Value: 00564 00565 TRUE - The operation was successful. 00566 00567 FALSE/NULL - The operation failed. Extended error status is available 00568 using GetLastError. 00569 00570 --*/ 00571 00572 { 00573 00574 CONSOLE_API_MSG m; 00575 PCONSOLE_CLOSEHANDLE_MSG a = &m.u.CloseHandle; 00576 00577 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00578 a->Handle = hConsole; 00579 CsrClientCallServer( (PCSR_API_MSG)&m, 00580 NULL, 00581 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00582 ConsolepCloseHandle 00583 ), 00584 sizeof( *a ) 00585 ); 00586 if (NT_SUCCESS( m.ReturnValue )) { 00587 return TRUE; 00588 } else { 00589 SET_LAST_NT_ERROR (m.ReturnValue); 00590 return FALSE; 00591 } 00592 00593 } 00594 00595 HANDLE 00596 APIENTRY 00597 DuplicateConsoleHandle( 00598 IN HANDLE hSourceHandle, 00599 IN DWORD dwDesiredAccess, 00600 IN BOOL bInheritHandle, 00601 IN DWORD dwOptions 00602 ) 00603 /*++ 00604 Parameters: 00605 00606 hSourceHandle - An open handle to the console device. 00607 00608 dwDesiredAccess - The access requested to for the new handle. This 00609 access must be equal to or a proper subset of the granted access 00610 associated with the SourceHandle. This parameter is ignored if 00611 the DUPLICATE_SAME_ACCESS option is specified. 00612 00613 bInheritHandle - Supplies a flag that if TRUE, marks the target 00614 handle as inheritable. If this is the case, then the target 00615 handle will be inherited to new processes each time the target 00616 process creates a new process using CreateProcess. 00617 00618 dwOptions - Specifies optional behaviors for the caller. 00619 00620 Options Flags: 00621 00622 DUPLICATE_CLOSE_SOURCE - The SourceHandle will be closed by 00623 this service prior to returning to the caller. This occurs 00624 regardless of any error status returned. 00625 00626 DUPLICATE_SAME_ACCESS - The DesiredAccess parameter is ignored 00627 and instead the GrantedAccess associated with SourceHandle 00628 is used as the DesiredAccess when creating the TargetHandle. 00629 00630 00631 Return Value: 00632 00633 Not -1 - Returns an open handle to the specified console device. 00634 Subsequent access to the file is controlled by the DesiredAccess 00635 parameter. 00636 00637 0xffffffff - The operation failed. Extended error status is available 00638 using GetLastError. 00639 --*/ 00640 00641 { 00642 00643 CONSOLE_API_MSG m; 00644 PCONSOLE_DUPHANDLE_MSG a = &m.u.DuplicateHandle; 00645 00646 if (dwOptions & ~VALID_DUP_OPTIONS) { 00647 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 00648 return (HANDLE) INVALID_HANDLE_VALUE; 00649 } 00650 if (((dwOptions & DUPLICATE_SAME_ACCESS) == 0) && 00651 (dwDesiredAccess & ~VALID_ACCESSES)) { 00652 SET_LAST_ERROR(ERROR_INVALID_PARAMETER); 00653 return (HANDLE) INVALID_HANDLE_VALUE; 00654 } 00655 00656 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00657 a->SourceHandle = hSourceHandle; 00658 a->DesiredAccess = dwDesiredAccess; 00659 a->InheritHandle = (BOOLEAN) bInheritHandle; 00660 a->Options = dwOptions; 00661 CsrClientCallServer( (PCSR_API_MSG)&m, 00662 NULL, 00663 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00664 ConsolepDupHandle 00665 ), 00666 sizeof( *a ) 00667 ); 00668 if (NT_SUCCESS( m.ReturnValue )) { 00669 return a->TargetHandle; 00670 } else { 00671 SET_LAST_NT_ERROR (m.ReturnValue); 00672 return (HANDLE) INVALID_HANDLE_VALUE; 00673 } 00674 00675 } 00676 00677 00678 BOOL 00679 APIENTRY 00680 GetConsoleHandleInformation( 00681 IN HANDLE hObject, 00682 OUT LPDWORD lpdwFlags 00683 ) 00684 00685 /*++ 00686 Parameters: 00687 00688 hObject - An open handle to console input or output. 00689 00690 lpdwFlags - Receives flags for console object. 00691 00692 Return Value: 00693 00694 TRUE - The operation was successful. 00695 00696 FALSE/NULL - The operation failed. Extended error status is available 00697 using GetLastError. 00698 00699 --*/ 00700 00701 { 00702 00703 CONSOLE_API_MSG m; 00704 PCONSOLE_GETHANDLEINFORMATION_MSG a = &m.u.GetHandleInformation; 00705 00706 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00707 a->Handle = hObject; 00708 00709 CsrClientCallServer( (PCSR_API_MSG)&m, 00710 NULL, 00711 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00712 ConsolepGetHandleInformation 00713 ), 00714 sizeof( *a ) 00715 ); 00716 if (NT_SUCCESS( m.ReturnValue )) { 00717 try { 00718 *lpdwFlags = a->Flags; 00719 } except( EXCEPTION_EXECUTE_HANDLER ) { 00720 SET_LAST_ERROR(ERROR_INVALID_ACCESS); 00721 return FALSE; 00722 } 00723 return TRUE; 00724 } else { 00725 SET_LAST_NT_ERROR (m.ReturnValue); 00726 return FALSE; 00727 } 00728 00729 } 00730 00731 00732 BOOL 00733 APIENTRY 00734 SetConsoleHandleInformation( 00735 IN HANDLE hObject, 00736 IN DWORD dwMask, 00737 IN DWORD dwFlags 00738 ) 00739 00740 /*++ 00741 Parameters: 00742 00743 hObject - An open handle to console input or output. 00744 00745 dwMask - Flags to change. 00746 00747 dwFlags - New values for flags. 00748 00749 Return Value: 00750 00751 TRUE - The operation was successful. 00752 00753 FALSE/NULL - The operation failed. Extended error status is available 00754 using GetLastError. 00755 00756 --*/ 00757 00758 { 00759 00760 CONSOLE_API_MSG m; 00761 PCONSOLE_SETHANDLEINFORMATION_MSG a = &m.u.SetHandleInformation; 00762 00763 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00764 a->Handle = hObject; 00765 a->Mask = dwMask; 00766 a->Flags = dwFlags; 00767 00768 CsrClientCallServer( (PCSR_API_MSG)&m, 00769 NULL, 00770 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00771 ConsolepSetHandleInformation 00772 ), 00773 sizeof( *a ) 00774 ); 00775 if (NT_SUCCESS( m.ReturnValue )) { 00776 return TRUE; 00777 } else { 00778 SET_LAST_NT_ERROR (m.ReturnValue); 00779 return FALSE; 00780 } 00781 00782 } 00783 00784 00785 BOOL 00786 APIENTRY 00787 VerifyConsoleIoHandle( 00788 IN HANDLE hIoHandle 00789 ) 00790 00791 /*++ 00792 Parameters: 00793 00794 hIoHandle - Handle to verify 00795 00796 Return Value: 00797 00798 TRUE - handle is a valid console handle. 00799 00800 FALSE - handle is not a valid console handle. 00801 00802 --*/ 00803 00804 { 00805 00806 CONSOLE_API_MSG m; 00807 PCONSOLE_VERIFYIOHANDLE_MSG a = &m.u.VerifyConsoleIoHandle; 00808 00809 a->ConsoleHandle = GET_CONSOLE_HANDLE; 00810 a->Handle = hIoHandle; 00811 00812 // 00813 // If this process doesn't have a console handle, bail immediately. 00814 // 00815 00816 if (a->ConsoleHandle == NULL) { 00817 return FALSE; 00818 } 00819 00820 CsrClientCallServer( (PCSR_API_MSG)&m, 00821 NULL, 00822 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX, 00823 ConsolepVerifyIoHandle 00824 ), 00825 sizeof( *a ) 00826 ); 00827 if (NT_SUCCESS( m.ReturnValue )) { 00828 return a->Valid; 00829 } else { 00830 SET_LAST_NT_ERROR (m.ReturnValue); 00831 return FALSE; 00832 } 00833 00834 00835 } 00836 00837 #endif

Generated on Sat May 15 19:41:53 2004 for test by doxygen 1.3.7