package main
import (
"fmt"
"syscall"
"win_api/cursor"
)
func main() {
mod := syscall.NewLazyDLL("user32.dll")
pt, err := cursor.GetCursorPosition(mod)
if err != nil {
panic(err)
}
fmt.Println(pt)
}
package cursor
import (
"syscall"
"unsafe"
)
type Point struct {
X, Y int32
}
func GetCursorPosition(mod *syscall.LazyDLL) (*Point, error) {
proc := mod.NewProc("GetCursorPos")
point := &Point{}
ret, _, err := proc.Call(uintptr(unsafe.Pointer(point)))
if ret == 0 {
return nil, err
}
return point, nil
}
설명
- syscall.NewLazyDLL → user32.dll 로드
- NewProc → GetCursorPos 함수 찾기
- unsafe.Pointer → Go 구조체 포인터를 C 포인터로 변환
- proc.Call → API 호출 (리턴값 확인)
'Go > window_api' 카테고리의 다른 글
[Go] Windows API - 창 핸들 찾기 (0) | 2025.03.05 |
---|---|
[Go] Windows API - 마우스, 화면, 시스템 상태까지 확인 (0) | 2025.03.05 |
[Go] Windows API - 시스템 해상도 가져오기 (0) | 2025.03.05 |
[Go] Windows API - 메시지 박스 (0) | 2025.03.05 |
[Go] Windows API 기본 개념, DLL, 시스템 호출, 메시지 루프,Handle (0) | 2025.03.05 |