Class: Win32::Console::API

Inherits:
Object
  • Object
show all
Defined in:
lib/Win32/Console/api.rb,
ext/Console_ext/Console.c

Class Method Summary collapse

Class Method Details

.AllocConsoleObject



18
19
20
21
# File 'lib/Win32/Console/api.rb', line 18

def AllocConsole()
  @AllocConsole ||= Win32API.new( "kernel32", "AllocConsole", [], 'l' )
  @AllocConsole.call()
end

.constant(t) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/Win32/Console/api.rb', line 10

def constant(t)
  begin
    return Win32::Console::Constants.const_get(t)
  rescue
    return nil
  end
end

.CreateConsoleScreenBuffer(dwDesiredAccess, dwShareMode, dwFlags) ⇒ Object



23
24
25
26
# File 'lib/Win32/Console/api.rb', line 23

def CreateConsoleScreenBuffer( dwDesiredAccess, dwShareMode, dwFlags )
  @CreateConsoleScreenBuffer ||= Win32API.new( "kernel32", "CreateConsoleScreenBuffer", ['l', 'l', 'p', 'l', 'p'], 'l' )
  @CreateConsoleScreenBuffer.call( dwDesiredAccess, dwShareMode, nil, dwFlags, nil )
end

.FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, col, row) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/Win32/Console/api.rb', line 28

