forked from kirides/go-winclipboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnative_windows.go
65 lines (56 loc) · 1.43 KB
/
native_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package clipboard
import (
"fmt"
"syscall"
"unsafe"
"github.com/kirides/go-winclipboard/internal/winsys"
"golang.org/x/sys/windows"
)
// Contains Win32 API wrappers and structs
// SECTION : CLIPBOARD
func dragQueryFileSlice(hDrop syscall.Handle, iFile uint, buf []uint16) (uint, error) {
var b *uint16
if len(buf) > 0 {
b = &buf[0]
}
i32, err := winsys.DragQueryFile(hDrop, uint32(iFile), b, uint32(len(buf)))
return uint(i32), err
}
func setClipboardDataSlice(id uint32, value []byte) error {
hHeap, err := winsys.GetProcessHeap()
if hHeap == 0 {
return err
}
hMem, err := winsys.HeapAlloc(hHeap, 0, uintptr(len(value)))
if err != nil {
return err
}
copy((*[1 << 30]byte)(unsafe.Pointer(hMem))[:len(value):len(value)], value)
r, e1 := winsys.SetClipboardData(id, syscall.Handle(hMem))
if r != syscall.Handle(hMem) {
e2 := winsys.HeapFree(hHeap, 0, hMem)
if e2 != nil {
return fmt.Errorf("failed to free heap memory: %v. %w", e2, e1)
}
return e1
}
return nil
}
type _FILEGROUPDESCRIPTORW struct {
nItems uint32
fgd *_FILEDESCRIPTORW
}
const _MAX_PATH = 260
type _FILEDESCRIPTORW struct {
dwFlags uint32
clsid windows.GUID
size [2]int32
pointl [2]int32
dwFileAttributes uint32
ftCreationTime windows.Filetime
ftLastAccessTime windows.Filetime
ftLastWriteTime windows.Filetime
nFileSizeHigh uint32
nFileSizeLow uint32
cFileName [_MAX_PATH]uint16
}