How to resolve the algorithm Determine if only one instance is running step by step in the TXR programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Determine if only one instance is running step by step in the TXR programming language
Table of Contents
Problem Statement
This task is to determine if there is only one instance of an application running. If the program discovers that an instance of it is already running, then it should display a message indicating that it is already running and exit.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Determine if only one instance is running step by step in the TXR programming language
Source code in the txr programming language
;;; 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)
You may also check:How to resolve the algorithm QR decomposition step by step in the D programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Ol programming language
You may also check:How to resolve the algorithm Möbius function step by step in the C++ programming language
You may also check:How to resolve the algorithm Mian-Chowla sequence step by step in the Java programming language
You may also check:How to resolve the algorithm Active object step by step in the Ada programming language