def FillConsoleOutputAttribute( hConsoleOutput, wAttribute, nLength, col, row )
  @FillConsoleOutputAttribute ||= Win32API.new( "kernel32", "FillConsoleOutputAttribute", ['l', 'i', 'l', 'l', 'p'], 'l' )
  dwWriteCoord = (row << 16) + col
  lpNumberOfAttrsWritten = ' ' * 4
  @FillConsoleOutputAttribute.call( hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
  return lpNumberOfAttrsWritten.unpack('L')
end

.FillConsoleOutputCharacter(hConsoleOutput, cCharacter, nLength, col, row) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/Win32/Console/api.rb', line 36

def FillConsoleOutputCharacter( hConsoleOutput, cCharacter, nLength, col, row )
  @FillConsoleOutputCharacter ||= Win32API.new( "kernel32", "FillConsoleOutputCharacter", ['l', 'i', 'l', 'l', 'p'], 'l' )
   dwWriteCoord = (row << 16) + col
   lpNumberOfAttrsWritten = ' ' * 4
  @FillConsoleOutputCharacter.call( hConsoleOutput, cCharacter, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
   return lpNumberOfAttrsWritten.unpack('L')
end

.FlushConsoleInputBuffer(hConsoleInput) ⇒ Object



44
45
46
47
# File 'lib/Win32/Console/api.rb', line 44

def FlushConsoleInputBuffer( hConsoleInput )
  @FlushConsoleInputBuffer ||= Win32API.new( "kernel32", "FillConsoleInputBuffer", ['l'], 'l' )
  @FlushConsoleInputBuffer.call( hConsoleInput )
end

.FreeConsoleObject



49
50
51
52
# File 'lib/Win32/Console/api.rb', line 49

def FreeConsole()
  @FreeConsole ||= Win32API.new( "kernel32", "FreeConsole", [], 'l' )
  @FreeConsole.call()
end

.GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId) ⇒ Object



54
55
56
57
# File 'lib/Win32/Console/api.rb', line 54

def GenerateConsoleCtrlEvent( dwCtrlEvent, dwProcessGroupId )
  @GenerateConsoleCtrlEvent ||= Win32API.new( "kernel32", "GenerateConsoleCtrlEvent", ['l', 'l'], 'l' )
  @GenerateConsoleCtrlEvent.call( dwCtrlEvent, dwProcessGroupId )
end

.GetConsoleCPObject



59
60
61
62
# File 'lib/Win32/Console/api.rb', line 59

def GetConsoleCP()
  @GetConsoleCP ||= Win32API.new( "kernel32", "GetConsoleCP", [], 'l' )
  @GetConsoleCP.call()
end

.GetConsoleCursorInfo(hConsoleOutput) ⇒ Object



64
65
66
67
68
69
# File 'lib/Win32/Console/api.rb', line 64

def GetConsoleCursorInfo( hConsoleOutput )
  @GetConsoleCursorInfo ||= Win32API.new( "kernel32", "GetConsoleCursorInfo", ['l', 'p'], 'l' )
   lpConsoleCursorInfo = ' ' * 8
  @GetConsoleCursorInfo.call( hConsoleOutput, lpConsoleCursorInfo )
   return lpConsoleCursorInfo.unpack('LL')
end

.GetConsoleMode(hConsoleHandle) ⇒ Object



71
72
73
74
75
76
# File 'lib/Win32/Console/api.rb', line 71

def GetConsoleMode( hConsoleHandle )
  @GetConsoleMode ||= Win32API.new( "kernel32", "GetConsoleMode", ['l', 'p'], 'l' )
  lpMode = ' ' * 4
  @GetConsoleMode.call( hConsoleHandle, lpMode )
  return lpMode.unpack('L').first
end

.GetConsoleOutputCPObject



78
79
80
81
# File 'lib/Win32/Console/api.rb', line 78

def GetConsoleOutputCP()
  @GetConsoleOutputCP ||= Win32API.new( "kernel32", "GetConsoleOutputCP", [], 'l' )
  @GetConsoleOutputCP.call()
end

.GetConsoleScreenBufferInfo(hConsoleOutput) ⇒ Object



83
84
85
86
87
88
# File 'lib/Win32/Console/api.rb', line 83

def GetConsoleScreenBufferInfo( hConsoleOutput )
  @GetConsoleScreenBufferInfo ||= Win32API.new( "kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'l' )
   lpBuffer = ' ' * 22
  @GetConsoleScreenBufferInfo.call( hConsoleOutput, lpBuffer )
   return lpBuffer.unpack('SSSSSssssSS')
end

.GetConsoleTitleObject



90
91
92
93
94
95
96
# File 'lib/Win32/Console/api.rb', line 90

def GetConsoleTitle()
  @GetConsoleTitle ||= Win32API.new( "kernel32", "GetConsoleTitle", ['p', 'l'], 'l' )
  nSize = 120
  lpConsoleTitle = ' ' * nSize
  @GetConsoleTitle.call( lpConsoleTitle, nSize )
  return lpConsoleTitle.strip
end

.GetConsoleWindowObject



98
99
100
101
# File 'lib/Win32/Console/api.rb', line 98

def GetConsoleWindow()
  @GetConsoleWindow ||= Win32API.new( "kernel32", "GetConsoleWindow",[], 'l' )
  @GetConsoleWindow.call()
end

.GetLargestConsoleWindowSize(hConsoleOutput) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/Win32/Console/api.rb', line 103

def GetLargestConsoleWindowSize( hConsoleOutput )
  @GetLargestConsoleWindowSize ||= Win32API.new( "kernel32", "GetLargestConsoleWindowSize", ['l'], 'l' )
  coord = @GetLargestConsoleWindowSize.call( hConsoleOutput )
  x = coord >> 16
  y = coord & 0x0000ffff
  return [x,y]
end

.GetNumberOfConsoleInputEvents(hConsoleInput) ⇒ Object



111
112
113
114
115
116
# File 'lib/Win32/Console/api.rb', line 111

def GetNumberOfConsoleInputEvents( hConsoleInput )
  @GetNumberOfConsoleInputEvents ||= Win32API.new( "kernel32", "GetNumberOfConsoleInputEvents", ['l', 'p'], 'l' )
  lpcNumberOfEvents = 0
  @GetNumberOfConsoleInputEvents.call( hConsoleInput, lpcNumberOfEvents )
  return lpcNumberOfEvents
end

.GetNumberOfConsoleMouseButtonsObject



118
119
120
121
122
123
# File 'lib/Win32/Console/api.rb', line 118

def GetNumberOfConsoleMouseButtons( )
  @GetNumberOfConsoleMouseButtons ||= Win32API.new( "kernel32", "GetNumberOfConsoleMouseButtons", ['p'], 'l' )
  lpNumberOfMouseButtons = 0
  @GetNumberOfConsoleMouseButtons.call( lpNumberOfMouseButtons )
  return lpNumberOfMouseButtons
end

.GetStdHandle(nStdHandle) ⇒ Object



125
126
127
128
# File 'lib/Win32/Console/api.rb', line 125

def GetStdHandle( nStdHandle )
  @GetStdHandle ||= Win32API.new( "kernel32", "GetStdHandle", ['l'], 'l' )
  @GetStdHandle.call( nStdHandle )
end

.PeekConsoleInput(hConsoleInput) ⇒ Object

<<HandlerRoutine>> : This is not an actual API function, just a concept description in the SDK.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/Win32/Console/api.rb', line 132

def PeekConsoleInput( hConsoleInput )
  @PeekConsoleInput ||= Win32API.new( "kernel32", "PeekConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
  lpNumberOfEventsRead = ' ' * 4
  lpBuffer = ' ' * 20
  nLength  = 20
  @PeekConsoleInput.call( hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead )
  type = lpBuffer.unpack('s')[0]

  case type
  when KEY_EVENT
    return lpBuffer.unpack('sSSSSCS')
  when MOUSE_EVENT
    return lpBuffer.unpack('sSSSS')
  when WINDOW_BUFFER_SIZE_EVENT
    return lpBuffer.unpack('sS')
  when MENU_EVENT
    return lpBuffer.unpack('sS')
  when FOCUS_EVENT
    return lpBuffer.unpack('sS')
  else
    return []
  end
end

.ReadConsole(hConsoleInput, lpBuffer, nNumberOfCharsToRead) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/Win32/Console/api.rb', line 156

def ReadConsole( hConsoleInput, lpBuffer, nNumberOfCharsToRead )
  @ReadConsole ||= Win32API.new( "kernel32", "ReadConsole", ['l', 'p', 'l', 'p', 'p'], 'l' )
  lpBuffer = ' ' * nNumberOfCharsToRead unless lpBuffer
  lpNumberOfCharsRead = ' ' * 4
  lpReserved = ' ' * 4
  @ReadConsole.call( hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved )
  return lpNumberOfCharsRead.unpack('L')
end

.ReadConsoleInput(hConsoleInput) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/Win32/Console/api.rb', line 165

def ReadConsoleInput( hConsoleInput )
  @ReadConsoleInput ||= Win32API.new( "kernel32", "ReadConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
  lpNumberOfEventsRead = ' ' * 4
  lpBuffer = ' ' * 20
  nLength  = 20
  @ReadConsoleInput.call( hConsoleInput, lpBuffer, nLength,
                            lpNumberOfEventsRead )
  type = lpBuffer.unpack('s')[0]

  case type
  when KEY_EVENT
    return lpBuffer.unpack('sSSSSCS')
  when MOUSE_EVENT
    return lpBuffer.unpack('sSSSS')
  when WINDOW_BUFFER_SIZE_EVENT
    return lpBuffer.unpack('sS')
  when MENU_EVENT
    return lpBuffer.unpack('sS')
  when FOCUS_EVENT
    return lpBuffer.unpack('sS')
  else
    return []
  end
end

.ReadConsoleOutput(hConsoleOutput, lpBuffer, cols, rows, bufx, bufy, left, top, right, bottom) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/Win32/Console/api.rb', line 190

def ReadConsoleOutput( hConsoleOutput, lpBuffer, cols, rows, bufx, bufy, left, top, right, bottom )
  @ReadConsoleOutput ||= Win32API.new( "kernel32", "ReadConsoleOutput", ['l', 'p', 'l', 'l', 'p'], 'l' )
  dwBufferSize  = cols * rows * 4
  lpBuffer = ' ' * dwBufferSize
  dwBufferCoord = (bufy << 16) + bufx
  lpReadRegion  = [ left, top, right, bottom ].pack('ssss')
  @ReadConsoleOutput.call( hConsoleOutput, lpBuffer, dwBufferSize,
                             dwBufferCoord, lpReadRegion )
end

.ReadConsoleOutputAttribute(hConsoleOutput, nLength, col, row) ⇒ Object



200
201
202
203
204
205
206
207
# File 'lib/Win32/Console/api.rb', line 200

def ReadConsoleOutputAttribute( hConsoleOutput, nLength, col, row )
  @ReadConsoleOutputAttribute ||= Win32API.new( "kernel32", "ReadConsoleOutputAttribute", ['l', 'p', 'l', 'l', 'p'], 'l' )
  lpAttribute = ' ' * nLength
  dwReadCoord = (row << 16) + col
  lpNumberOfAttrsRead = ' ' * 4
  @ReadConsoleOutputAttribute.call( hConsoleOutput, lpAttribute, nLength, dwReadCoord, lpNumberOfAttrsRead )
  return lpAttribute
end

.ReadConsoleOutputCharacter(hConsoleOutput, lpCharacter, nLength, col, row) ⇒ Object



209
210
211
212
213
214
215
# File 'lib/Win32/Console/api.rb', line 209

def ReadConsoleOutputCharacter( hConsoleOutput, lpCharacter, nLength,  col, row )
  @ReadConsoleOutputCharacter ||= Win32API.new( "kernel32", "ReadConsoleOutputCharacter", ['l', 'p', 'l', 'l', 'p'], 'l' )
  dwReadCoord = (row << 16) + col
  lpNumberOfCharsRead = ' ' * 4
  @ReadConsoleOutputCharacter.call( hConsoleOutput, lpCharacter, nLength, dwReadCoord, lpNumberOfCharsRead )
  return lpNumberOfCharsRead.unpack('L')
end

.ScrollConsoleScreenBuffer(hConsoleOutput, left1, top1, right1, bottom1, col, row, char, attr, left2, top2, right2, bottom2) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/Win32/Console/api.rb', line 217

def ScrollConsoleScreenBuffer( hConsoleOutput, left1, top1, right1, bottom1,col, row, char, attr, left2, top2, right2, bottom2 )
  @ScrollConsoleScreenBuffer ||= Win32API.new( "kernel32", "ScrollConsoleScreenBuffer", ['l', 'p', 'p', 'l', 'p'], 'l' )
  lpScrollRectangle = [left1, top1, right1, bottom1].pack('ssss')
  lpClipRectangle   = [left2, top2, right2, bottom2].pack('ssss')
  dwDestinationOrigin = (row << 16) + col
  lpFill = [char, attr].pack('ss')
  @ScrollConsoleScreenBuffer.call( hConsoleOutput, lpScrollRectangle, lpClipRectangle, dwDestinationOrigin, lpFill )
end

.SetConsoleActiveScreenBuffer(hConsoleOutput) ⇒ Object



226
227
228
229
# File 'lib/Win32/Console/api.rb', line 226

def SetConsoleActiveScreenBuffer( hConsoleOutput )
  @SetConsoleActiveScreenBuffer ||= Win32API.new( "kernel32", "SetConsoleActiveScreenBuffer", ['l'], 'l' )
  @SetConsoleActiveScreenBuffer.call( hConsoleOutput )
end

.SetConsoleCP(wCodePageID) ⇒ Object

<<SetConsoleCtrlHandler>>: Will probably not be implemented.



233
234
235
236
# File 'lib/Win32/Console/api.rb', line 233

def SetConsoleCP( wCodePageID )
  @SetConsoleCP ||= Win32API.new( "kernel32", "SetConsoleCP", ['l'], 'l' )
  @SetConsoleCP.call( wCodePageID )
end

.SetConsoleCursorInfo(hConsoleOutput, col, row) ⇒ Object



238
239
240
241
242
# File 'lib/Win32/Console/api.rb', line 238

def SetConsoleCursorInfo( hConsoleOutput, col, row )
  @SetConsoleCursorInfo ||= Win32API.new( "kernel32", "SetConsoleCursorInfo", ['l', 'p'], 'l' )
  lpConsoleCursorInfo = [size,visi].pack('LL')
  @SetConsoleCursorInfo.call( hConsoleOutput, lpConsoleCursorInfo )
end

.SetConsoleCursorPosition(hConsoleOutput, col, row) ⇒ Object



244
245
246
247
248
# File 'lib/Win32/Console/api.rb', line 244

def SetConsoleCursorPosition( hConsoleOutput, col, row )
  @SetConsoleCursorPosition ||= Win32API.new( "kernel32", "SetConsoleCursorPosition", ['l', 'p'], 'l' )
  dwCursorPosition = (row << 16) + col
  @SetConsoleCursorPosition.call( hConsoleOutput, dwCursorPosition )
end

.SetConsoleMode(hConsoleHandle, lpMode) ⇒ Object



250
251
252
253
# File 'lib/Win32/Console/api.rb', line 250

def SetConsoleMode( hConsoleHandle, lpMode )
  @SetConsoleMode ||= Win32API.new( "kernel32", "SetConsoleMode", ['l', 'p'], 'l' )
  @SetConsoleMode.call( hConsoleHandle, lpMode )
end

.SetConsoleOutputCP(wCodePageID) ⇒ Object



255
256
257
258
# File 'lib/Win32/Console/api.rb', line 255

def SetConsoleOutputCP( wCodePageID )
  @SetConsoleOutputCP ||= Win32API.new( "kernel32", "GetConsoleOutputCP", ['l'], 'l' )
  @SetConsoleOutputCP.call( wCodePageID )
end

.SetConsoleScreenBufferSize(hConsoleOutput, col, row) ⇒ Object



260
261
262
263
264
# File 'lib/Win32/Console/api.rb', line 260

def SetConsoleScreenBufferSize( hConsoleOutput, col, row )
  @SetConsoleScreenBufferSize ||= Win32API.new( "kernel32", "SetConsoleScreenBufferSize", ['l', 'l'], 'l' )
  dwSize = (row << 16) + col
  @SetConsoleScreenBufferSize.call( hConsoleOutput, dwSize )
end

.SetConsoleTextAttribute(hConsoleOutput, wAttributes) ⇒ Object



266
267
268
269
# File 'lib/Win32/Console/api.rb', line 266

def SetConsoleTextAttribute( hConsoleOutput, wAttributes )
  @SetConsoleTextAttribute ||= Win32API.new( "kernel32", "SetConsoleTextAttribute", ['l', 'i'], 'l' )
  @SetConsoleTextAttribute.call( hConsoleOutput, wAttributes )
end

.SetConsoleTitle(lpConsoleTitle) ⇒ Object



271
272
273
274
# File 'lib/Win32/Console/api.rb', line 271

def SetConsoleTitle( lpConsoleTitle )
  @SetConsoleTitle ||= Win32API.new( "kernel32", "SetConsoleTitle", ['p'], 'l' )
  @SetConsoleTitle.call( lpConsoleTitle )
end

.SetConsoleWindowInfo(hConsoleOutput, bAbsolute, left, top, right, bottom) ⇒ Object



276
277
278
279
280
# File 'lib/Win32/Console/api.rb', line 276

def SetConsoleWindowInfo( hConsoleOutput, bAbsolute, left, top, right, bottom )
  @SetConsoleWindowInfo ||= Win32API.new( "kernel32", "SetConsoleWindowInfo", ['l', 'l', 'p'], 'l' )
  lpConsoleWindow = [ left, top, right, bottom ].pack('ssss')
  @SetConsoleWindowInfo.call( hConsoleOutput, bAbsolute, lpConsoleWindow )
end

.SetStdHandle(nStdHandle, hHandle) ⇒ Object



282
283
284
285
# File 'lib/Win32/Console/api.rb', line 282

def SetStdHandle( nStdHandle, hHandle )
  @SetStdHandle ||= Win32API.new( "kernel32", "SetStdHandle", ['l', 'l'], 'l' )
  @SetStdHandle.call( nStdHandle, hHandle )
end

.WriteConsole(hConsoleOutput, lpBuffer) ⇒ Object



287
288
289
290
291
292
293
294
# File 'lib/Win32/Console/api.rb', line 287

def WriteConsole( hConsoleOutput, lpBuffer )
  @WriteConsole ||= Win32API.new( "kernel32", "WriteConsole", ['l', 'p', 'l', 'p', 'p'], 'l' )
  nNumberOfCharsToWrite = lpBuffer.length()
  lpNumberOfCharsWritten = ' ' * 4
  lpReserved = ' ' * 4
  @WriteConsole.call( hConsoleOutput, lpBuffer, nNumberOfCharsToWrite, lpNumberOfCharsWritten,  lpReserved )
  return lpNumberOfCharsWritten
end

.WriteConsoleInput(hConsoleInput, lpBuffer) ⇒ Object



305
306
307
308
# File 'lib/Win32/Console/api.rb', line 305

def WriteConsoleInput( hConsoleInput, lpBuffer )
  @WriteConsoleInput ||= Win32API.new( "kernel32", "WriteConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
  @WriteConsoleInput.call( hConsoleInput, lpBuffer, nLength,  lpNumberOfEventsWritten )
end

.WriteConsoleOutput(hConsoleOutput, buffer, cols, rows, bufx, bufy, left, top, right, bottom) ⇒ Object

@@ Todo: Test this



311
312
313
314
315
316
317
318
# File 'lib/Win32/Console/api.rb', line 311

def WriteConsoleOutput( hConsoleOutput, buffer, cols, rows, bufx, bufy, left, top, right, bottom )
  @WriteConsoleOutput ||= Win32API.new( "kernel32", "WriteConsoleOutput", ['l', 'p', 'l', 'l', 'p'], 'l' )
  lpBuffer = buffer.flatten.pack('ss' * buffer.length() * 2)
  dwBufferSize = (buffer.length() << 16) + 2
  dwBufferCoord = (row << 16) + col
  lpWriteRegion = [ left, top, right, bottom ].pack('ssss')
  @WriteConsoleOutput.call( hConsoleOutput, lpBuffer, dwBufferSize, dwBufferCoord, lpWriteRegion )
end

.WriteConsoleOutputAttribute(hConsoleOutput, lpAttribute, col, row) ⇒ Object



320
321
322
323
324
325
326
327
# File 'lib/Win32/Console/api.rb', line 320

def WriteConsoleOutputAttribute( hConsoleOutput, lpAttribute, col, row )
  @WriteConsoleOutputAttribute ||= Win32API.new( "kernel32", "WriteConsoleOutputAttribute", ['l', 'p', 'l', 'l', 'p'], 'l' )
  nLength = lpAttribute.length()
  dwWriteCoord = (row << 16) + col
  lpNumberOfAttrsWritten = ' ' * 4
  @WriteConsoleOutputAttribute.call( hConsoleOutput, lpAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
  return lpNumberOfAttrsWritten.unpack('L')
end

.WriteConsoleOutputCharacter(hConsoleOutput, lpCharacter, col, row) ⇒ Object



329
330
331
332
333
334
335
336
# File 'lib/Win32/Console/api.rb', line 329

def WriteConsoleOutputCharacter( hConsoleOutput, lpCharacter, col, row )
  @WriteConsoleOutputCharacter ||= Win32API.new( "kernel32", "WriteConsoleOutputCharacter", ['l', 'p', 'l', 'l', 'p'], 'l' )
  nLength = lpCharacter.length()
  dwWriteCoord = (row << 16) + col
  lpNumberOfCharsWritten = ' ' * 4
  @WriteConsoleOutputCharacter.call( hConsoleOutput, lpCharacter, nLength, dwWriteCoord, lpNumberOfCharsWritten )
  return lpNumberOfCharsWritten.unpack('L')
end

.WriteFile(hConsoleOutput, lpBuffer) ⇒ Object



296
297
298
299
300
301
302
303
# File 'lib/Win32/Console/api.rb', line 296

def WriteFile( hConsoleOutput, lpBuffer )
  @WriteFile ||= Win32API.new( "kernel32", "WriteFile", ['l', 'p', 'l', 'p', 'p'], 'l' )
  nNumberOfBytesToWrite = lpBuffer.length()
  lpNumberOfBytesWritten = ' ' * 4
  lpReserved = nil
  @WriteFile.call( hConsoleOutput, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,  lpReserved )
  return lpNumberOfBytesWritten.unpack('L')
end