I am trying to port this code to Perl6. While I can call GetStdHandle
, GetConsoleMode
and SetConsoleMode
, my script breaks when I try to call ReadConsoleInput
:
Cannot locate symbol 'ReadConsoleInput' in native library 'Kernel32.dll'
in method setup at C:\rakudo\share\perl6\sources\947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 287
in method CALL-ME at C:\rakudo\share\perl6\sources\947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 576
in block <unit> at test.p6 line 149
Now, that function is definitly there. It has a a complex signature though, which I am not sure I got right in my script. Could that be the reason? Does NativeCall look at the signature?
This is how I defined the sub in my code (the comment is taken from the MS docs)
#BOOL WINAPI ReadConsoleInput( _In_ HANDLE hConsoleInput, _Out_ PINPUT_RECORD lpBuffer, _In_ DWORD nLength, _Out_ LPDWORD lpNumberOfEventsRead );
sub ReadConsoleInput(Pointer[void], INPUT_RECORD is rw, uint32, uint32 is rw) is native('Kernel32') returns Bool { * };
I can post the rest my code if needed, but it is A LOT of boilerplate because of all the structs and stuff I have to define and which usually come from header files.
The real function name is ReadConsoleInputA
or ReadConsoleInputW
, depending on whether you want ANSI or Unicode (UTF-16) input. The C headers have macros that automatically translate ReadConsoleInput
to the correct function based on preprocessor symbols. But when you are loading functions at run-time like this, you have to specify exactly which function you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With