如何在 Forth 中使用 ReadConsoleOutputCharacterA?
How to use ReadConsoleOutputCharacterA in Forth?
我用
WINAPI: ReadConsoleOutputCharacterA KERNEL32.DLL
这似乎可行,但如何处理输入和输出参数?特别是,如何获得
hConsoleOutput [in] A handle to the console screen buffer. The handle
must have the GENERIC_READ access right. For more information, see
Console Buffer Security and Access Rights.
hConsoleOutput
只是一个合适的句柄。 ReadConsoleOutputCharacter
的一些用法示例可以在 devel
目录(贡献)中找到。
此 API 用法示例:
\ Global variables in dictionary space just for learning,
\ -- don't use such approach, especially in multithreading.
VARIABLE lpNumberOfCharsRead
CREATE lpCharacter 5 CHARS ALLOT \ buffer for 5 chars
: XYC@ ( x y -- c )
16 LSHIFT OR >R \ COORD
0 lpCharacter C!
lpNumberOfCharsRead \ _Out_ LPDWORD lpNumberOfCharsRead
R> \ dwReadCoord
1 \ nLength \ to read
lpCharacter \ _Out_ LPTSTR lpCharacter
H-STDOUT
ReadConsoleOutputCharacterA ERR THROW
lpCharacter C@
;
\ test
0 0 XYC@ EMIT
有用的包装器:
: READOUT-CONSOLE-XY ( a-buf u x y -- a-buf u2 ior )
2SWAP 2>R 16 LSHIFT OR >R
0 SP@ R> ( 0 addr-cnt coord )
R> R@ H-STDOUT ( 0 addr-cnt coord u a-buf handle )
ReadConsoleOutputCharacterA ERR ( u2 ior )
R> -ROT
;
\ test
HERE 50 0 0 READOUT-CONSOLE-XY THROW TYPE
我用
WINAPI: ReadConsoleOutputCharacterA KERNEL32.DLL
这似乎可行,但如何处理输入和输出参数?特别是,如何获得
hConsoleOutput [in] A handle to the console screen buffer. The handle must have the GENERIC_READ access right. For more information, see Console Buffer Security and Access Rights.
hConsoleOutput
只是一个合适的句柄。 ReadConsoleOutputCharacter
的一些用法示例可以在 devel
目录(贡献)中找到。
此 API 用法示例:
\ Global variables in dictionary space just for learning,
\ -- don't use such approach, especially in multithreading.
VARIABLE lpNumberOfCharsRead
CREATE lpCharacter 5 CHARS ALLOT \ buffer for 5 chars
: XYC@ ( x y -- c )
16 LSHIFT OR >R \ COORD
0 lpCharacter C!
lpNumberOfCharsRead \ _Out_ LPDWORD lpNumberOfCharsRead
R> \ dwReadCoord
1 \ nLength \ to read
lpCharacter \ _Out_ LPTSTR lpCharacter
H-STDOUT
ReadConsoleOutputCharacterA ERR THROW
lpCharacter C@
;
\ test
0 0 XYC@ EMIT
有用的包装器:
: READOUT-CONSOLE-XY ( a-buf u x y -- a-buf u2 ior )
2SWAP 2>R 16 LSHIFT OR >R
0 SP@ R> ( 0 addr-cnt coord )
R> R@ H-STDOUT ( 0 addr-cnt coord u a-buf handle )
ReadConsoleOutputCharacterA ERR ( u2 ior )
R> -ROT
;
\ test
HERE 50 0 0 READOUT-CONSOLE-XY THROW TYPE