Converted to the new debug interface, using script written by Patrik
[wine/multimedia.git] / win32 / console.c
blobc6d711769cea90f11dabd0846559eb8d63481bf4
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 */
10 /* FIXME:
11 * - Completely lacks SCREENBUFFER interface.
12 * - No abstraction for something other than xterm.
13 * - Key input translation shouldn't use VkKeyScan and MapVirtualKey, since
14 * they are window (USER) driver dependend.
15 * - Output sometimes is buffered (We switched off buffering by ~ICANON ?)
17 /* Reference applications:
18 * - IDA (interactive disassembler) full version 3.75. Works.
19 * - LYNX/W32. Works mostly, some keys crash it.
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <termios.h>
25 #include <string.h>
26 #include <sys/ioctl.h>
27 #include <sys/types.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <sys/errno.h>
33 #include <signal.h>
34 #include <assert.h>
36 #include "winbase.h"
37 #include "wine/winuser16.h"
38 #include "wine/keyboard16.h"
39 #include "thread.h"
40 #include "async.h"
41 #include "file.h"
42 #include "process.h"
43 #include "winerror.h"
44 #include "wincon.h"
45 #include "heap.h"
46 #include "debugtools.h"
48 #include "server/request.h"
49 #include "server.h"
51 DEFAULT_DEBUG_CHANNEL(console)
54 /* FIXME: Should be in an internal header file. OK, so which one?
55 Used by CONSOLE_makecomplex. */
56 FILE *wine_openpty(int *master, int *slave, char *name,
57 struct termios *term, struct winsize *winsize);
59 /****************************************************************************
60 * CONSOLE_GetInfo
62 static BOOL CONSOLE_GetInfo( HANDLE handle, struct get_console_info_reply *reply )
64 struct get_console_info_request req;
66 req.handle = handle;
67 CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) );
68 return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL );
71 /****************************************************************************
72 * XTERM_string_to_IR [internal]
74 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
75 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
77 static void
78 CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
79 int j,k;
80 INPUT_RECORD ir;
81 DWORD junk;
83 for (j=0;j<len;j++) {
84 unsigned char inchar = buf[j];
86 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
87 ir.EventType = 1; /* Key_event */
89 ir.Event.KeyEvent.bKeyDown = 1;
90 ir.Event.KeyEvent.wRepeatCount = 0;
92 ir.Event.KeyEvent.dwControlKeyState = 0;
93 if (inchar & 0x80) {
94 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
95 inchar &= ~0x80;
97 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(inchar);
98 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
99 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
100 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
101 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
102 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
103 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
104 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
105 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
106 0 /* VirtualKeyCodes to ScanCode */
108 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
110 if (inchar==127) { /* backspace */
111 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
112 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
113 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
114 } else {
115 if (inchar=='\n') {
116 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
117 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
118 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
119 } else {
120 if (inchar<' ') {
121 /* FIXME: find good values for ^X */
122 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
123 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
128 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
129 ir.Event.KeyEvent.bKeyDown = 0;
130 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
131 continue;
133 /* inchar is ESC */
134 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
135 ir.EventType = 1; /* Key_event */
136 ir.Event.KeyEvent.bKeyDown = 1;
137 ir.Event.KeyEvent.wRepeatCount = 0;
139 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(27);
140 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
141 ir.Event.KeyEvent.wVirtualKeyCode,0
143 ir.Event.KeyEvent.dwControlKeyState = 0;
144 ir.Event.KeyEvent.uChar.AsciiChar = 27;
145 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
146 ir.Event.KeyEvent.bKeyDown = 0;
147 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
148 continue;
150 for (k=j;k<len;k++) {
151 if (((buf[k]>='A') && (buf[k]<='Z')) ||
152 ((buf[k]>='a') && (buf[k]<='z')) ||
153 (buf[k]=='~')
155 break;
157 if (k<len) {
158 int subid,scancode=0;
160 ir.EventType = 1; /* Key_event */
161 ir.Event.KeyEvent.bKeyDown = 1;
162 ir.Event.KeyEvent.wRepeatCount = 0;
163 ir.Event.KeyEvent.dwControlKeyState = 0;
165 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
166 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
167 ir.Event.KeyEvent.uChar.AsciiChar = 0;
169 switch (buf[k]) {
170 case '~':
171 sscanf(&buf[j+2],"%d",&subid);
172 switch (subid) {
173 case 2:/*INS */scancode = 0xe052;break;
174 case 3:/*DEL */scancode = 0xe053;break;
175 case 6:/*PGDW*/scancode = 0xe051;break;
176 case 5:/*PGUP*/scancode = 0xe049;break;
177 case 11:/*F1 */scancode = 0x003b;break;
178 case 12:/*F2 */scancode = 0x003c;break;
179 case 13:/*F3 */scancode = 0x003d;break;
180 case 14:/*F4 */scancode = 0x003e;break;
181 case 15:/*F5 */scancode = 0x003f;break;
182 case 17:/*F6 */scancode = 0x0040;break;
183 case 18:/*F7 */scancode = 0x0041;break;
184 case 19:/*F8 */scancode = 0x0042;break;
185 case 20:/*F9 */scancode = 0x0043;break;
186 case 21:/*F10 */scancode = 0x0044;break;
187 case 23:/*F11 */scancode = 0x00d9;break;
188 case 24:/*F12 */scancode = 0x00da;break;
189 /* FIXME: Shift-Fx */
190 default:
191 FIXME("parse ESC[%d~\n",subid);
192 break;
194 break;
195 case 'A': /* Cursor Up */scancode = 0xe048;break;
196 case 'B': /* Cursor Down */scancode = 0xe050;break;
197 case 'D': /* Cursor Left */scancode = 0xe04b;break;
198 case 'C': /* Cursor Right */scancode = 0xe04d;break;
199 case 'F': /* End */scancode = 0xe04f;break;
200 case 'H': /* Home */scancode = 0xe047;break;
201 case 'M':
202 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
203 * Release (ESCM#<x+'!'><y+'!'>
205 if (k<len-3) {
206 ir.EventType = MOUSE_EVENT;
207 ir.Event.MouseEvent.dwMousePosition.x = buf[k+2]-'!';
208 ir.Event.MouseEvent.dwMousePosition.y = buf[k+3]-'!';
209 if (buf[k+1]=='#')
210 ir.Event.MouseEvent.dwButtonState = 0;
211 else
212 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
213 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
214 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
215 j=k+3;
217 break;
218 case 'c':
219 j=k;
220 break;
222 if (scancode) {
223 ir.Event.KeyEvent.wVirtualScanCode = scancode;
224 ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
225 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
226 ir.Event.KeyEvent.bKeyDown = 0;
227 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
228 j=k;
229 continue;
235 /****************************************************************************
236 * CONSOLE_get_input (internal)
238 * Reads (nonblocking) as much input events as possible and stores them
239 * in an internal queue.
241 static void
242 CONSOLE_get_input( HANDLE handle, BOOL blockwait )
244 char *buf = HeapAlloc(GetProcessHeap(),0,1);
245 int len = 0;
247 while (1)
249 DWORD res;
250 char inchar;
251 if (WaitForSingleObject( handle, 0 )) break;
252 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
253 if (!res) /* res 0 but readable means EOF? Hmm. */
254 break;
255 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
256 buf[len++]=inchar;
258 CONSOLE_string_to_IR(handle,buf,len);
259 HeapFree(GetProcessHeap(),0,buf);
262 /******************************************************************************
263 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
265 * PARAMS
266 * func [I] Address of handler function
267 * add [I] Handler to add or remove
269 * RETURNS
270 * Success: TRUE
271 * Failure: FALSE
273 * CHANGED
274 * James Sutherland (JamesSutherland@gmx.de)
275 * Added global variables console_ignore_ctrl_c and handlers[]
276 * Does not yet do any error checking, or set LastError if failed.
277 * This doesn't yet matter, since these handlers are not yet called...!
279 static unsigned int console_ignore_ctrl_c = 0;
280 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
281 BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
283 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
284 unsigned int done = 0;
285 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
286 if (!func)
288 console_ignore_ctrl_c = add;
289 return TRUE;
291 if (add)
293 for (;alloc_loop--;)
294 if (!handlers[alloc_loop] && !done)
296 handlers[alloc_loop] = func;
297 done++;
299 if (!done)
300 FIXME("Out of space on CtrlHandler table\n");
301 return(done);
303 else
305 for (;alloc_loop--;)
306 if (handlers[alloc_loop] == func && !done)
308 handlers[alloc_loop] = 0;
309 done++;
311 if (!done)
312 WARN("Attempt to remove non-installed CtrlHandler %p\n",
313 func);
314 return (done);
316 return (done);
320 /******************************************************************************
321 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
323 * PARAMS
324 * dwCtrlEvent [I] Type of event
325 * dwProcessGroupID [I] Process group ID to send event to
327 * NOTES
328 * Doesn't yet work...!
330 * RETURNS
331 * Success: True
332 * Failure: False (and *should* [but doesn't] set LastError)
334 BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
335 DWORD dwProcessGroupID )
337 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
339 ERR("invalid event %d for PGID %ld\n",
340 (unsigned short)dwCtrlEvent, dwProcessGroupID );
341 return FALSE;
343 if (dwProcessGroupID == GetCurrentProcessId() )
345 FIXME("Attempt to send event %d to self - stub\n",
346 (unsigned short)dwCtrlEvent );
347 return FALSE;
349 FIXME("event %d to external PGID %ld - not implemented yet\n",
350 (unsigned short)dwCtrlEvent, dwProcessGroupID );
351 return FALSE;
355 /******************************************************************************
356 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
358 * PARAMS
359 * dwDesiredAccess [I] Access flag
360 * dwShareMode [I] Buffer share mode
361 * sa [I] Security attributes
362 * dwFlags [I] Type of buffer to create
363 * lpScreenBufferData [I] Reserved
365 * NOTES
366 * Should call SetLastError
368 * RETURNS
369 * Success: Handle to new console screen buffer
370 * Failure: INVALID_HANDLE_VALUE
372 HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
373 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
374 DWORD dwFlags, LPVOID lpScreenBufferData )
376 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
377 dwShareMode, sa, dwFlags, lpScreenBufferData);
378 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
379 return INVALID_HANDLE_VALUE;
383 /***********************************************************************
384 * GetConsoleScreenBufferInfo (KERNEL32.190)
386 BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
387 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
389 csbi->dwSize.x = 80;
390 csbi->dwSize.y = 24;
391 csbi->dwCursorPosition.x = 0;
392 csbi->dwCursorPosition.y = 0;
393 csbi->wAttributes = 0;
394 csbi->srWindow.Left = 0;
395 csbi->srWindow.Right = 79;
396 csbi->srWindow.Top = 0;
397 csbi->srWindow.Bottom = 23;
398 csbi->dwMaximumWindowSize.x = 80;
399 csbi->dwMaximumWindowSize.y = 24;
400 return TRUE;
404 /******************************************************************************
405 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
407 * RETURNS
408 * Success: TRUE
409 * Failure: FALSE
411 BOOL WINAPI SetConsoleActiveScreenBuffer(
412 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
414 FIXME("(%x): stub\n", hConsoleOutput);
415 return FALSE;
419 /***********************************************************************
420 * GetLargestConsoleWindowSize (KERNEL32.226)
422 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
424 return (DWORD)MAKELONG(80,24);
427 /***********************************************************************
428 * FreeConsole (KERNEL32.267)
430 BOOL WINAPI FreeConsole(VOID)
432 struct free_console_request req;
433 CLIENT_SendRequest( REQ_FREE_CONSOLE, -1, 1, &req, sizeof(req) );
434 return !CLIENT_WaitReply( NULL, NULL, 0 );
438 /*************************************************************************
439 * CONSOLE_OpenHandle
441 * Open a handle to the current process console.
443 HANDLE CONSOLE_OpenHandle( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES sa )
445 struct open_console_request req;
446 struct open_console_reply reply;
448 req.output = output;
449 req.access = access;
450 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
451 CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) );
452 SetLastError(0);
453 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
454 return reply.handle;
458 /*************************************************************************
459 * CONSOLE_make_complex [internal]
461 * Turns a CONSOLE kernel object into a complex one.
462 * (switches from output/input using the terminal where WINE was started to
463 * its own xterm).
465 * This makes simple commandline tools pipeable, while complex commandline
466 * tools work without getting messed up by debugoutput.
468 * All other functions should work indedependend from this call.
470 * To test for complex console: pid == 0 -> simple, otherwise complex.
472 static BOOL CONSOLE_make_complex(HANDLE handle)
474 struct set_console_fd_request req;
475 struct get_console_info_reply info;
476 struct termios term;
477 char buf[256];
478 char c = '\0';
479 int status = 0;
480 int i,xpid,master,slave;
481 DWORD xlen;
483 if (!CONSOLE_GetInfo( handle, &info )) return FALSE;
484 if (info.pid) return TRUE; /* already complex */
486 MESSAGE("Console: Making console complex (creating an xterm)...\n");
488 if (tcgetattr(0, &term) < 0) {
489 /* ignore failure, or we can't run from a script */
491 term.c_lflag = ~(ECHO|ICANON);
493 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
494 return FALSE;
496 if ((xpid=fork()) == 0) {
497 tcsetattr(slave, TCSADRAIN, &term);
498 sprintf(buf, "-Sxx%d", master);
499 /* "-fn vga" for VGA font. Harmless if vga is not present:
500 * xterm: unable to open font "vga", trying "fixed"....
502 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
503 ERR("error creating AllocConsole xterm\n");
504 exit(1);
507 req.handle = handle;
508 req.pid = xpid;
509 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(slave), 1, &req, sizeof(req) );
510 CLIENT_WaitReply( NULL, NULL, 0 );
512 /* most xterms like to print their window ID when used with -S;
513 * read it and continue before the user has a chance...
515 for (i=0; c!='\n'; (status=read(slave, &c, 1)), i++) {
516 if (status == -1 && c == '\0') {
517 /* wait for xterm to be created */
518 usleep(100);
520 if (i > 10000) {
521 ERR("can't read xterm WID\n");
522 kill(xpid, SIGKILL);
523 return FALSE;
526 /* enable mouseclicks */
527 sprintf(buf,"%c[?1001s%c[?1000h",27,27);
528 WriteFile(handle,buf,strlen(buf),&xlen,NULL);
530 if (GetConsoleTitleA( buf, sizeof(buf) ))
532 WriteFile(handle,"\033]2;",4,&xlen,NULL);
533 WriteFile(handle,buf,strlen(buf),&xlen,NULL);
534 WriteFile(handle,"\a",1,&xlen,NULL);
536 return TRUE;
541 /***********************************************************************
542 * AllocConsole (KERNEL32.103)
544 * creates an xterm with a pty to our program
546 BOOL WINAPI AllocConsole(VOID)
548 struct open_console_request req;
549 struct open_console_reply reply;
550 HANDLE hIn, hOut, hErr;
551 DWORD ret;
553 TRACE("()\n");
554 CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 1, &req, sizeof(req) );
555 ret = CLIENT_WaitReply( NULL, NULL, 0 );
556 if (ret != ERROR_SUCCESS) {
557 /* Hmm, error returned by server when we already have an
558 * opened console. however, we might have inherited it(?)
559 * and our handles are wrong? puzzling -MM 990330
561 if (ret!=ERROR_ACCESS_DENIED) {
562 ERR(" failed to allocate console: %ld\n",ret);
563 return FALSE;
567 req.output = 0;
568 req.access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
569 req.inherit = FALSE;
570 CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) );
571 ret =CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
572 if (ret != ERROR_SUCCESS)
574 /* FIXME: free console */
575 ERR(" open console error %ld\n",ret);
576 return FALSE;
578 hIn = reply.handle;
580 req.output = 1;
581 CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) );
582 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS)
584 CloseHandle(hIn);
585 /* FIXME: free console */
586 return FALSE;
588 hOut = reply.handle;
590 if (!DuplicateHandle( GetCurrentProcess(), hOut,
591 GetCurrentProcess(), &hErr,
592 0, TRUE, DUPLICATE_SAME_ACCESS ))
594 CloseHandle(hIn);
595 CloseHandle(hOut);
596 return FALSE;
599 /* NT resets the STD_*_HANDLEs on console alloc */
600 SetStdHandle(STD_INPUT_HANDLE, hIn);
601 SetStdHandle(STD_OUTPUT_HANDLE, hOut);
602 SetStdHandle(STD_ERROR_HANDLE, hErr);
604 SetLastError(ERROR_SUCCESS);
605 SetConsoleTitleA("Wine Console");
606 return TRUE;
610 /******************************************************************************
611 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
613 * RETURNS
614 * Code page code
616 UINT WINAPI GetConsoleCP(VOID)
618 return GetACP();
622 /***********************************************************************
623 * GetConsoleOutputCP (KERNEL32.189)
625 UINT WINAPI GetConsoleOutputCP(VOID)
627 return GetConsoleCP();
630 /***********************************************************************
631 * GetConsoleMode (KERNEL32.188)
633 BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
635 struct get_console_mode_request req;
636 struct get_console_mode_reply reply;
638 req.handle = hcon;
639 CLIENT_SendRequest( REQ_GET_CONSOLE_MODE, -1, 1, &req, sizeof(req));
640 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
641 *mode = reply.mode;
642 return TRUE;
646 /******************************************************************************
647 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
649 * PARAMS
650 * hcon [I] Handle to console input or screen buffer
651 * mode [I] Input or output mode to set
653 * RETURNS
654 * Success: TRUE
655 * Failure: FALSE
657 BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
659 struct set_console_mode_request req;
661 req.handle = hcon;
662 req.mode = mode;
663 CLIENT_SendRequest( REQ_SET_CONSOLE_MODE, -1, 1, &req, sizeof(req));
664 return !CLIENT_WaitReply( NULL, NULL, 0 );
668 /***********************************************************************
669 * GetConsoleTitleA (KERNEL32.191)
671 DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
673 struct get_console_info_request req;
674 struct get_console_info_reply reply;
675 int len;
676 DWORD ret = 0;
677 HANDLE hcon;
679 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
680 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
681 return 0;
682 req.handle = hcon;
683 CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) );
684 if (!CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply), title, size ))
686 if (len > sizeof(reply)+size) title[size-1] = 0;
687 ret = strlen(title);
689 CloseHandle( hcon );
690 return ret;
694 /******************************************************************************
695 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
697 * PARAMS
698 * title [O] Address of buffer for title
699 * size [I] Size of buffer
701 * RETURNS
702 * Success: Length of string copied
703 * Failure: 0
705 DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
707 char *tmp;
708 DWORD ret;
710 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size ))) return 0;
711 ret = GetConsoleTitleA( tmp, size );
712 lstrcpyAtoW( title, tmp );
713 HeapFree( GetProcessHeap(), 0, tmp );
714 return ret;
718 /***********************************************************************
719 * WriteConsoleA (KERNEL32.729)
721 BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
722 LPCVOID lpBuffer,
723 DWORD nNumberOfCharsToWrite,
724 LPDWORD lpNumberOfCharsWritten,
725 LPVOID lpReserved )
727 /* FIXME: should I check if this is a console handle? */
728 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
729 lpNumberOfCharsWritten, NULL);
733 #define CADD(c) \
734 if (bufused==curbufsize-1) \
735 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
736 buffer[bufused++]=c;
737 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
739 /***********************************************************************
740 * WriteConsoleOutputA (KERNEL32.732)
742 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
743 LPCHAR_INFO lpBuffer,
744 COORD dwBufferSize,
745 COORD dwBufferCoord,
746 LPSMALL_RECT lpWriteRegion)
748 int i,j,off=0,lastattr=-1;
749 char sbuf[20],*buffer=NULL;
750 int bufused=0,curbufsize = 100;
751 DWORD res;
752 const int colormap[8] = {
753 0,4,2,6,
754 1,5,3,7,
756 CONSOLE_make_complex(hConsoleOutput);
757 buffer = HeapAlloc(GetProcessHeap(),0,100);;
758 curbufsize = 100;
760 TRACE("wr: top = %d, bottom=%d, left=%d,right=%d\n",
761 lpWriteRegion->Top,
762 lpWriteRegion->Bottom,
763 lpWriteRegion->Left,
764 lpWriteRegion->Right
767 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
768 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
769 SADD(sbuf);
770 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
771 if (lastattr!=lpBuffer[off].Attributes) {
772 lastattr = lpBuffer[off].Attributes;
773 sprintf(sbuf,"%c[0;%s3%d;4%dm",
775 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
776 colormap[lastattr&7],
777 colormap[(lastattr&0x70)>>4]
779 /* FIXME: BACKGROUND_INTENSITY */
780 SADD(sbuf);
782 CADD(lpBuffer[off].Char.AsciiChar);
783 off++;
786 sprintf(sbuf,"%c[0m",27);SADD(sbuf);
787 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
788 HeapFree(GetProcessHeap(),0,buffer);
789 return TRUE;
792 /***********************************************************************
793 * WriteConsoleW (KERNEL32.577)
795 BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
796 LPCVOID lpBuffer,
797 DWORD nNumberOfCharsToWrite,
798 LPDWORD lpNumberOfCharsWritten,
799 LPVOID lpReserved )
801 BOOL ret;
802 LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite );
804 lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite);
806 /* FIXME: should I check if this is a console handle? */
807 ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite,
808 lpNumberOfCharsWritten, NULL);
809 HeapFree( GetProcessHeap(), 0, xstring );
810 return ret;
814 /***********************************************************************
815 * ReadConsoleA (KERNEL32.419)
817 BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
818 LPVOID lpBuffer,
819 DWORD nNumberOfCharsToRead,
820 LPDWORD lpNumberOfCharsRead,
821 LPVOID lpReserved )
823 int charsread = 0;
824 LPSTR xbuf = (LPSTR)lpBuffer;
825 struct read_console_input_request req;
826 INPUT_RECORD ir;
828 TRACE("(%d,%p,%ld,%p,%p)\n",
829 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
830 lpNumberOfCharsRead,lpReserved
833 CONSOLE_get_input(hConsoleInput,FALSE);
835 req.handle = hConsoleInput;
836 req.count = 1;
837 req.flush = 1;
839 /* FIXME: should we read at least 1 char? The SDK does not say */
840 while (charsread<nNumberOfCharsToRead)
842 int len;
844 CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
845 if (CLIENT_WaitReply( &len, NULL, 1, &ir, sizeof(ir) ))
846 return FALSE;
847 assert( !(len % sizeof(ir)) );
848 if (!len) break;
849 if (!ir.Event.KeyEvent.bKeyDown)
850 continue;
851 if (ir.EventType != KEY_EVENT)
852 continue;
853 *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
854 charsread++;
856 if (lpNumberOfCharsRead)
857 *lpNumberOfCharsRead = charsread;
858 return TRUE;
861 /***********************************************************************
862 * ReadConsoleW (KERNEL32.427)
864 BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
865 LPVOID lpBuffer,
866 DWORD nNumberOfCharsToRead,
867 LPDWORD lpNumberOfCharsRead,
868 LPVOID lpReserved )
870 BOOL ret;
871 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
873 ret = ReadConsoleA(
874 hConsoleInput,
875 buf,
876 nNumberOfCharsToRead,
877 lpNumberOfCharsRead,
878 lpReserved
880 if (ret)
881 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
882 HeapFree( GetProcessHeap(), 0, buf );
883 return ret;
887 /******************************************************************************
888 * ReadConsoleInput32A [KERNEL32.569] Reads data from a console
890 * PARAMS
891 * hConsoleInput [I] Handle to console input buffer
892 * lpBuffer [O] Address of buffer for read data
893 * nLength [I] Number of records to read
894 * lpNumberOfEventsRead [O] Address of number of records read
896 * RETURNS
897 * Success: TRUE
898 * Failure: FALSE
900 BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput,
901 LPINPUT_RECORD lpBuffer,
902 DWORD nLength, LPDWORD lpNumberOfEventsRead)
904 struct read_console_input_request req;
905 int len;
907 req.handle = hConsoleInput;
908 req.count = nLength;
909 req.flush = 1;
911 /* loop until we get at least one event */
912 for (;;)
914 CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
915 if (CLIENT_WaitReply( &len, NULL, 1, lpBuffer, nLength * sizeof(*lpBuffer) ))
916 return FALSE;
917 assert( !(len % sizeof(INPUT_RECORD)) );
918 if (len) break;
919 CONSOLE_get_input(hConsoleInput,TRUE);
920 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
922 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = len / sizeof(INPUT_RECORD);
923 return TRUE;
927 /***********************************************************************
928 * ReadConsoleInput32W (KERNEL32.570)
930 BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
931 DWORD count, LPDWORD read )
933 /* FIXME: Fix this if we get UNICODE input. */
934 return ReadConsoleInputA( handle, buffer, count, read );
938 /***********************************************************************
939 * FlushConsoleInputBuffer (KERNEL32.132)
941 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
943 struct read_console_input_request req;
944 int len;
946 req.handle = handle;
947 req.count = -1; /* get all records */
948 req.flush = 1;
949 CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
950 return !CLIENT_WaitReply( &len, NULL, 0 );
954 /***********************************************************************
955 * PeekConsoleInputA (KERNEL32.550)
957 * Gets 'count' first events (or less) from input queue.
959 * Does not need a complex console.
961 BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer,
962 DWORD count, LPDWORD read )
964 struct read_console_input_request req;
965 int len;
967 CONSOLE_get_input(handle,FALSE);
968 req.handle = handle;
969 req.count = count;
970 req.flush = 0;
972 CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
973 if (CLIENT_WaitReply( &len, NULL, 1, buffer, count * sizeof(*buffer) ))
974 return FALSE;
975 assert( !(len % sizeof(INPUT_RECORD)) );
976 if (read) *read = len / sizeof(INPUT_RECORD);
977 return TRUE;
981 /***********************************************************************
982 * PeekConsoleInputW (KERNEL32.551)
984 BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
985 LPINPUT_RECORD pirBuffer,
986 DWORD cInRecords,
987 LPDWORD lpcRead)
989 /* FIXME: Hmm. Fix this if we get UNICODE input. */
990 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
994 /******************************************************************************
995 * WriteConsoleInput32A [KERNEL32.730] Write data to a console input buffer
998 BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
999 DWORD count, LPDWORD written )
1001 struct write_console_input_request req;
1002 struct write_console_input_reply reply;
1004 req.handle = handle;
1005 req.count = count;
1006 CLIENT_SendRequest( REQ_WRITE_CONSOLE_INPUT, -1, 2, &req, sizeof(req),
1007 buffer, count * sizeof(*buffer) );
1008 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
1009 if (written) *written = reply.written;
1010 return TRUE;
1014 /***********************************************************************
1015 * SetConsoleTitle32A (KERNEL32.476)
1017 * Sets the console title.
1019 * We do not necessarily need to create a complex console for that,
1020 * but should remember the title and set it on creation of the latter.
1021 * (not fixed at this time).
1023 BOOL WINAPI SetConsoleTitleA(LPCSTR title)
1025 struct set_console_info_request req;
1026 struct get_console_info_reply info;
1027 HANDLE hcon;
1028 DWORD written;
1030 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1031 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
1032 return FALSE;
1033 req.handle = hcon;
1034 req.mask = SET_CONSOLE_INFO_TITLE;
1035 CLIENT_SendRequest( REQ_SET_CONSOLE_INFO, -1, 2, &req, sizeof(req),
1036 title, strlen(title)+1 );
1037 if (CLIENT_WaitReply( NULL, NULL, 0 )) goto error;
1038 if (CONSOLE_GetInfo( hcon, &info ) && info.pid)
1040 /* only set title for complex console (own xterm) */
1041 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1042 WriteFile( hcon, title, strlen(title), &written, NULL );
1043 WriteFile( hcon, "\a", 1, &written, NULL );
1045 CloseHandle( hcon );
1046 return TRUE;
1047 error:
1048 CloseHandle( hcon );
1049 return FALSE;
1053 /******************************************************************************
1054 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
1056 * PARAMS
1057 * title [I] Address of new title
1059 * NOTES
1060 * This should not be calling the A version
1062 * RETURNS
1063 * Success: TRUE
1064 * Failure: FALSE
1066 BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
1068 BOOL ret;
1070 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1071 ret = SetConsoleTitleA(titleA);
1072 HeapFree( GetProcessHeap(), 0, titleA );
1073 return ret;
1076 /******************************************************************************
1077 * SetConsoleCursorPosition [KERNEL32.627]
1078 * Sets the cursor position in console
1080 * PARAMS
1081 * hConsoleOutput [I] Handle of console screen buffer
1082 * dwCursorPosition [I] New cursor position coordinates
1084 * RETURNS STD
1086 BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
1088 char xbuf[20];
1089 DWORD xlen;
1091 /* make console complex only if we change lines, not just in the line */
1092 if (pos.y)
1093 CONSOLE_make_complex(hcon);
1095 TRACE("%d (%dx%d)\n", hcon, pos.x , pos.y );
1096 /* x are columns, y rows */
1097 if (pos.y)
1098 /* full screen cursor absolute positioning */
1099 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.y+1, pos.x+1);
1100 else
1101 /* relative cursor positioning in line (\r to go to 0) */
1102 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.x);
1103 /* FIXME: store internal if we start using own console buffers */
1104 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1105 return TRUE;
1108 /***********************************************************************
1109 * GetNumberOfConsoleInputEvents (KERNEL32.246)
1111 BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
1113 CONSOLE_get_input(hcon,FALSE);
1114 *nrofevents = 1; /* UMM */
1115 return TRUE;
1118 /***********************************************************************
1119 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1121 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1123 FIXME("(%p): stub\n", nrofbuttons);
1124 *nrofbuttons = 2;
1125 return TRUE;
1128 /******************************************************************************
1129 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
1131 * PARAMS
1132 * hcon [I] Handle to console screen buffer
1133 * cinfo [O] Address of cursor information
1135 * RETURNS
1136 * Success: TRUE
1137 * Failure: FALSE
1139 BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon,
1140 LPCONSOLE_CURSOR_INFO cinfo )
1142 struct get_console_info_reply reply;
1144 if (!CONSOLE_GetInfo( hcon, &reply )) return FALSE;
1145 if (cinfo)
1147 cinfo->dwSize = reply.cursor_size;
1148 cinfo->bVisible = reply.cursor_visible;
1150 return TRUE;
1154 /******************************************************************************
1155 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
1157 * RETURNS
1158 * Success: TRUE
1159 * Failure: FALSE
1161 BOOL WINAPI SetConsoleCursorInfo(
1162 HANDLE hcon, /* [in] Handle to console screen buffer */
1163 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1165 struct set_console_info_request req;
1166 char buf[8];
1167 DWORD xlen;
1169 req.handle = hcon;
1170 CONSOLE_make_complex(hcon);
1171 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
1172 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1174 req.cursor_size = cinfo->dwSize;
1175 req.cursor_visible = cinfo->bVisible;
1176 req.mask = SET_CONSOLE_INFO_CURSOR;
1177 CLIENT_SendRequest( REQ_SET_CONSOLE_INFO, -1, 1, &req, sizeof(req) );
1178 return !CLIENT_WaitReply( NULL, NULL, 0 );
1182 /******************************************************************************
1183 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1185 * RETURNS
1186 * Success: TRUE
1187 * Failure: FALSE
1189 BOOL WINAPI SetConsoleWindowInfo(
1190 HANDLE hcon, /* [in] Handle to console screen buffer */
1191 BOOL bAbsolute, /* [in] Coordinate type flag */
1192 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1194 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1195 return TRUE;
1199 /******************************************************************************
1200 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
1202 * Sets the foreground and background color attributes of characters
1203 * written to the screen buffer.
1205 * RETURNS
1206 * Success: TRUE
1207 * Failure: FALSE
1209 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
1211 const int colormap[8] = {
1212 0,4,2,6,
1213 1,5,3,7,
1215 DWORD xlen;
1216 char buffer[20];
1218 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
1219 sprintf(buffer,"%c[0;%s3%d;4%dm",
1221 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1222 colormap[wAttr&7],
1223 colormap[(wAttr&0x70)>>4]
1225 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1226 return TRUE;
1230 /******************************************************************************
1231 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1233 * PARAMS
1234 * hConsoleOutput [I] Handle to console screen buffer
1235 * dwSize [I] New size in character rows and cols
1237 * RETURNS
1238 * Success: TRUE
1239 * Failure: FALSE
1241 BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
1242 COORD dwSize )
1244 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.x,dwSize.y);
1245 return TRUE;
1249 /******************************************************************************
1250 * FillConsoleOutputCharacterA [KERNEL32.242]
1252 * PARAMS
1253 * hConsoleOutput [I] Handle to screen buffer
1254 * cCharacter [I] Character to write
1255 * nLength [I] Number of cells to write to
1256 * dwCoord [I] Coords of first cell
1257 * lpNumCharsWritten [O] Pointer to number of cells written
1259 * RETURNS
1260 * Success: TRUE
1261 * Failure: FALSE
1263 BOOL WINAPI FillConsoleOutputCharacterA(
1264 HANDLE hConsoleOutput,
1265 BYTE cCharacter,
1266 DWORD nLength,
1267 COORD dwCoord,
1268 LPDWORD lpNumCharsWritten)
1270 long count;
1271 DWORD xlen;
1273 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1274 for(count=0;count<nLength;count++)
1275 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1276 *lpNumCharsWritten = nLength;
1277 return TRUE;
1281 /******************************************************************************
1282 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1284 * PARAMS
1285 * hConsoleOutput [I] Handle to screen buffer
1286 * cCharacter [I] Character to write
1287 * nLength [I] Number of cells to write to
1288 * dwCoord [I] Coords of first cell
1289 * lpNumCharsWritten [O] Pointer to number of cells written
1291 * RETURNS
1292 * Success: TRUE
1293 * Failure: FALSE
1295 BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
1296 WCHAR cCharacter,
1297 DWORD nLength,
1298 COORD dwCoord,
1299 LPDWORD lpNumCharsWritten)
1301 long count;
1302 DWORD xlen;
1304 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1305 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1306 * first
1308 for(count=0;count<nLength;count++)
1309 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1310 *lpNumCharsWritten = nLength;
1311 return TRUE;
1315 /******************************************************************************
1316 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1318 * PARAMS
1319 * hConsoleOutput [I] Handle to screen buffer
1320 * wAttribute [I] Color attribute to write
1321 * nLength [I] Number of cells to write to
1322 * dwCoord [I] Coords of first cell
1323 * lpNumAttrsWritten [O] Pointer to number of cells written
1325 * RETURNS
1326 * Success: TRUE
1327 * Failure: FALSE
1329 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
1330 WORD wAttribute, DWORD nLength, COORD dwCoord,
1331 LPDWORD lpNumAttrsWritten)
1333 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1334 wAttribute,nLength,dwCoord.x,dwCoord.y,lpNumAttrsWritten);
1335 *lpNumAttrsWritten = nLength;
1336 return TRUE;
1339 /******************************************************************************
1340 * ReadConsoleOutputCharacter32A [KERNEL32.573]
1342 * BUGS
1343 * Unimplemented
1345 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
1346 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1348 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1349 dword,coord.x,coord.y,lpdword);
1350 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1351 return FALSE;
1355 /******************************************************************************
1356 * ScrollConsoleScreenBuffer [KERNEL32.612]
1358 * BUGS
1359 * Unimplemented
1361 BOOL WINAPI ScrollConsoleScreenBuffer( HANDLE hConsoleOutput,
1362 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1363 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1365 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1366 lpClipRect,dwDestOrigin.x,dwDestOrigin.y,lpFill);
1367 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1368 return FALSE;