Created
December 3, 2012 05:39
-
-
Save yongzhy/4192984 to your computer and use it in GitHub Desktop.
Call functions from Windows DLL file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+build windows | |
package colorterm | |
import ( | |
"syscall" | |
"unsafe" | |
) | |
type ( | |
HANDLE uintptr | |
) | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119.aspx | |
type _COORD struct { | |
X, Y uint16 | |
} | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686311.aspx | |
type _SMALL_RECT struct { | |
Left, Top, Right, Bottom uint16 | |
} | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093.aspx | |
type _CONSOLE_SCREEN_BUFFER_INFO struct { | |
DwSize _COORD | |
DwCursorPosition _COORD | |
WAttributes uint16 | |
SrWindow _SMALL_RECT | |
DwMaximumWindowSize _COORD | |
} | |
var ( | |
modkernel32 = syscall.NewLazyDLL("kernel32.dll") | |
procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo") | |
procSetConsoleTextAttribute = modkernel32.NewProc("SetConsoleTextAttribute") | |
procSetConsoleTitle = modkernel32.NewProc("SetConsoleTitle") | |
procSetConsoleCursorPosition = modkernel32.NewProc("SetConsoleCursorPosition") | |
procFillConsoleOutputCharacter = modkernel32.NewProc("FillConsoleOutputCharacter") | |
procFillConsoleOutputAttribute = modkernel32.NewProc("FillConsoleOutputAttribute") | |
procGetStdHandle = modkernel32.NewProc("GetStdHandle") | |
) | |
func GetConsoleScreenBufferInfo(hConsoleOutput HANDLE) *CONSOLE_SCREEN_BUFFER_INFO { | |
var csbi CONSOLE_SCREEN_BUFFER_INFO | |
ret, _, _ := procGetConsoleScreenBufferInfo.Call( | |
uintptr(hConsoleOutput), | |
uintptr(unsafe.Pointer(&csbi))) | |
if ret == 0 { | |
return nil | |
} | |
return &csbi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment