/* * @implemented */ BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions) { NTSTATUS Status; HANDLE hTargetHandle; hSourceHandle = TranslateStdHandle(hSourceHandle); if ((IsConsoleHandle(hSourceHandle)) && ((hSourceHandle != NtCurrentProcess()) && (hSourceHandle != NtCurrentThread()))) { if ((hSourceProcessHandle != NtCurrentProcess()) && (hTargetProcessHandle != NtCurrentProcess())) { BaseSetLastNTError(STATUS_INVALID_PARAMETER); return FALSE; } hTargetHandle = DuplicateConsoleHandle(hSourceHandle, dwDesiredAccess, bInheritHandle, dwOptions); if (hTargetHandle != INVALID_HANDLE_VALUE) { if (lpTargetHandle) *lpTargetHandle = hTargetHandle; return TRUE; } return FALSE; } Status = NtDuplicateObject(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle ? OBJ_INHERIT : 0, dwOptions); if (NT_SUCCESS(Status)) return TRUE; BaseSetLastNTError(Status); return FALSE; }
/* * @implemented */ BOOL WINAPI DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) { DWORD SourceProcessId, TargetProcessId; NTSTATUS Status; hSourceHandle = TranslateStdHandle(hSourceHandle); if (IsConsoleHandle(hSourceHandle)) { SourceProcessId = GetProcessId(hSourceProcessHandle); TargetProcessId = GetProcessId(hTargetProcessHandle); if (!SourceProcessId || !TargetProcessId || SourceProcessId != TargetProcessId || SourceProcessId != GetCurrentProcessId()) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } *lpTargetHandle = DuplicateConsoleHandle(hSourceHandle, dwDesiredAccess, bInheritHandle, dwOptions); return *lpTargetHandle != INVALID_HANDLE_VALUE; } Status = NtDuplicateObject(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle ? OBJ_INHERIT : 0, dwOptions); if (!NT_SUCCESS(Status)) { SetLastErrorByStatus (Status); return FALSE; } return TRUE; }