Index: win/tclWin32Dll.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWin32Dll.c,v
retrieving revision 1.24.2.7
diff -u -r1.24.2.7 tclWin32Dll.c
--- win/tclWin32Dll.c	6 Jun 2005 21:04:47 -0000	1.24.2.7
+++ win/tclWin32Dll.c	3 Nov 2005 10:05:17 -0000
@@ -118,6 +118,8 @@
     (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _utime,
     NULL,
     NULL,
+    (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleA,
+    (BOOL (WINAPI *)(HANDLE, const VOID*, DWORD, LPDWORD, LPVOID)) WriteConsoleA
 };
 
 static TclWinProcs unicodeProcs = {
@@ -167,6 +169,8 @@
     (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _wutime,
     NULL,
     NULL,
+    (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleW,
+    (BOOL (WINAPI *)(HANDLE, const VOID*, DWORD, LPDWORD, LPVOID)) WriteConsoleW
 };
 
 TclWinProcs *tclWinProcs;
Index: win/tclWinConsole.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinConsole.c,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 tclWinConsole.c
--- win/tclWinConsole.c	27 Jan 2005 22:53:37 -0000	1.11.2.1
+++ win/tclWinConsole.c	3 Nov 2005 10:05:18 -0000
@@ -189,6 +189,45 @@
 
 /*
  *----------------------------------------------------------------------
+ * 
+ * readConsoleBytes, writeConsoleBytes --
+ * Wrapper for ReadConsole{A,W}, that takes and returns number of bytes
+ * instead of number of TCHARS
+ */
+static BOOL readConsoleBytes(HANDLE hConsole,
+  LPVOID lpBuffer,
+  DWORD nbytes,
+  LPDWORD nbytesread)
+{
+    DWORD ntchars;
+    BOOL result;
+    int tcharsize;
+    tcharsize = tclWinProcs->useWide? 2 : 1;
+    result = tclWinProcs->readConsoleProc(
+	    hConsole, lpBuffer, nbytes / tcharsize, &ntchars, NULL);
+    if (nbytesread) 
+	*nbytesread = (ntchars*tcharsize);
+    return result;
+}
+
+static BOOL writeConsoleBytes(HANDLE hConsole,
+  const VOID *lpBuffer,
+  DWORD nbytes,
+  LPDWORD nbyteswritten)
+{
+    DWORD ntchars;
+    BOOL result;
+    int tcharsize;
+    tcharsize = tclWinProcs->useWide? 2 : 1;
+    result = tclWinProcs->writeConsoleProc(
+	    hConsole, lpBuffer, nbytes / tcharsize, &ntchars, NULL);
+    if (nbyteswritten) 
+	*nbyteswritten = (ntchars*tcharsize);
+    return result;
+}
+
+/*
+ *----------------------------------------------------------------------
  *
  * ConsoleInit --
  *
@@ -705,8 +744,8 @@
      * at least one byte is available or an EOF occurs.
      */
 
-    if (ReadConsole(infoPtr->handle, (LPVOID) buf, (DWORD) bufSize, &count,
-		    (LPOVERLAPPED) NULL) == TRUE) {
+    if (readConsoleBytes(infoPtr->handle, (LPVOID) buf, (DWORD) bufSize, &count)
+	    == TRUE) {
 	buf[count] = '\0';
 	return count;
     }
@@ -792,8 +831,8 @@
 	 * This avoids an unnecessary copy.
 	 */
 
-	if (WriteFile(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite,
-		&bytesWritten, (LPOVERLAPPED) NULL) == FALSE) {
+	if (writeConsoleBytes(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite,
+		&bytesWritten) == FALSE) {
 	    TclWinConvertError(GetLastError());
 	    goto error;
 	}
@@ -1144,8 +1183,8 @@
 	 * Look for data on the console, but first ignore any events
 	 * that are not KEY_EVENTs 
 	 */
-	if (ReadConsoleA(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE,
-		(LPDWORD) &infoPtr->bytesRead, NULL) != FALSE) {
+	if (readConsoleBytes(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE,
+		(LPDWORD) &infoPtr->bytesRead) != FALSE) {
 	    /*
 	     * Data was stored in the buffer.
 	     */
@@ -1240,7 +1279,8 @@
 	 */
 
 	while (toWrite > 0) {
-	    if (WriteConsoleA(handle, buf, toWrite, &count, NULL) == FALSE) {
+	    if (writeConsoleBytes(handle, buf, toWrite, &count)
+		    == FALSE) {
 		infoPtr->writeError = GetLastError();
 		break;
 	    } else {
@@ -1367,7 +1407,10 @@
     
     Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto");
     Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}");
-    Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding);
+    if (tclWinProcs->useWide)
+	Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", "unicode");
+    else
+	Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding);
 
     return infoPtr->channel;
 }
Index: win/tclWinInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinInt.h,v
retrieving revision 1.20.2.3
diff -u -r1.20.2.3 tclWinInt.h
--- win/tclWinInt.h	3 May 2004 18:01:37 -0000	1.20.2.3
+++ win/tclWinInt.h	3 Nov 2005 10:05:18 -0000
@@ -111,6 +111,21 @@
 					 LPVOID, UINT,
 					 LPVOID, DWORD);
     BOOL (WINAPI *getVolumeNameForVMPProc)(CONST TCHAR*, TCHAR*, DWORD);
+    /* Console I/O with unicode support */
+    BOOL (WINAPI *readConsoleProc)(
+      HANDLE hConsoleInput,
+      LPVOID lpBuffer,
+      DWORD nNumberOfCharsToRead,
+      LPDWORD lpNumberOfCharsRead,
+      LPVOID lpReserved
+    );
+    BOOL (WINAPI *writeConsoleProc)(
+      HANDLE hConsoleOutput,
+      const VOID* lpBuffer,
+      DWORD nNumberOfCharsToWrite,
+      LPDWORD lpNumberOfCharsWritten,
+      LPVOID lpReserved
+    );
 } TclWinProcs;
 
 EXTERN TclWinProcs *tclWinProcs;
