Determine if only one instance is running: Difference between revisions
Determine if only one instance is running (view source)
Revision as of 16:20, 19 June 2017
, 6 years ago→{{header|TXR}}: New section.
(Added Kotlin) |
(→{{header|TXR}}: New section.) |
||
Line 1,038:
exit 1
}</lang>
=={{header|TXR}}==
==== Microsoft Windows ====
<lang txrlisp>;;; Define some typedefs for clear correspondence with Win32
(typedef HANDLE cptr)
(typedef LPSECURITY_ATTRIBUTES cptr)
(typedef WINERR (enum WINERR ERROR_SUCCESS
(ERROR_ALREADY_EXISTS 183)))
(typedef BOOL (enum BOOL FALSE TRUE))
(typedef LPCWSTR wstr)
;;; More familiar spelling for null pointer.
(defvarl NULL cptr-null)
;;; Define access to foreign functions.
(with-dyn-lib "kernel32.dll"
(deffi CreateMutex "CreateMutexW" HANDLE (LPSECURITY_ATTRIBUTES BOOL LPCWSTR))
(deffi CloseHandle "CloseHandle" BOOL (HANDLE))
(deffi GetLastError "GetLastError" WINERR ()))
;;; Now, the single-instance program:
(defvar m (CreateMutex NULL 'TRUE "ApplicationName"))
(unless (eq (GetLastError) 'ERROR_ALREADY_EXISTS)
;; mutual exclusion here
)
(CloseHandle m)
=={{header|UNIX Shell}}==
|