PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Ruby/lib/ruby/gems/2.0.0/gems/win32console-1.3.2-x86-mingw32/ext/Console_ext/Console.c

https://gitlab.com/orvi2014/rcs-db-ext
C | 1216 lines | 1050 code | 156 blank | 10 comment | 89 complexity | 4a62a0c0fbd6e82d8b14ba410fdf457b MD5 | raw file
  1. #include <windows.h>
  2. #include "ruby.h"
  3. /* Workaround deprecated RString accessors */
  4. #ifndef RSTRING_PTR
  5. #define RSTRING_PTR(s) (RSTRING(s)->ptr)
  6. #endif
  7. #ifndef RSTRING_LEN
  8. #define RSTRING_LEN(s) (RSTRING(s)->len)
  9. #endif
  10. VALUE rb_mWin32;
  11. VALUE rb_mConsole;
  12. VALUE rb_mAPI;
  13. VALUE rb_mConstants;
  14. /* old RUBY_METHOD_FUNC() definition doesn't match to prototypes in those days. */
  15. #ifndef ANYARGS
  16. #undef RUBY_METHOD_FUNC
  17. #define RUBY_METHOD_FUNC(func) ((VALUE (*)())func)
  18. #endif
  19. #define RB_DEF_S_METHOD(klass,method,func,argtype) \
  20. rb_define_singleton_method(klass,method,RUBY_METHOD_FUNC(func), argtype)
  21. #define RB_DEF_API_METHOD(name,argtype) \
  22. RB_DEF_S_METHOD(rb_mAPI,#name,RUBY_METHOD_FUNC(rb_##name), argtype)
  23. #define RB_DEF_METHOD(klass,method,func,argtype) \
  24. rb_define_method(klass,method,RUBY_METHOD_FUNC(func), argtype)
  25. VALUE
  26. rb_getWin32Error()
  27. {
  28. LPVOID lpMsgBuf;
  29. if (!FormatMessage(
  30. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  31. FORMAT_MESSAGE_FROM_SYSTEM |
  32. FORMAT_MESSAGE_IGNORE_INSERTS,
  33. NULL,
  34. GetLastError(),
  35. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  36. (LPTSTR) &lpMsgBuf,
  37. 0,
  38. NULL ))
  39. {
  40. // Handle the error.
  41. return Qnil;
  42. }
  43. VALUE t = rb_str_new2( (LPCTSTR) lpMsgBuf );
  44. // Free the buffer.
  45. LocalFree( lpMsgBuf );
  46. // Raise exception
  47. rb_raise(rb_eRuntimeError, RSTRING_PTR(t));
  48. return Qnil;
  49. }
  50. static VALUE rb_GetStdHandle(VALUE self, VALUE handle)
  51. {
  52. unsigned long x;
  53. if ( FIXNUM_P( handle ) )
  54. {
  55. x = NUM2ULONG( handle );
  56. }
  57. else
  58. {
  59. Check_Type( handle, T_BIGNUM );
  60. x = rb_big2ulong(handle);
  61. }
  62. unsigned long h = PtrToUlong( GetStdHandle( x ) );
  63. return ULONG2NUM(h);
  64. }
  65. static VALUE rb_AllocConsole(VALUE self)
  66. {
  67. if (AllocConsole()) return INT2FIX(1);
  68. return rb_getWin32Error();
  69. }
  70. static VALUE rb_FreeConsole(VALUE self)
  71. {
  72. if (FreeConsole()) return INT2FIX(1);
  73. return rb_getWin32Error();
  74. }
  75. static VALUE rb_GenerateConsoleCtrlEvent(VALUE self, VALUE event, VALUE pgid)
  76. {
  77. unsigned int e = NUM2UINT(event);
  78. if ( e != CTRL_C_EVENT && e != CTRL_BREAK_EVENT )
  79. rb_raise(rb_eArgError, "Wrong event: only CTRL_C_EVENT or "
  80. "CTRL_BREAK_EVENT accepted.");
  81. if ( GenerateConsoleCtrlEvent(e, NUM2UINT(pgid)) )
  82. return INT2FIX(1);
  83. return rb_getWin32Error();
  84. }
  85. static VALUE rb_GetConsoleMode(VALUE self, VALUE hConsoleOutput)
  86. {
  87. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  88. DWORD mode;
  89. if (GetConsoleMode(handle,&mode))
  90. return UINT2NUM(mode);
  91. return rb_getWin32Error();
  92. }
  93. static VALUE rb_GetConsoleTitle(VALUE self)
  94. {
  95. char title[1024];
  96. if (GetConsoleTitle((char*)&title,1024))
  97. return rb_str_new2( title );
  98. return rb_getWin32Error();
  99. }
  100. static VALUE rb_GetNumberOfConsoleMouseButtons( VALUE self )
  101. {
  102. DWORD mb;
  103. if (GetNumberOfConsoleMouseButtons( &mb ))
  104. return INT2FIX(mb);
  105. return rb_getWin32Error();
  106. }
  107. static VALUE rb_GetNumberOfConsoleInputEvents( VALUE self, VALUE hConsoleOutput )
  108. {
  109. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  110. DWORD events;
  111. if (GetNumberOfConsoleInputEvents(handle, &events))
  112. return INT2FIX(events);
  113. return rb_getWin32Error();
  114. }
  115. static VALUE
  116. rb_CreateConsoleScreenBuffer( VALUE self, VALUE dwDesiredAccess,
  117. VALUE dwShareMode, VALUE dwFlags )
  118. {
  119. if (CreateConsoleScreenBuffer( NUM2UINT(dwDesiredAccess),
  120. NUM2UINT( dwShareMode),
  121. NULL,
  122. NUM2UINT( dwFlags),
  123. NULL
  124. ))
  125. return INT2FIX(1);
  126. return rb_getWin32Error();
  127. }
  128. static VALUE rb_GetConsoleCP( VALUE self )
  129. {
  130. unsigned int h = GetConsoleCP();
  131. return UINT2NUM(h);
  132. }
  133. static VALUE rb_GetConsoleOutputCP( VALUE self )
  134. {
  135. unsigned int h = GetConsoleOutputCP();
  136. return UINT2NUM(h);
  137. }
  138. static VALUE rb_SetConsoleMode( VALUE self, VALUE hConsoleOutput,
  139. VALUE Mode )
  140. {
  141. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  142. if ( SetConsoleMode( handle, NUM2UINT( Mode ) ) )
  143. return INT2FIX(1);
  144. return rb_getWin32Error();
  145. }
  146. static VALUE rb_SetConsoleCP( VALUE self, VALUE wCodePageID )
  147. {
  148. if ( SetConsoleCP( NUM2UINT( wCodePageID ) ) )
  149. return INT2FIX(1);
  150. return rb_getWin32Error();
  151. }
  152. static VALUE rb_SetConsoleOutputCP( VALUE self, VALUE wCodePageID )
  153. {
  154. if ( SetConsoleOutputCP( NUM2UINT( wCodePageID ) ) )
  155. return INT2FIX(1);
  156. return rb_getWin32Error();
  157. }
  158. static VALUE rb_GetConsoleWindow( VALUE self )
  159. {
  160. unsigned long h = PtrToUlong( GetConsoleOutputCP() );
  161. return ULONG2NUM(h);
  162. }
  163. static VALUE rb_WriteConsole( VALUE self, VALUE hConsoleOutput,
  164. VALUE lpBuffer )
  165. {
  166. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  167. DWORD nNumberOfCharsToWrite = RSTRING_LEN(lpBuffer);
  168. DWORD lpNumberOfCharsWritten;
  169. WriteConsole( handle, RSTRING_PTR(lpBuffer),
  170. nNumberOfCharsToWrite,
  171. &lpNumberOfCharsWritten, NULL );
  172. return UINT2NUM( lpNumberOfCharsWritten );
  173. }
  174. static VALUE rb_WriteFile( VALUE self, VALUE hConsoleOutput,
  175. VALUE lpBuffer )
  176. {
  177. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  178. DWORD nNumberOfBytesToWrite = RSTRING_LEN(lpBuffer);
  179. DWORD lpNumberOfBytesWritten;
  180. WriteFile( handle, RSTRING_PTR(lpBuffer),
  181. nNumberOfBytesToWrite,
  182. &lpNumberOfBytesWritten, NULL );
  183. return UINT2NUM( lpNumberOfBytesWritten );
  184. }
  185. static VALUE rb_GetLargestConsoleWindowSize( VALUE self, VALUE hConsoleOutput )
  186. {
  187. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  188. COORD size = GetLargestConsoleWindowSize( handle);
  189. VALUE ret = rb_ary_new();
  190. rb_ary_push( ret, UINT2NUM( size.X ) );
  191. rb_ary_push( ret, UINT2NUM( size.Y ) );
  192. return ret;
  193. }
  194. static VALUE rb_GetConsoleCursorInfo( VALUE self, VALUE hConsoleOutput )
  195. {
  196. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  197. CONSOLE_CURSOR_INFO out;
  198. if ( !GetConsoleCursorInfo( handle, &out ) )
  199. return rb_getWin32Error();
  200. VALUE ret = rb_ary_new();
  201. rb_ary_push( ret, UINT2NUM( out.dwSize ) );
  202. rb_ary_push( ret, UINT2NUM( out.bVisible ) );
  203. return ret;
  204. }
  205. void rb_ParseEvent(VALUE ret, INPUT_RECORD *event )
  206. {
  207. switch(event->EventType) {
  208. case KEY_EVENT:
  209. {
  210. KEY_EVENT_RECORD* kevent=(KEY_EVENT_RECORD *)&(event->Event);
  211. rb_ary_push(ret, UINT2NUM(KEY_EVENT));
  212. rb_ary_push(ret, UINT2NUM(kevent->bKeyDown));
  213. rb_ary_push(ret, UINT2NUM(kevent->wRepeatCount));
  214. rb_ary_push(ret, UINT2NUM(kevent->wVirtualKeyCode));
  215. rb_ary_push(ret, UINT2NUM(kevent->wVirtualScanCode));
  216. #ifdef UNICODE
  217. rb_ary_push(ret, UINT2NUM(kevent->uChar.UnicodeChar));
  218. #else
  219. rb_ary_push(ret, UINT2NUM(kevent->uChar.AsciiChar));
  220. #endif
  221. rb_ary_push(ret, UINT2NUM(kevent->dwControlKeyState));
  222. break;
  223. }
  224. case MOUSE_EVENT:
  225. {
  226. MOUSE_EVENT_RECORD * mevent=(MOUSE_EVENT_RECORD *)&(event->Event);
  227. rb_ary_push(ret, UINT2NUM(MOUSE_EVENT) );
  228. rb_ary_push(ret, UINT2NUM(mevent->dwMousePosition.X) );
  229. rb_ary_push(ret, UINT2NUM(mevent->dwMousePosition.Y) );
  230. rb_ary_push(ret, UINT2NUM(mevent->dwButtonState) );
  231. rb_ary_push(ret, UINT2NUM(mevent->dwControlKeyState) );
  232. rb_ary_push(ret, UINT2NUM(mevent->dwEventFlags) );
  233. break;
  234. }
  235. case WINDOW_BUFFER_SIZE_EVENT:
  236. {
  237. WINDOW_BUFFER_SIZE_RECORD* wevent=
  238. (WINDOW_BUFFER_SIZE_RECORD *)&(event->Event);
  239. rb_ary_push(ret, UINT2NUM(WINDOW_BUFFER_SIZE_EVENT) );
  240. rb_ary_push(ret, UINT2NUM(wevent->dwSize.X) );
  241. rb_ary_push(ret, UINT2NUM(wevent->dwSize.Y) );
  242. }
  243. break;
  244. case MENU_EVENT:
  245. {
  246. MENU_EVENT_RECORD* mevent= (MENU_EVENT_RECORD *)&(event->Event);
  247. rb_ary_push(ret, UINT2NUM(MENU_EVENT) );
  248. rb_ary_push(ret, UINT2NUM(mevent->dwCommandId) );
  249. }
  250. break;
  251. case FOCUS_EVENT:
  252. {
  253. FOCUS_EVENT_RECORD* mevent= (FOCUS_EVENT_RECORD *)&(event->Event);
  254. rb_ary_push(ret, UINT2NUM(FOCUS_EVENT) );
  255. rb_ary_push(ret, UINT2NUM(mevent->bSetFocus) );
  256. }
  257. break;
  258. }
  259. }
  260. static VALUE rb_PeekConsoleInput( VALUE self, VALUE hConsoleOutput )
  261. {
  262. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  263. DWORD nofread;
  264. INPUT_RECORD event;
  265. if (!PeekConsoleInput(handle,&event,1,&nofread))
  266. return rb_getWin32Error();
  267. VALUE ret = rb_ary_new();
  268. rb_ParseEvent( ret, &event );
  269. return ret;
  270. }
  271. static VALUE rb_ReadConsole( VALUE self, VALUE hConsoleOutput,
  272. VALUE buffer, VALUE numread )
  273. {
  274. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  275. DWORD nofread;
  276. Check_Type( buffer, T_STRING );
  277. int to_read = NUM2INT(numread);
  278. if ( RSTRING_LEN(buffer) > to_read )
  279. rb_raise(rb_eArgError, "String is too small to read that many characters.");
  280. if (ReadConsole(handle,(void *)RSTRING_PTR(buffer), to_read,
  281. &nofread,NULL))
  282. return UINT2NUM(nofread);
  283. return rb_getWin32Error();
  284. }
  285. static VALUE rb_ReadConsoleInput( VALUE self, VALUE hConsoleOutput )
  286. {
  287. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  288. DWORD nofread;
  289. INPUT_RECORD event;
  290. if (!ReadConsoleInput(handle,&event,1,&nofread))
  291. return rb_getWin32Error();
  292. VALUE ret = rb_ary_new();
  293. rb_ParseEvent( ret, &event );
  294. return ret;
  295. }
  296. static VALUE rb_ReadConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput,
  297. VALUE charbuf, VALUE len,
  298. VALUE x, VALUE y )
  299. {
  300. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  301. COORD coords;
  302. DWORD nofread;
  303. coords.X= NUM2UINT( x );
  304. coords.Y= NUM2UINT( y );
  305. int l = NUM2INT(len);
  306. if ( (unsigned long)RSTRING_LEN(charbuf) < l*sizeof(TCHAR) )
  307. rb_raise(rb_eArgError, "String is too small to read that many characters.");
  308. if (ReadConsoleOutputCharacter(handle,RSTRING_PTR(charbuf),l,
  309. coords,&nofread))
  310. return UINT2NUM( nofread );
  311. return rb_getWin32Error();
  312. }
  313. static VALUE rb_ReadConsoleOutputAttribute( VALUE self, VALUE hConsoleOutput,
  314. VALUE len, VALUE x, VALUE y )
  315. {
  316. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  317. COORD coords;
  318. DWORD nofread;
  319. unsigned short abuffer[80*999*sizeof(unsigned short)];
  320. char cbuffer[80*999];
  321. unsigned i = 0;
  322. coords.X= NUM2UINT( x );
  323. coords.Y= NUM2UINT( y );
  324. if (ReadConsoleOutputAttribute(handle, abuffer, NUM2UINT(len),
  325. coords,&nofread))
  326. {
  327. for(i=0;i<nofread;++i) {
  328. cbuffer[i]=(char)abuffer[i];
  329. }
  330. return rb_str_new( cbuffer, nofread );
  331. }
  332. return rb_getWin32Error();
  333. }
  334. static VALUE rb_ReadConsoleOutput( VALUE self, VALUE hConsoleOutput,
  335. VALUE buffer, VALUE srcwid, VALUE srcht,
  336. VALUE startx, VALUE starty,
  337. VALUE l, VALUE t, VALUE r, VALUE b )
  338. {
  339. COORD coords;
  340. COORD size;
  341. SMALL_RECT from;
  342. size.X= NUM2UINT( srcwid );
  343. size.Y= NUM2UINT( srcht );
  344. coords.X= NUM2INT( startx );
  345. coords.Y= NUM2INT( starty );
  346. from.Left = NUM2INT( l );
  347. from.Top = NUM2INT( t );
  348. from.Right = NUM2INT( r );
  349. from.Bottom = NUM2INT( b );
  350. Check_Type( buffer, T_STRING );
  351. if ( (unsigned long)RSTRING_LEN(buffer) < (sizeof(CHAR_INFO)*size.X*size.Y) )
  352. rb_raise(rb_eArgError, "string buffer is too small for reading that many characters.");
  353. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  354. if (!ReadConsoleOutput(handle,(CHAR_INFO *)RSTRING_PTR(buffer),size,coords,&from))
  355. return rb_getWin32Error();
  356. VALUE ret = rb_ary_new();
  357. rb_ary_push( ret, INT2FIX(from.Left) );
  358. rb_ary_push( ret, INT2FIX(from.Top) );
  359. rb_ary_push( ret, INT2FIX(from.Right) );
  360. rb_ary_push( ret, INT2FIX(from.Bottom) );
  361. return ret;
  362. }
  363. static VALUE rb_GetConsoleScreenBufferInfo( VALUE self, VALUE hConsoleOutput )
  364. {
  365. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  366. CONSOLE_SCREEN_BUFFER_INFO out;
  367. if ( !GetConsoleScreenBufferInfo( handle, &out ) )
  368. return rb_getWin32Error();
  369. VALUE ret = rb_ary_new();
  370. rb_ary_push( ret, UINT2NUM( out.dwSize.X ) );
  371. rb_ary_push( ret, UINT2NUM( out.dwSize.Y ) );
  372. rb_ary_push( ret, UINT2NUM( out.dwCursorPosition.X ) );
  373. rb_ary_push( ret, UINT2NUM( out.dwCursorPosition.Y ) );
  374. rb_ary_push( ret, UINT2NUM( out.wAttributes ) );
  375. rb_ary_push( ret, INT2FIX( out.srWindow.Left ) );
  376. rb_ary_push( ret, INT2FIX( out.srWindow.Top ) );
  377. rb_ary_push( ret, INT2FIX( out.srWindow.Right ) );
  378. rb_ary_push( ret, INT2FIX( out.srWindow.Bottom ) );
  379. rb_ary_push( ret, UINT2NUM( out.dwMaximumWindowSize.X ) );
  380. rb_ary_push( ret, UINT2NUM( out.dwMaximumWindowSize.Y ) );
  381. return ret;
  382. }
  383. #define strEQ(x,y) strcmp(x,y) == 0
  384. DWORD c_constant(char *name)
  385. {
  386. switch (*name) {
  387. case 'A':
  388. break;
  389. case 'B':
  390. if (strEQ(name, "BACKGROUND_BLUE"))
  391. #ifdef BACKGROUND_BLUE
  392. return BACKGROUND_BLUE;
  393. #else
  394. goto not_there;
  395. #endif
  396. if (strEQ(name, "BACKGROUND_GREEN"))
  397. #ifdef BACKGROUND_GREEN
  398. return BACKGROUND_GREEN;
  399. #else
  400. goto not_there;
  401. #endif
  402. if (strEQ(name, "BACKGROUND_INTENSITY"))
  403. #ifdef BACKGROUND_INTENSITY
  404. return BACKGROUND_INTENSITY;
  405. #else
  406. goto not_there;
  407. #endif
  408. if (strEQ(name, "BACKGROUND_RED"))
  409. #ifdef BACKGROUND_RED
  410. return BACKGROUND_RED;
  411. #else
  412. goto not_there;
  413. #endif
  414. break;
  415. case 'C':
  416. if (strEQ(name, "CAPSLOCK_ON"))
  417. #ifdef CAPSLOCK_ON
  418. return CAPSLOCK_ON;
  419. #else
  420. goto not_there;
  421. #endif
  422. if (strEQ(name, "CONSOLE_TEXTMODE_BUFFER"))
  423. #ifdef CONSOLE_TEXTMODE_BUFFER
  424. return CONSOLE_TEXTMODE_BUFFER;
  425. #else
  426. goto not_there;
  427. #endif
  428. if (strEQ(name, "CTRL_BREAK_EVENT"))
  429. #ifdef CTRL_BREAK_EVENT
  430. return CTRL_BREAK_EVENT;
  431. #else
  432. goto not_there;
  433. #endif
  434. if (strEQ(name, "CTRL_C_EVENT"))
  435. #ifdef CTRL_C_EVENT
  436. return CTRL_C_EVENT;
  437. #else
  438. goto not_there;
  439. #endif
  440. break;
  441. case 'D':
  442. break;
  443. case 'E':
  444. if (strEQ(name, "ENABLE_ECHO_INPUT"))
  445. #ifdef ENABLE_ECHO_INPUT
  446. return ENABLE_ECHO_INPUT;
  447. #else
  448. goto not_there;
  449. #endif
  450. if (strEQ(name, "ENABLE_LINE_INPUT"))
  451. #ifdef ENABLE_LINE_INPUT
  452. return ENABLE_LINE_INPUT;
  453. #else
  454. goto not_there;
  455. #endif
  456. if (strEQ(name, "ENABLE_MOUSE_INPUT"))
  457. #ifdef ENABLE_MOUSE_INPUT
  458. return ENABLE_MOUSE_INPUT;
  459. #else
  460. goto not_there;
  461. #endif
  462. if (strEQ(name, "ENABLE_PROCESSED_INPUT"))
  463. #ifdef ENABLE_PROCESSED_INPUT
  464. return ENABLE_PROCESSED_INPUT;
  465. #else
  466. goto not_there;
  467. #endif
  468. if (strEQ(name, "ENABLE_PROCESSED_OUTPUT"))
  469. #ifdef ENABLE_PROCESSED_OUTPUT
  470. return ENABLE_PROCESSED_OUTPUT;
  471. #else
  472. goto not_there;
  473. #endif
  474. if (strEQ(name, "ENABLE_WINDOW_INPUT"))
  475. #ifdef ENABLE_WINDOW_INPUT
  476. return ENABLE_WINDOW_INPUT;
  477. #else
  478. goto not_there;
  479. #endif
  480. if (strEQ(name, "ENABLE_WRAP_AT_EOL_OUTPUT"))
  481. #ifdef ENABLE_WRAP_AT_EOL_OUTPUT
  482. return ENABLE_WRAP_AT_EOL_OUTPUT;
  483. #else
  484. goto not_there;
  485. #endif
  486. if (strEQ(name, "ENHANCED_KEY"))
  487. #ifdef ENHANCED_KEY
  488. return ENHANCED_KEY;
  489. #else
  490. goto not_there;
  491. #endif
  492. break;
  493. case 'F':
  494. if (strEQ(name, "FILE_SHARE_READ"))
  495. #ifdef FILE_SHARE_READ
  496. return FILE_SHARE_READ;
  497. #else
  498. goto not_there;
  499. #endif
  500. if (strEQ(name, "FILE_SHARE_WRITE"))
  501. #ifdef FILE_SHARE_WRITE
  502. return FILE_SHARE_WRITE;
  503. #else
  504. goto not_there;
  505. #endif
  506. if (strEQ(name, "FOREGROUND_BLUE"))
  507. #ifdef FOREGROUND_BLUE
  508. return FOREGROUND_BLUE;
  509. #else
  510. goto not_there;
  511. #endif
  512. if (strEQ(name, "FOREGROUND_GREEN"))
  513. #ifdef FOREGROUND_GREEN
  514. return FOREGROUND_GREEN;
  515. #else
  516. goto not_there;
  517. #endif
  518. if (strEQ(name, "FOREGROUND_INTENSITY"))
  519. #ifdef FOREGROUND_INTENSITY
  520. return FOREGROUND_INTENSITY;
  521. #else
  522. goto not_there;
  523. #endif
  524. if (strEQ(name, "FOREGROUND_RED"))
  525. #ifdef FOREGROUND_RED
  526. return FOREGROUND_RED;
  527. #else
  528. goto not_there;
  529. #endif
  530. break;
  531. case 'G':
  532. if (strEQ(name, "GENERIC_READ"))
  533. #ifdef GENERIC_READ
  534. return GENERIC_READ;
  535. #else
  536. goto not_there;
  537. #endif
  538. if (strEQ(name, "GENERIC_WRITE"))
  539. #ifdef GENERIC_WRITE
  540. return GENERIC_WRITE;
  541. #else
  542. goto not_there;
  543. #endif
  544. break;
  545. case 'H':
  546. break;
  547. case 'I':
  548. break;
  549. case 'J':
  550. break;
  551. case 'K':
  552. if (strEQ(name, "KEY_EVENT"))
  553. #ifdef KEY_EVENT
  554. return KEY_EVENT;
  555. #else
  556. goto not_there;
  557. #endif
  558. break;
  559. case 'L':
  560. if (strEQ(name, "LEFT_ALT_PRESSED"))
  561. #ifdef LEFT_ALT_PRESSED
  562. return LEFT_ALT_PRESSED;
  563. #else
  564. goto not_there;
  565. #endif
  566. if (strEQ(name, "LEFT_CTRL_PRESSED"))
  567. #ifdef LEFT_CTRL_PRESSED
  568. return LEFT_CTRL_PRESSED;
  569. #else
  570. goto not_there;
  571. #endif
  572. break;
  573. case 'M':
  574. break;
  575. case 'N':
  576. if (strEQ(name, "NUMLOCK_ON"))
  577. #ifdef NUMLOCK_ON
  578. return NUMLOCK_ON;
  579. #else
  580. goto not_there;
  581. #endif
  582. break;
  583. case 'O':
  584. break;
  585. case 'P':
  586. break;
  587. case 'Q':
  588. break;
  589. case 'R':
  590. if (strEQ(name, "RIGHT_ALT_PRESSED"))
  591. #ifdef RIGHT_ALT_PRESSED
  592. return RIGHT_ALT_PRESSED;
  593. #else
  594. goto not_there;
  595. #endif
  596. if (strEQ(name, "RIGHT_CTRL_PRESSED"))
  597. #ifdef RIGHT_CTRL_PRESSED
  598. return RIGHT_CTRL_PRESSED;
  599. #else
  600. goto not_there;
  601. #endif
  602. break;
  603. case 'S':
  604. if (strEQ(name, "SCROLLLOCK_ON"))
  605. #ifdef SCROLLLOCK_ON
  606. return SCROLLLOCK_ON;
  607. #else
  608. goto not_there;
  609. #endif
  610. if (strEQ(name, "SHIFT_PRESSED"))
  611. #ifdef SHIFT_PRESSED
  612. return SHIFT_PRESSED;
  613. #else
  614. goto not_there;
  615. #endif
  616. if (strEQ(name, "STD_ERROR_HANDLE"))
  617. #ifdef STD_ERROR_HANDLE
  618. return STD_ERROR_HANDLE;
  619. #else
  620. goto not_there;
  621. #endif
  622. if (strEQ(name, "STD_INPUT_HANDLE"))
  623. #ifdef STD_INPUT_HANDLE
  624. return STD_INPUT_HANDLE;
  625. #else
  626. goto not_there;
  627. #endif
  628. if (strEQ(name, "STD_OUTPUT_HANDLE"))
  629. #ifdef STD_OUTPUT_HANDLE
  630. return STD_OUTPUT_HANDLE;
  631. #else
  632. goto not_there;
  633. #endif
  634. break;
  635. case 'T':
  636. break;
  637. case 'U':
  638. break;
  639. case 'V':
  640. break;
  641. case 'W':
  642. break;
  643. case 'X':
  644. break;
  645. case 'Y':
  646. break;
  647. case 'Z':
  648. break;
  649. }
  650. rb_raise(rb_eArgError, "Not such constant.");
  651. return 0;
  652. not_there:
  653. rb_raise(rb_eArgError, "Not defined.");
  654. return 0;
  655. }
  656. VALUE rb_constant( VALUE self, VALUE name )
  657. {
  658. Check_Type( name, T_STRING );
  659. return ULONG2NUM( c_constant( RSTRING_PTR(name) ) );
  660. }
  661. void define_constants()
  662. {
  663. #define DEF_SELF_CONST(NAME) \
  664. rb_define_const(rb_mConstants, #NAME, ULONG2NUM( (ULONG)NAME ) );
  665. DEF_SELF_CONST( STD_INPUT_HANDLE );
  666. DEF_SELF_CONST( STD_OUTPUT_HANDLE );
  667. DEF_SELF_CONST( STD_ERROR_HANDLE );
  668. DEF_SELF_CONST( INVALID_HANDLE_VALUE );
  669. DEF_SELF_CONST( GENERIC_READ );
  670. DEF_SELF_CONST( GENERIC_WRITE );
  671. DEF_SELF_CONST( FILE_SHARE_READ );
  672. DEF_SELF_CONST( FILE_SHARE_WRITE );
  673. DEF_SELF_CONST( CONSOLE_TEXTMODE_BUFFER );
  674. DEF_SELF_CONST( FOREGROUND_BLUE );
  675. DEF_SELF_CONST( FOREGROUND_GREEN );
  676. DEF_SELF_CONST( FOREGROUND_RED );
  677. DEF_SELF_CONST( FOREGROUND_INTENSITY );
  678. DEF_SELF_CONST( BACKGROUND_BLUE );
  679. DEF_SELF_CONST( BACKGROUND_GREEN );
  680. DEF_SELF_CONST( BACKGROUND_RED );
  681. DEF_SELF_CONST( BACKGROUND_INTENSITY );
  682. DEF_SELF_CONST( ENABLE_PROCESSED_INPUT );
  683. DEF_SELF_CONST( ENABLE_LINE_INPUT );
  684. DEF_SELF_CONST( ENABLE_ECHO_INPUT );
  685. DEF_SELF_CONST( ENABLE_WINDOW_INPUT );
  686. DEF_SELF_CONST( ENABLE_MOUSE_INPUT );
  687. DEF_SELF_CONST( ENABLE_PROCESSED_OUTPUT );
  688. DEF_SELF_CONST( ENABLE_WRAP_AT_EOL_OUTPUT );
  689. DEF_SELF_CONST( KEY_EVENT );
  690. DEF_SELF_CONST( MOUSE_EVENT );
  691. DEF_SELF_CONST( WINDOW_BUFFER_SIZE_EVENT );
  692. DEF_SELF_CONST( MENU_EVENT );
  693. DEF_SELF_CONST( FOCUS_EVENT );
  694. DEF_SELF_CONST( CAPSLOCK_ON );
  695. DEF_SELF_CONST( ENHANCED_KEY );
  696. DEF_SELF_CONST( NUMLOCK_ON );
  697. DEF_SELF_CONST( SHIFT_PRESSED );
  698. DEF_SELF_CONST( LEFT_CTRL_PRESSED );
  699. DEF_SELF_CONST( RIGHT_CTRL_PRESSED );
  700. DEF_SELF_CONST( LEFT_ALT_PRESSED );
  701. DEF_SELF_CONST( RIGHT_ALT_PRESSED );
  702. DEF_SELF_CONST( SCROLLLOCK_ON );
  703. DEF_SELF_CONST( MOUSE_WHEELED );
  704. DEF_SELF_CONST( DOUBLE_CLICK );
  705. DEF_SELF_CONST( MOUSE_MOVED );
  706. DEF_SELF_CONST( FROM_LEFT_1ST_BUTTON_PRESSED );
  707. DEF_SELF_CONST( FROM_LEFT_2ND_BUTTON_PRESSED );
  708. DEF_SELF_CONST( FROM_LEFT_3RD_BUTTON_PRESSED );
  709. DEF_SELF_CONST( FROM_LEFT_4TH_BUTTON_PRESSED );
  710. DEF_SELF_CONST( RIGHTMOST_BUTTON_PRESSED );
  711. DEF_SELF_CONST( CTRL_C_EVENT );
  712. DEF_SELF_CONST( CTRL_BREAK_EVENT );
  713. DEF_SELF_CONST( CTRL_CLOSE_EVENT );
  714. DEF_SELF_CONST( CTRL_LOGOFF_EVENT );
  715. DEF_SELF_CONST( CTRL_SHUTDOWN_EVENT );
  716. }
  717. VALUE
  718. rb_FillConsoleOutputAttribute( VALUE self, VALUE hConsoleOutput,
  719. VALUE wAttribute, VALUE nLength,
  720. VALUE col, VALUE row )
  721. {
  722. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  723. COORD dwWriteCoord;
  724. dwWriteCoord.X = NUM2UINT(col);
  725. dwWriteCoord.Y = NUM2UINT(row);
  726. DWORD numChars;
  727. if (FillConsoleOutputAttribute( handle, NUM2UINT(wAttribute),
  728. NUM2ULONG(nLength), dwWriteCoord,
  729. &numChars ))
  730. return ULONG2NUM(numChars);
  731. return rb_getWin32Error();
  732. }
  733. VALUE
  734. rb_SetConsoleScreenBufferSize( VALUE self, VALUE hConsoleOutput,
  735. VALUE x, VALUE y )
  736. {
  737. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  738. COORD size;
  739. size.X=NUM2UINT(x);
  740. size.Y=NUM2UINT(y);
  741. if (SetConsoleScreenBufferSize(handle, size))
  742. return NUM2UINT(1);
  743. return rb_getWin32Error();
  744. }
  745. VALUE
  746. rb_SetConsoleTitle( VALUE self, VALUE title )
  747. {
  748. Check_Type( title, T_STRING );
  749. if (SetConsoleTitle(RSTRING_PTR( title )))
  750. return NUM2UINT(1);
  751. return rb_getWin32Error();
  752. }
  753. VALUE
  754. rb_SetStdHandle( VALUE self, VALUE fd, VALUE hConsoleOutput )
  755. {
  756. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  757. if (SetStdHandle(NUM2UINT(fd), handle))
  758. return NUM2UINT(1);
  759. return rb_getWin32Error();
  760. }
  761. VALUE
  762. rb_SetConsoleWindowInfo( VALUE self, VALUE hConsoleOutput, VALUE bAbsolute,
  763. VALUE left, VALUE top, VALUE right, VALUE bottom )
  764. {
  765. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  766. SMALL_RECT rect;
  767. rect.Left = NUM2INT( left );
  768. rect.Top = NUM2INT( top );
  769. rect.Right = NUM2INT( right );
  770. rect.Bottom = NUM2INT( bottom );
  771. if (SetConsoleWindowInfo( handle, NUM2INT( bAbsolute ), &rect ))
  772. return UINT2NUM(1);
  773. return rb_getWin32Error();
  774. }
  775. VALUE
  776. rb_SetConsoleCursorPosition( VALUE self, VALUE hConsoleOutput,
  777. VALUE col, VALUE row )
  778. {
  779. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  780. COORD dwWriteCoord;
  781. dwWriteCoord.X = NUM2UINT(col);
  782. dwWriteCoord.Y = NUM2UINT(row);
  783. // Cannot call rb_getWin32Error as this function fails when
  784. // setting cursor to last column/row.
  785. if ( !SetConsoleCursorPosition( handle, dwWriteCoord ) )
  786. return Qnil;
  787. return INT2FIX(1);
  788. }
  789. VALUE
  790. rb_SetConsoleCursorInfo( VALUE self, VALUE hConsoleOutput,
  791. VALUE size, VALUE visib )
  792. {
  793. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  794. CONSOLE_CURSOR_INFO c;
  795. c.dwSize = NUM2UINT(size);
  796. c.bVisible = NUM2UINT(visib);
  797. if ( !SetConsoleCursorInfo( handle, &c ) )
  798. return rb_getWin32Error();
  799. return INT2FIX(1);
  800. }
  801. VALUE
  802. rb_SetConsoleActiveScreenBuffer( VALUE self, VALUE hConsoleOutput )
  803. {
  804. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  805. if ( !SetConsoleActiveScreenBuffer( handle ) )
  806. return rb_getWin32Error();
  807. return INT2FIX(1);
  808. }
  809. VALUE
  810. rb_SetConsoleTextAttribute( VALUE self, VALUE hConsoleOutput,
  811. VALUE wAttributes )
  812. {
  813. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  814. if ( !SetConsoleTextAttribute( handle, NUM2UINT(wAttributes) ) )
  815. return Qnil; // no getWin32Error to allow piping/redirecting
  816. return INT2FIX(1);
  817. }
  818. VALUE
  819. rb_ScrollConsoleScreenBuffer( VALUE self, VALUE hConsoleOutput, VALUE left1,
  820. VALUE top1, VALUE right1, VALUE bottom1,
  821. VALUE col, VALUE row, VALUE cChar, VALUE attr,
  822. VALUE left2, VALUE top2, VALUE right2,
  823. VALUE bottom2)
  824. {
  825. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  826. SMALL_RECT scroll, clip;
  827. scroll.Left = NUM2INT( left1 );
  828. scroll.Right = NUM2INT( right1 );
  829. scroll.Top = NUM2INT( top1 );
  830. scroll.Bottom = NUM2INT( bottom1 );
  831. clip.Left = NUM2INT( left2 );
  832. clip.Right = NUM2INT( right2 );
  833. clip.Top = NUM2INT( top2 );
  834. clip.Bottom = NUM2INT( bottom2 );
  835. CHAR_INFO fill;
  836. #ifdef UNICODE
  837. fill.Char.UnicodeChar = NUM2CHR( cChar );
  838. #else
  839. fill.Char.AsciiChar = NUM2CHR( cChar );
  840. #endif
  841. fill.Attributes = NUM2INT(attr);
  842. COORD origin;
  843. origin.X = NUM2UINT( col );
  844. origin.Y = NUM2UINT( row );
  845. if ( ScrollConsoleScreenBuffer( handle, &scroll, &clip, origin,
  846. &fill ) )
  847. return INT2FIX(1);
  848. return rb_getWin32Error();
  849. }
  850. VALUE
  851. rb_FillConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput,
  852. VALUE cCharacter, VALUE nLength,
  853. VALUE col, VALUE row )
  854. {
  855. HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
  856. COORD dwWriteCoord;
  857. dwWriteCoord.X = NUM2UINT(col);
  858. dwWriteCoord.Y = NUM2UINT(row);
  859. DWORD numChars;
  860. if (FillConsoleOutputCharacter( handle, NUM2CHR(cCharacter),
  861. NUM2ULONG(nLength), dwWriteCoord,
  862. &numChars ))
  863. return ULONG2NUM(numChars);
  864. return rb_getWin32Error();
  865. }
  866. VALUE
  867. rb_WriteConsoleInput(int argc, VALUE *argv, VALUE self)
  868. {
  869. if (argc < 3)
  870. rb_raise(rb_eArgError, "Wrong number of arguments.");
  871. HANDLE handle = ULongToPtr( NUM2ULONG( argv[0] ) );
  872. WORD type = NUM2INT( argv[1] );
  873. DWORD written;
  874. INPUT_RECORD event;
  875. event.EventType = type;
  876. switch(event.EventType) {
  877. case KEY_EVENT:
  878. {
  879. KEY_EVENT_RECORD* kevent=(KEY_EVENT_RECORD *)&(event.Event);
  880. kevent->bKeyDown=(BOOL)NUM2UINT( argv[2] );
  881. kevent->wRepeatCount=NUM2UINT( argv[3] );
  882. kevent->wVirtualKeyCode=NUM2UINT( argv[4] );
  883. kevent->wVirtualScanCode=NUM2UINT( argv[5] );
  884. #ifdef UNICODE
  885. if (argc < 7)
  886. rb_raise(rb_eArgError, "Wrong number of arguments.");
  887. kevent->uChar.UnicodeChar=NUM2UINT( argv[6] );
  888. #else
  889. if (argc < 8)
  890. rb_raise(rb_eArgError, "Wrong number of arguments.");
  891. kevent->uChar.AsciiChar=NUM2UINT( argv[7] );
  892. #endif
  893. break;
  894. }
  895. case MOUSE_EVENT:
  896. {
  897. if (argc < 7)
  898. rb_raise(rb_eArgError, "Wrong number of arguments.");
  899. MOUSE_EVENT_RECORD* mevent=(MOUSE_EVENT_RECORD *)&(event.Event);
  900. mevent->dwMousePosition.X=NUM2UINT( argv[2] );
  901. mevent->dwMousePosition.Y=NUM2UINT( argv[3] );
  902. mevent->dwButtonState=NUM2UINT( argv[4] );
  903. mevent->dwControlKeyState=NUM2UINT( argv[5] );
  904. mevent->dwEventFlags=NUM2UINT( argv[6] );
  905. break;
  906. }
  907. case WINDOW_BUFFER_SIZE_EVENT:
  908. {
  909. if (argc < 4)
  910. rb_raise(rb_eArgError, "Wrong number of arguments.");
  911. WINDOW_BUFFER_SIZE_RECORD* mevent=
  912. (WINDOW_BUFFER_SIZE_RECORD *)&(event.Event);
  913. mevent->dwSize.X = NUM2UINT( argv[2] );
  914. mevent->dwSize.Y = NUM2UINT( argv[3] );
  915. }
  916. break;
  917. case MENU_EVENT:
  918. {
  919. if (argc < 3)
  920. rb_raise(rb_eArgError, "Wrong number of arguments.");
  921. MENU_EVENT_RECORD* mevent= (MENU_EVENT_RECORD *)&(event.Event);
  922. mevent->dwCommandId = argv[2];
  923. }
  924. break;
  925. case FOCUS_EVENT:
  926. {
  927. if (argc < 3)
  928. rb_raise(rb_eArgError, "Wrong number of arguments.");
  929. FOCUS_EVENT_RECORD* mevent= (FOCUS_EVENT_RECORD *)&(event.Event);
  930. mevent->bSetFocus = NUM2UINT( argv[2] );
  931. }
  932. default:
  933. rb_raise( rb_eArgError, "Unknown type of event.");
  934. break;
  935. }
  936. if (WriteConsoleInput(handle,&event,1,&written))
  937. return INT2FIX(1);
  938. return rb_getWin32Error();
  939. }
  940. VALUE
  941. rb_WriteConsoleOutput(VALUE self, VALUE h, VALUE buffer,
  942. VALUE srcwid, VALUE srcht, VALUE startx,
  943. VALUE starty, VALUE l, VALUE t, VALUE r, VALUE b)
  944. {
  945. COORD coords;
  946. COORD size;
  947. SMALL_RECT to;
  948. HANDLE handle = ULongToPtr( NUM2ULONG( h ) );
  949. Check_Type( buffer, T_STRING );
  950. size.X=NUM2UINT( srcwid );
  951. size.Y=NUM2UINT( srcht );
  952. coords.X=NUM2INT( startx );
  953. coords.Y=NUM2INT( starty );
  954. to.Left = NUM2INT( l );
  955. to.Top = NUM2INT( t );
  956. to.Right = NUM2INT( r );
  957. to.Bottom = NUM2INT( b );
  958. if (WriteConsoleOutput(handle,(CHAR_INFO *)RSTRING_PTR(buffer),
  959. size,coords,&to)) {
  960. VALUE ret = rb_ary_new();
  961. rb_ary_push( ret, INT2FIX( to.Left ) );
  962. rb_ary_push( ret, INT2FIX( to.Top ) );
  963. rb_ary_push( ret, INT2FIX( to.Right ) );
  964. rb_ary_push( ret, INT2FIX( to.Bottom ) );
  965. return ret;
  966. }
  967. return rb_getWin32Error();
  968. }
  969. VALUE
  970. rb_WriteConsoleOutputAttribute(VALUE self, VALUE h, VALUE s,
  971. VALUE x, VALUE y)
  972. {
  973. HANDLE handle = ULongToPtr( NUM2ULONG( h ) );
  974. Check_Type( s, T_STRING );
  975. unsigned short buffer[80*999*sizeof(unsigned short)];
  976. DWORD written;
  977. DWORD towrite = RSTRING_LEN(s);
  978. unsigned i = 0;
  979. for(i=0; i<towrite; i++) {
  980. buffer[i] = (unsigned short)(RSTRING_PTR(s)[i]);
  981. }
  982. COORD coords;
  983. coords.X=NUM2INT( x );
  984. coords.Y=NUM2INT( y );
  985. if (WriteConsoleOutputAttribute(handle,(const unsigned short *)&buffer,
  986. towrite,coords,&written)) {
  987. return UINT2NUM( written );
  988. }
  989. return rb_getWin32Error();
  990. }
  991. VALUE
  992. rb_WriteConsoleOutputCharacter(VALUE self, VALUE h, VALUE s,
  993. VALUE x, VALUE y)
  994. {
  995. HANDLE handle = ULongToPtr( NUM2ULONG( h ) );
  996. Check_Type( s, T_STRING );
  997. DWORD written;
  998. COORD coords;
  999. coords.X=NUM2INT( x );
  1000. coords.Y=NUM2INT( y );
  1001. if (WriteConsoleOutputCharacter(handle,(LPCTSTR)RSTRING_PTR(s),
  1002. RSTRING_LEN(s),coords,&written)) {
  1003. return UINT2NUM( written );
  1004. }
  1005. return rb_getWin32Error();
  1006. }
  1007. void Init_Console_ext(void)
  1008. {
  1009. rb_mWin32 = rb_define_module("Win32");
  1010. rb_define_const(rb_mKernel, "Win32", rb_mWin32);
  1011. rb_mConsole = rb_define_class_under(rb_mWin32, "Console", rb_cObject);
  1012. // Handle Constants
  1013. rb_mConstants = rb_define_module_under(rb_mConsole,"Constants");
  1014. define_constants();
  1015. // Handle API
  1016. rb_mAPI = rb_define_class_under(rb_mConsole, "API", rb_cObject);
  1017. RB_DEF_API_METHOD(constant, 1); //OK
  1018. RB_DEF_API_METHOD(AllocConsole, 0);
  1019. RB_DEF_API_METHOD(CreateConsoleScreenBuffer, 3); //OK
  1020. RB_DEF_API_METHOD(FillConsoleOutputAttribute, 5); //OK
  1021. RB_DEF_API_METHOD(FillConsoleOutputCharacter, 5); //OK
  1022. // RB_DEF_API_METHOD(FillConsoleInputBuffer, 1); // Does not exist anymore
  1023. RB_DEF_API_METHOD(FreeConsole, 0);
  1024. RB_DEF_API_METHOD(GenerateConsoleCtrlEvent, 2);
  1025. RB_DEF_API_METHOD(GetConsoleCP, 0); //OK
  1026. RB_DEF_API_METHOD(GetConsoleCursorInfo, 1); //OK
  1027. RB_DEF_API_METHOD(GetConsoleMode, 1);
  1028. RB_DEF_API_METHOD(GetConsoleOutputCP, 0);
  1029. RB_DEF_API_METHOD(GetConsoleScreenBufferInfo, 1); //OK
  1030. RB_DEF_API_METHOD(GetConsoleTitle, 0);
  1031. RB_DEF_API_METHOD(GetConsoleWindow, 0);
  1032. RB_DEF_API_METHOD(GetLargestConsoleWindowSize, 1);
  1033. RB_DEF_API_METHOD(GetNumberOfConsoleInputEvents, 1);
  1034. RB_DEF_API_METHOD(GetNumberOfConsoleMouseButtons, 0);
  1035. RB_DEF_API_METHOD(GetStdHandle, 1); //OK
  1036. RB_DEF_API_METHOD(PeekConsoleInput, 1); //OK
  1037. RB_DEF_API_METHOD(ReadConsole, 3); //OK
  1038. RB_DEF_API_METHOD(ReadConsoleInput, 1); //OK
  1039. RB_DEF_API_METHOD(ReadConsoleOutput, 10); // OK
  1040. RB_DEF_API_METHOD(ReadConsoleOutputAttribute, 4); // OK
  1041. RB_DEF_API_METHOD(ReadConsoleOutputCharacter, 5); // OK
  1042. RB_DEF_API_METHOD(ScrollConsoleScreenBuffer, 13); //OK
  1043. RB_DEF_API_METHOD(SetConsoleActiveScreenBuffer, 1);
  1044. RB_DEF_API_METHOD(SetConsoleCP, 1);
  1045. RB_DEF_API_METHOD(SetConsoleCursorPosition, 3);
  1046. RB_DEF_API_METHOD(SetConsoleCursorInfo, 3);
  1047. RB_DEF_API_METHOD(SetConsoleMode, 2); //OK
  1048. RB_DEF_API_METHOD(SetConsoleOutputCP, 1);
  1049. RB_DEF_API_METHOD(SetConsoleScreenBufferSize, 3);
  1050. RB_DEF_API_METHOD(SetConsoleTextAttribute, 2);
  1051. RB_DEF_API_METHOD(SetConsoleTitle, 1); //OK
  1052. RB_DEF_API_METHOD(SetConsoleWindowInfo, 6);
  1053. RB_DEF_API_METHOD(SetStdHandle, 2);
  1054. RB_DEF_API_METHOD(WriteConsole, 2);
  1055. RB_DEF_API_METHOD(WriteFile, 2);
  1056. RB_DEF_API_METHOD(WriteConsoleInput, -1);
  1057. RB_DEF_API_METHOD(WriteConsoleOutput, 10);
  1058. RB_DEF_API_METHOD(WriteConsoleOutputAttribute, 4);
  1059. RB_DEF_API_METHOD(WriteConsoleOutputCharacter, 4);
  1060. }