Re: how to run only one instance of delivered app on Windows?
Hi Chris,
I dunno whether Lispworks does this out of the box, but the technique
I use (in C++, I admit) is to create a named Win32 event and see
whether I get an ERROR_ALREADY_EXISTS result. Here's some LWW code to
do it:
;;; Note: ERROR_ALREADY_EXISTS = 183 in winerror.h
(define-foreign-function (get-last-error "GetLastError")
()
:result-type (:unsigned :long)
:calling-convention :stdcall)
(define-foreign-function (create-event "CreateEventW")
((security-attributes (:pointer :void))
(manual-reset-p :boolean)
(initially-signalled-p :boolean)
(name (:pointer (:unsigned :short))))
:result-type (:pointer :void)
:calling-convention :stdcall)
(defun create-named-win32-event (name &key manual-reset-p initially-signalled-p)
(with-foreign-string (ptr elts bytes :external-format :unicode)
name
(declare (ignore elts bytes))
(let ((handle (create-event *null-pointer* manual-reset-p
initially-signalled-p ptr)))
(values handle (= (get-last-error) 183)))))
(define-foreign-function (close-handle "CloseHandle")
((handle (:pointer :void)))
:result-type :boolean
:calling-convention :stdcall)
CL-USER> (create-named-win32-event "test-event")
#<Pointer to type :VOID = #x000001EC>
NIL
CL-USER> (setq h1 *)
#<Pointer to type :VOID = #x000001EC>
CL-USER> (create-named-win32-event "test-event")
#<Pointer to type :VOID = #x000001FC>
T
CL-USER> (setq h2 *)
#<Pointer to type :VOID = #x000001FC>
CL-USER> (mapcar #'close-handle (list h1 h2))
(T T)
CL-USER>
Obviously this code could be wrapped up a bit more neatly, but you get
the idea. If your event didn't previously exist, you keep the handle
around until your process exits (when it will be cleaned up
automatically).
Hope this helps,
John :^P
On Thu, Aug 13, 2009 at 5:08 PM, Chris Perkins<cperkins@medialab.com> wrote:
>
> On Windows it is possible to have an application that can be launched over
> and over and create new instances for each launch. And it is also possible
> to have an application that has just a single instance, no new instances.
>
> Right now, my delivered Lispworks application creates a new instance
> whenever launched. Is it possible to have it only have one instance? If so,
> how? I looked through all the delivery keys but didn't see one for this.
>
> Thanks,
>
> Chris
--
John Pallister
john@synchromesh.com
john@johnp.net