// SetText sets the current text data of the clipboard. func (c *ClipboardService) SetText(s string) error { return c.withOpenClipboard(func() error { utf16, err := syscall.UTF16FromString(s) if err != nil { return err } hMem := win.GlobalAlloc(win.GMEM_MOVEABLE, uintptr(len(utf16)*2)) if hMem == 0 { return lastError("GlobalAlloc") } p := win.GlobalLock(hMem) if p == nil { return lastError("GlobalLock()") } win.MoveMemory(p, unsafe.Pointer(&utf16[0]), uintptr(len(utf16)*2)) win.GlobalUnlock(hMem) if 0 == win.SetClipboardData(win.CF_UNICODETEXT, win.HANDLE(hMem)) { // We need to free hMem. defer win.GlobalFree(hMem) return lastError("SetClipboardData") } // The system now owns the memory referred to by hMem. return nil }) }
func (bmp *Bitmap) Dispose() { if bmp.hBmp != 0 { win.DeleteObject(win.HGDIOBJ(bmp.hBmp)) win.GlobalUnlock(bmp.hPackedDIB) win.GlobalFree(bmp.hPackedDIB) bmp.hPackedDIB = 0 bmp.hBmp = 0 } }