gpt4 book ai didi

windows - NativeCall 在 Kernel32.dll 中找不到函数

转载 作者:可可西里 更新时间:2023-11-01 13:29:09 24 4
gpt4 key购买 nike

我正在尝试移植 this code到 Perl6。虽然我可以调用 GetStdHandleGetConsoleModeSetConsoleMode,但当我尝试调用 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

现在,该函数是 definitly there .虽然它有一个复杂的签名,但我不确定我的脚本是否正确。这可能是原因吗? NativeCall 看签名吗?

这就是我在代码中定义 sub 的方式(注释取自 MS 文档)

#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 { * };

如果需要,我可以发布我的其余代码,但它是很多样板文件,因为我必须定义所有结构和内容,并且通常来自头文件。

最佳答案

真正的函数名称是ReadConsoleInputAReadConsoleInputW,这取决于您想要ANSI 还是Unicode (UTF-16) 输入。 C header 具有根据预处理器符号自动将 ReadConsoleInput 转换为正确函数的宏。但是当你像这样在运行时加载函数时,你必须准确指定你想要的函数。

关于windows - NativeCall 在 Kernel32.dll 中找不到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57582796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com