我試圖從控制檯應用程序調用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