示例#1
0
func main() {
	c := C.struct_columns{15, 30, 45}
	sum := C.sum_columns(c)
	fmt.Println(sum)
	var a int = 15
	var b int = 30
	s := C.sum_vals((C.int)(a), (C.int)(b)) //调用C语言的函数
	fmt.Println(s)
	var goSum int = int(sum) //C语言的int转成Golang的int类型
	fmt.Println(goSum)

	in := []byte("test")
	inLen := len(in)
	out := (*C.uchar)(C.malloc(16))
	outLen := C.uint(16)
	r := C.update((*C.uchar)(&in[0]), C.uint(inLen), out, &outLen)
	if r == 0 {
		fmt.Printf("outlen=%d\n", outLen)

		dst := fmt.Sprintf("%02X", C.GoBytes(unsafe.Pointer(out), C.int(outLen)))
		fmt.Println(dst)
	}

	//C.free(unsafe.Pointer(out))

}
示例#2
0
文件: functions.go 项目: gale320/cgo
func main() {

	c := C.struct_columns{15, 30, 45}

	sum := C.sum_columns(c)
	fmt.Println(sum)

	var a int = 15
	var b int = 30

	s := C.sum_vals((C.int)(a), (C.int)(b))
	fmt.Println(s)
}