Reputation: 742
I wanted to add a listbox based on the sample A here below. The Common Lisp Cookbook - Using the Win32 API
I added a function, sendmessage which maps to its windows API counter part and call it from the wndproc. But it complained type conversion error like below.
CL-USER 1 > (create-toplevel-window "ppp")
Error: #<Pointer to type (:UNSIGNED :SHORT) = #x01E902D8> cannot be
converted to foreign type (:UNSIGNED-INTEGER-TYPE 32).
Here are the functions related to the error. Any idea to fix the issue? I tried to define sendmessage with lparam as (:unsigned :short) but no use.
(fli:define-foreign-function
(SendMessage "SendMessage" :dbcs)
((hwnd hwnd) (msg uint) (wparam ulong) (lparam (:unsigned :long)))
:result-type ulong :calling-convention :stdcall)
(fli:define-foreign-callable
(wndproc :result-type :long :calling-convention :stdcall)
((hwnd hwnd) (msg (:unsigned :long))
(wparam (:unsigned :long)) (lparam (:unsigned :long)))
(case msg
(#.WM_CREATE
(fli:with-foreign-string ;; class name pointer
(cn-p ec bc :external-format (external-format)) "LISTBOX"
(fli:with-foreign-string ;; window name pointer
(wn-p ec bc :external-format (external-format)) ""
(let ((lstbx (createwindowex hwnd cn-p wn-p
(logior ws_visible ws_child lbs_notify)
cw_usedefault cw_usedefault cw_usedefault cw_usedefault
0 0 200 100)))
(fli:with-foreign-string (msg ec bc :external-format (external-format)) "item1"
(sendmessage lstbx LB_ADDSTRING 0 msg ))))))
;;0 0 (GetModuleHandle-current 0) 0))))
;;(createwindowex "listbox4test" hwnd))
;;(#.WM_PAINT (wndproc-paint hwnd msg wparam lparam))
#+console (#.WM_DESTROY (PostQuitMessage 0) 0)
(t (DefWindowProc hwnd msg wparam lparam))))
Upvotes: 1
Views: 82
Reputation: 742
I changed the sendmessage function as below. And this time, it did not complain.
(fli:define-foreign-function
(SendMessage "SendMessage" :dbcs)
((hwnd hwnd) (msg uint) (wparam ulong) (lparam :pointer)) ;;;(lparam (:unsigned :long)))
:result-type ulong :calling-convention :stdcall)
Upvotes: 0