我正在尝试调用 GetConsoleScreenBufferInfoEx来自控制台应用程序的函数。如果重要的话,该应用程序是在 64 位 Windows 7 上运行的 32 位应用程序。语言是 RealBasic。
我相信我已经正确定义了所有结构,并且缓冲区输出句柄适用于正在调用的每个其他 API 函数:
Declare Function GetConsoleScreenBufferInfoEx Lib "Kernel32" (cHandle As Integer, ByRef info As CONSOLE_SCREEN_BUFFER_INFOEX) As Boolean
Declare Function GetLastError Lib "Kernel32" () As Integer
Declare Function GetStdHandle Lib "Kernel32" (hIOStreamType As Integer) As Integer
Const STD_OUTPUT_HANDLE = -11
Dim stdHandle As Integer = GetStdHandle(STD_OUTPUT_HANDLE)
Dim err As Integer
Dim info As CONSOLE_SCREEN_BUFFER_INFOEX
If GetConsoleScreenBufferInfoEx(stdHandle, info) Then
Break
Else
err = GetLastError //Always 87, Invalid parameter
Break
End If
结构:
Structure CONSOLE_SCREEN_BUFFER_INFOEX
cbSize As Integer
dwSize As COORD
CursorPosition As COORD
Attribute As UInt16
srWindow As SMALL_RECT
MaxWindowSize As COORD
PopupAttributes As UInt16
FullScreenSupported As Boolean
ColorTable(15) As UInt32
Structure COORD
X As UInt16
Y As UInt16
Structure SMALL_RECT
Left As UInt16
Top As UInt16
Right As UInt16
Bottom As UInt16
我已经把这个问题看了 20 遍了,我觉得没有什么问题。我之前多次使用过 COORD 和 SMALL_RECT 结构,所以我不认为我对它们犯了任何翻译错误。然而,CONSOLE_SCREEN_BUFFER_INFOEX 结构是我在这里第一次使用的,我感觉错误出在我对它的翻译中的某个地方。
最佳答案
在发送之前,您需要设置 CONSOLE_SCREEN_BUFFER_INFOEX
的 cbSize 参数。GetConsoleScreenBufferInfoEx
将检查它的大小是否正确,这就是它返回无效参数的原因.
因此在调用 GetConsoleScreenBufferInfoEx
之前添加:
info.cbSize = 96
或者更好的是 Real Basic 确实允许您访问 structure 的大小:
info.cbSize = GetConsoleScreenBufferInfoEx.Size
它应该为您处理计算。
关于winapi - GetConsoleScreenBufferInfoEx 由于参数无效而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9222314/