我是Common Lisp的新手,並對它做了一些實驗。 我努力獲得一些訪問到Windows剪貼板,然後我發現這個參考:CFFI和win32剪貼板訪問
https://groups.google.com/forum/#!topic/comp.lang.lisp/hyNqn2QhUY0
這是完美的,除了它是爲CLISP FFI量身定做的,我希望它與CFFI工作。 然後我試圖將代碼轉換,部分成功,但有一個與常規 (獲得夾弦),與Clozure CL 1.10在WinXP測試的問題(!):
測試文字:足夠的空間Suit- Will Travel
? (獲得夾弦)
Error: The value "Have Space Suit-Will Travel" is not of the expected type (UNSIGNED-BYTE 32). While executing: GLOBAL-LOCK-STRING, in process listener(1). Type :POP to abort, :R for a list of available restarts. Type :? for other options.
我覺得我沒有拿到樣東西上CFFI(雖然我讀過的手冊),或在CLISP原來的處方。有人有任何提示? 下面的命令序列工作,但恐怕不是安全:
(open-clip 0)
(get-clip 1)
(close-clip 0)
(開夾0) (GET-夾1) (接近夾0)
這裏驗證碼:
(ql:quickload :cffi)
(cffi:load-foreign-library "user32.dll")
(cffi:load-foreign-library "kernel32.dll")
(cffi:load-foreign-library "msvcrt.dll")
(cffi:defcfun ("GetClipboardData" get-clip) :string
(uformat :unsigned-int))
(cffi:defcfun ("OpenClipboard" open-clip) :int
(hOwner :unsigned-int))
(cffi:defcfun ("CloseClipboard" close-clip) :int
(hOwner :unsigned-int))
(cffi:defcfun ("EmptyClipboard" empty-clip) :int)
(cffi:defcfun ("SetClipboardData" set-clip) :int
(data :unsigned-int)
(format :unsigned-int))
(cffi:defcfun ("GlobalAlloc" global-alloc) :int
(flags :unsigned-int)
(numbytes :unsigned-int))
(cffi:defcfun ("GlobalLock" global-lock) :unsigned-int
(typ :unsigned-int))
(cffi:defcfun ("GlobalLock" global-lock-string) :string
(typ :unsigned-int))
(cffi:defcfun ("GlobalUnlock" global-unlock) :int
(typ :unsigned-int))
(cffi:defcfun ("memcpy" memcpy) :int
(dest :unsigned-int)
(src :string)
(coun :unsigned-int))
(defun get-clip-string()
(open-clip 0)
(let* ((h (get-clip 1)) (s (global-lock-string h)))
(global-unlock h) (close-clip 0) s))
(defun set-clip-string (s)
(let* ((slen (+ 1 (length s)))(newh (global-alloc 8194 slen))
(newp (global-lock newh)))
(memcpy newp s (+ 1 slen)) (global-unlock newh) (open-clip 0)
(set-clip 1 newh) (close-clip 0)))
沒有很大的啓示,我會建議搞清楚如何':string'和'(無符號字節32)'正相關,且可能更改到別的東西;例如,也許Windows API正在返回'(無符號字節16)'或'(無符號字節8)'字符。 – BRFennPocock