// Find a pixel format with no antialiasing, if not needed or not supported func BestChoosePixelFormat(hdc C.HDC, bitsPerPixel uint, settings *ContextSettings) C.int { // Setup a pixel format descriptor from the rendering settings descriptor := C.PIXELFORMATDESCRIPTOR{ nSize: C.PIXELFORMATDESCRIPTOR_size, nVersion: 1, iLayerType: C.PFD_MAIN_PLANE, dwFlags: C.PFD_DRAW_TO_WINDOW | C.PFD_SUPPORT_OPENGL | C.PFD_DOUBLEBUFFER, iPixelType: C.PFD_TYPE_RGBA, cColorBits: C.BYTE(bitsPerPixel), cDepthBits: C.BYTE(settings.DepthBits), cStencilBits: C.BYTE(settings.StencilBits), } if bitsPerPixel == 32 { descriptor.cAlphaBits = 8 } // Get the pixel format that best matches our requirements return C.ChoosePixelFormat(hdc, &descriptor) }
func newHandle(c *Config) (handle syscall.Handle, err error) { handle, err = syscall.CreateFile( syscall.StringToUTF16Ptr(c.Address), syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, // mode nil, // security syscall.OPEN_EXISTING, // create mode 0, // attributes 0) // templates if err != nil { return } defer func() { if err != nil { syscall.CloseHandle(handle) } }() var dcb C.DCB dcb.BaudRate = C.DWORD(c.BaudRate) // Data bits if c.DataBits == 0 { dcb.ByteSize = 8 } else { dcb.ByteSize = C.BYTE(c.DataBits) } // Stop bits switch c.StopBits { case 0, 1: // Default is one stop bit. dcb.StopBits = C.ONESTOPBIT case 2: dcb.StopBits = C.TWOSTOPBITS default: err = fmt.Errorf("serial: unsupported stop bits %v", c.StopBits) return } // Parity switch c.Parity { case "", "E": // Default parity mode is Even. dcb.Parity = C.EVENPARITY case "O": dcb.Parity = C.ODDPARITY case "N": dcb.Parity = C.NOPARITY default: err = fmt.Errorf("serial: unsupported parity %v", c.Parity) return } if C.SetCommState(C.HANDLE(handle), &dcb) == 0 { err = fmt.Errorf("serial: could not set device state: %v", syscall.GetLastError()) return } return }
func (com *WinCom) Set(info *ComInfo) error { var dcb C.DCB dcb.BaudRate = C.DWORD(info.BaudRate) dcb.ByteSize = C.BYTE(info.DataBit) if info.Parity == NPBit { dcb.Parity = C.NOPARITY } if info.StopBits == SB1 { dcb.StopBits = C.ONESTOPBIT } ret := C.com_set(C.int(com.fd), &dcb) if ret < 0 { return &WinComErr{"Set Com", "fail"} } return nil }
//Execute stored procedure by name and list of params. // //Example: // conn.ExecSp("sp_help", "authors") func (conn *Conn) ExecSp(spName string, params ...interface{}) (*SpResult, error) { //hold references to data sent to the C code until the end of this function //without this GC could remove something used later in C, and we will get SIGSEG refHolder := make([]*[]byte, 0) conn.clearMessages() name := C.CString(spName) defer C.free(unsafe.Pointer(name)) if C.dbrpcinit(conn.dbproc, name, 0) == C.FAIL { return nil, conn.raiseError("dbrpcinit failed") } //input params spParams, err := conn.getSpParams(spName) if err != nil { return nil, err } for i, spParam := range spParams { //get datavalue for the suplied stored procedure parametar var datavalue *C.BYTE datalen := C.DBINT(0) if i < len(params) { param := params[i] if param != nil { data, err := typeToSqlBuf(int(spParam.UserTypeId), param) if err != nil { return nil, err } if len(data) > 0 { datalen = C.DBINT(len(data)) datavalue = (*C.BYTE)(unsafe.Pointer(&data[0])) refHolder = append(refHolder, &data) } } } //set parametar valus, call dbrpcparam if i < len(params) || spParam.IsOutput { maxOutputSize := C.DBINT(0) status := C.BYTE(0) if spParam.IsOutput { status = C.DBRPCRETURN maxOutputSize = C.DBINT(spParam.MaxLength) } paramname := C.CString(spParam.Name) defer C.free(unsafe.Pointer(paramname)) if C.dbrpcparam(conn.dbproc, paramname, status, C.int(spParam.UserTypeId), maxOutputSize, datalen, datavalue) == C.FAIL { return nil, errors.New("dbrpcparam failed") } } } //execute if C.dbrpcsend(conn.dbproc) == C.FAIL { return nil, conn.raiseError("dbrpcsend failed") } //results result := NewSpResult() result.results, err = conn.fetchResults() if err != nil { return nil, conn.raise(err) } //return status if C.dbhasretstat(conn.dbproc) == C.TRUE { result.status = int(C.dbretstatus(conn.dbproc)) } //read output params numOutParams := int(C.dbnumrets(conn.dbproc)) result.outputParams = make([]*SpOutputParam, numOutParams) for i := 1; i <= numOutParams; i++ { j := C.int(i) len := C.dbretlen(conn.dbproc, j) name := C.GoString(C.dbretname(conn.dbproc, j)) typ := int(C.dbrettype(conn.dbproc, j)) data := C.GoBytes(unsafe.Pointer(C.dbretdata(conn.dbproc, j)), len) value := sqlBufToType(typ, data) param := &SpOutputParam{Name: name, Value: value} result.outputParams[i-1] = param } return result, nil }