我正在尝试从控制台应用程序调用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 结构在这里被我第一次使用,我感觉错误在于我的翻译中的某个地方。