本文整理汇总了Golang中C.GetLastError函数的典型用法代码示例。如果您正苦于以下问题:Golang GetLastError函数的具体用法?Golang GetLastError怎么用?Golang GetLastError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetLastError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initializeFromSettings
func (ic *contextInternal) initializeFromSettings(settings ContextSettings, width, height int) ThreadError {
ic.deactivateSignal = make(chan bool)
ic.settings = settings
ic.window = createHiddenWindow(width, height)
if ic.window == nil {
// C.GetLastError()
return NewThreadError(fmt.Errorf("could not create window (%d)", C.GetLastError()), true)
}
ic.ownsWindow = true
ic.hdc = C.GetDC(ic.window)
if ic.hdc == nil {
return NewThreadError(errors.New("no device context"), true)
}
if sharedContext == nil { // if there is no shared context, we are it
ic.isSharedContext = true
pfd := C.PIXELFORMATDESCRIPTOR{
nSize: C.PIXELFORMATDESCRIPTOR_size, // size of this pfd
nVersion: 1, // version number
iPixelType: C.PFD_TYPE_RGBA, // RGBA type
cColorBits: 24, // 24-bit color depth
cDepthBits: 32, // 32-bit z-buffer
iLayerType: C.PFD_MAIN_PLANE, // main layer
// support window | OpenGL | double buffer
dwFlags: C.PFD_DRAW_TO_WINDOW | C.PFD_SUPPORT_OPENGL | C.PFD_DOUBLEBUFFER,
}
// get the best available match of pixel format for the device context
// make that the pixel format of the device context
if iPixelFormat := C.ChoosePixelFormat(ic.hdc, &pfd); iPixelFormat == 0 {
return NewThreadError(fmt.Errorf("sharedContext: ChoosePixelFormat failed (%d)", C.GetLastError()), true)
} else if C.SetPixelFormat(ic.hdc, iPixelFormat, &pfd) == C.FALSE {
return NewThreadError(fmt.Errorf("sharedContext: SetPixelFormat failed (%d)", C.GetLastError()), true)
}
ic.context = C.wglCreateContext(ic.hdc)
if ic.context == nil {
return NewThreadError(fmt.Errorf("sharedContext: wglCreateContext failed (%d)", C.GetLastError()), true)
}
} else { // otherwise we push the commands onto the shared context thread
bitsPerPixel := GetDefaultMonitor().GetDesktopMode().BitsPerPixel
ic.context = createContext(&sharedContext.internal.procs, sharedContext.internal.context, ic.hdc, bitsPerPixel, &ic.settings)
if ic.context == nil {
return NewThreadError(fmt.Errorf("could not create context (%d)", C.GetLastError()), true)
}
}
// signal because we start out deactivated
ic.signalDeactivation()
return nil
}
示例2: getNativeName
func getNativeName(DeviceInfoSet C.HDEVINFO, DeviceInfoData C.PSP_DEVINFO_DATA) (string, error) {
key := C.SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, C.DICS_FLAG_GLOBAL, 0, C.DIREG_DEV, C.KEY_READ)
defer C.RegCloseKey(key)
if C.is_INVALID_HANDLE_VALUE(unsafe.Pointer(key)) != C.FALSE {
return "", errors.New(fmt.Sprintf("Reg error: %d", int(C.GetLastError())))
}
var i C.DWORD = 0
var keyType C.DWORD = 0
buffKeyName := make([]C.CHAR, 16384)
buffKeyVal := make([]C.BYTE, 16384)
for {
var lenKeyName C.DWORD = C.DWORD(cap(buffKeyName))
var lenKeyValue C.DWORD = C.DWORD(cap(buffKeyVal))
ret := C.RegEnumValue(key, i, &buffKeyName[0], &lenKeyName, (*C.DWORD)(nil), &keyType, &buffKeyVal[0], &lenKeyValue)
i++
if ret == C.ERROR_SUCCESS {
if keyType == C.REG_SZ {
itemName := C.GoString((*C.char)(&buffKeyName[0]))
itemValue := C.GoString((*C.char)(unsafe.Pointer((&buffKeyVal[0]))))
if strings.Contains(itemName, "PortName") {
return itemValue, nil
}
}
} else {
break
}
}
return "", errors.New("Empty response")
}
示例3: pause
// Deactivate, signal, wait for response, activate
func (ic *contextInternal) pause(signal chan bool) ThreadError {
// disable the current context
if C.wglMakeCurrent(ic.hdc, nil) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
// let the other thread know and then wait for them
signal <- true
<-signal
// start up the context
if C.wglMakeCurrent(ic.hdc, ic.context) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
return nil
}
示例4: release
// Temporary deactivate the context
func (ic *contextInternal) release() ThreadError {
// disable the current context
if C.wglMakeCurrent(ic.hdc, nil) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
return nil
}
示例5: take
// Temporary activate the context
func (ic *contextInternal) take() ThreadError {
// start up the context
if C.wglMakeCurrent(ic.hdc, ic.context) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
return nil
}
示例6: Get
func (self *ProcList) Get() error {
var enumSize int
var pids [1024]C.DWORD
// If the function succeeds, the return value is nonzero.
ret, _, _ := procEnumProcesses.Call(
uintptr(unsafe.Pointer(&pids[0])),
uintptr(unsafe.Sizeof(pids)),
uintptr(unsafe.Pointer(&enumSize)),
)
if ret == 0 {
return fmt.Errorf("error %d while reading processes", C.GetLastError())
}
results := []int{}
pids_size := enumSize / int(unsafe.Sizeof(pids[0]))
for _, pid := range pids[:pids_size] {
results = append(results, int(pid))
}
self.List = results
return nil
}
示例7: setIcon
// Change the window's icon
func (wi *windowInternal) setIcon(icon image.Image) error {
// First destroy the previous one
if wi.icon != nil {
C.DestroyIcon(wi.icon)
}
type BGRA [4]uint8
// Windows wants BGRA pixels: swap red and blue channels
Rect := icon.Bounds()
iconPixels := make([]BGRA, Rect.Dy()*Rect.Dx())
for i, y := 0, 0; y < Rect.Dy(); y++ {
for x := 0; x < Rect.Dx(); x++ {
r, g, b, a := icon.At(x, y).RGBA()
iconPixels[i][0] = uint8(b)
iconPixels[i][1] = uint8(g)
iconPixels[i][2] = uint8(r)
iconPixels[i][3] = uint8(a)
}
}
// Create the icon from the pixel array
width, height := C.int(Rect.Dx()), C.int(Rect.Dy())
wi.icon = C.CreateIcon(C.GetModuleHandle(nil), width, height, 1, 32, nil, (*C.BYTE)(&iconPixels[0][0]))
if wi.icon == nil {
return fmt.Errorf("could not create icon (%d)", C.GetLastError())
}
C.SendMessage(wi.window.Handle, C.WM_SETICON, C.ICON_BIG, C.LPARAM(uintptr(unsafe.Pointer(wi.icon))))
C.SendMessage(wi.window.Handle, C.WM_SETICON, C.ICON_SMALL, C.LPARAM(uintptr(unsafe.Pointer(wi.icon))))
return nil
}
示例8: setMousePosition
// Set the current position of the mouse in window coordinates
func (wi *windowInternal) setMousePosition(x, y int) ThreadError {
if !wi.window.IsValid() {
// TODO ERROR
return nil
}
point := C.POINT{x: C.LONG(x), y: C.LONG(y)}
if C.__ScreenToClient(wi.window.Handle, &point) == 0 {
return NewThreadError(fmt.Errorf("ScreenToClient (%d)", C.GetLastError()), false)
}
if C.SetCursorPos(C.int(x), C.int(y)) == 0 {
return NewThreadError(fmt.Errorf("SetCursorPos (%d)", C.GetLastError()), false)
}
return nil
}
示例9: SetWallPaper
func SetWallPaper(file_path string) error {
path := []byte(file_path)
result := int(C.SystemParametersInfo(C.SPI_SETDESKWALLPAPER, 0, C.PVOID(unsafe.Pointer(&path[0])), C.SPIF_UPDATEINIFILE))
if result != C.TRUE {
return fmt.Errorf("", C.GetLastError())
}
return nil
}
示例10: getMousePosition
// Get the current position of the mouse in window coordinates
func (wi *windowInternal) getMousePosition() (x, y int, err ThreadError) {
if !wi.window.IsValid() {
// TODO ERROR
return
}
var point C.POINT
if C.__GetCursorPos(&point) == 0 {
err = NewThreadError(fmt.Errorf("GetCursorPos (%d)", C.GetLastError()), false)
return
}
if C.__ScreenToClient(wi.window.Handle, &point) == 0 {
err = NewThreadError(fmt.Errorf("ScreenToClient (%d)", C.GetLastError()), false)
return
}
return int(point.x), int(point.y), nil
}
示例11: getMousePosition
// Get the current position of the mouse in desktop coordinates
func getMousePosition() (x, y int) {
x, y = -1, -1
var point C.POINT
if C.__GetCursorPos(&point) == 0 {
C.GetLastError()
return
}
return int(point.x), int(point.y)
}
示例12: deactivate
// Deactivate the context as the current target for rendering
func (ic *contextInternal) deactivate() ThreadError {
// disable the current context
if C.wglMakeCurrent(ic.hdc, nil) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
// end by signaling
ic.signalDeactivation()
return nil
}
示例13: Get
func (self *Mem) Get() error {
var statex C.MEMORYSTATUSEX
statex.dwLength = C.DWORD(unsafe.Sizeof(statex))
succeeded := C.GlobalMemoryStatusEx(&statex)
if succeeded == C.FALSE {
lastError := C.GetLastError()
return fmt.Errorf("GlobalMemoryStatusEx failed with error: %d", int(lastError))
}
self.Total = uint64(statex.ullTotalPhys)
return nil
}
示例14: activate
// Activate the context as the current target for rendering
func (ic *contextInternal) activate() ThreadError {
// start by waiting for deactivation to finish
<-ic.deactivateSignal
// start up the context
if C.wglMakeCurrent(ic.hdc, ic.context) == C.FALSE {
return NewThreadError(fmt.Errorf("wglMakeCurrent failed (%d)", C.GetLastError()), true)
}
// Load all the functions and such
C.wglLoadProcs(&ic.procs)
return nil
}
示例15: setVerticalSyncEnabled
func (ic *contextInternal) setVerticalSyncEnabled(enabled bool) ThreadError {
var interval C.int
if enabled {
interval = 1
}
if ic.procs.p_wglSwapIntervalEXT == nil {
return NewThreadError(fmt.Errorf("wglSwapIntervalEXT == nil (%d)", ic.procs.error_wglSwapIntervalEXT), false)
}
if C.__wglSwapIntervalEXT(&ic.procs, interval) == C.FALSE {
return NewThreadError(fmt.Errorf("wglSwapIntervalEXT failed (%d)", C.GetLastError()), false)
}
return nil
}