我试图从控制台应用程序调用GetConsoleScreenBufferInfoEx函数。如果重要,应用程序是在64位Windows 7上运行的32位应用程序。语言是RealBasic。GetConsoleScreenBufferInfoEx由于参数无效而失败
我相信我已经正确定义所有的结构和缓冲输出手柄适用于所调用所有其他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结构在我看来是第一次使用它,并且我感觉到错误在我的翻译中。
嗯是的,但**不硬编码的大小**!这是编译器的目的。 – 2012-02-10 03:45:04
有趣的是,我已经尝试了这一点,我*没有*硬编码的大小。如果我使用'96'(硬编码),则该功能成功。如果我加上结构的所有成员,就像我定义的那样,大小是** 93 **。所以,结构定义看起来似乎有错误。 – 2012-02-10 04:23:05
@Amazed - 没有错误,这是由于结构对齐 - http://msdn.microsoft.com/en-us/library/71kf49f1%28v=vs.80%29.aspx – shf301 2012-02-10 04:44:06