Exemplo n.º 1
0
func Create(windowInstance unsafe.Pointer) (obj DirectInput, err error) {
	DirectInput8Create, err := syscall.GetProcAddress(dll, "DirectInput8Create")
	if err != nil {
		return DirectInput{}, err
	}
	err = toError(C.create(
		unsafe.Pointer(DirectInput8Create),
		C.HINSTANCE(windowInstance),
		&obj.handle,
	))
	return
}
Exemplo n.º 2
0
func main() {
	var p *C.PERSON

	name := C.CString("Maria")
	age := C.int(20)

	p = C.create(name, age)

	fmt.Println(C.GoString(p.name)) // Maria: char *는 C.GoString 함수로 변환하여 사용
	fmt.Println(p.age)              // 20

	C.free(unsafe.Pointer(name)) // C.CString으로 만든 문자열은 반드시 해제
	C.free(unsafe.Pointer(p))    // C 언어의 malloc 함수로 할당한 메모리는 반드시 해제
}
Exemplo n.º 3
0
func create(path string, flags int) (*DB, error) {
	pstr := C.CString(path)
	defer C.free(unsafe.Pointer(pstr))

	db, err := C.create(pstr, C.int(flags))

	if db == nil {
		return nil, err
	}

	ret := &DB{db, sync.Mutex{}}
	runtime.SetFinalizer(ret, destroy)
	return ret, nil
}
Exemplo n.º 4
0
func main() {
	var p *C.PERSON

	name := C.CString("kinow")
	age := C.int(33)

	p = C.create(name, age)

	C.show_person(p)

	fmt.Println("reflect PERSON: ", reflect.TypeOf(p))
	fmt.Println("reflect char* of PERSON: ", reflect.TypeOf(p.name))
	fmt.Println("reflect int of PERSON: ", reflect.TypeOf(p.age))
	fmt.Println(C.GoString(p.name))
	fmt.Println(p.age)

	C.free(unsafe.Pointer(name))
	C.free(unsafe.Pointer(p))

}
Exemplo n.º 5
0
func (Cv *Canvas) Create() {
	//I.Lock()
	Cv.Cv = C.create()
	C.clear(Cv.Cv)
	//I.Unlock()
}
Exemplo n.º 6
0
func TestCharStarStarSlice() {
	m := C.create()
	names := CharStarStarSlice(m.names, 2)
	fmt.Println("age:", m.age)
	fmt.Println("names:", names)
}