I'm trying to make an application that I do not want to have more than one instance.

How do I check for a previous instance then terminate?

Thanks ahead!
Posted on 2001-10-30 15:06:54 by JamesE
This is one way:

; FindWindow function retrieves the handle of the top-level window whose
; class name and window name match the specified strings, only one instance
push OFFSET WindowName ;lpWindowName, address of window name
push OFFSET Class ;lpClassName, address of class name
call FindWindowA ;- API Function -
cmp eax,0h
je RunPrg ;OK, no previous instance running
; API "MessageBoxA" creates a message box
push 10h ;uType,style,0=MB_OK Button,10h=MB_ICONSTOP
push OFFSET MB1_Title ;lpCaption,pointer to title text
push OFFSET MB1_Text ;lpText,pointer to text message box
push eax ;handle of owner window
call MessageBoxA ;- API Function -
jmp ExitPrg

Posted on 2001-10-31 02:39:26 by Test Department
You could try doing a search on the board, this issue has been up
"a couple" of times ;). But I'll present a method (that has been presented
before) nevertheless. The mutex method. It works pretty well. The
only problem is if your main app crashes without releasing the mutex,
I dunno if windows will free it for you...

mutexString db "lalala my little mutex", 0
hndMutex dd 0

invoke OpenMutex, MUTEX_ALL_ACCESS, FALSE, offset mutexString
cmp eax, 0
jne blah_app_already_running

invoke CreateMutex, NULL, TRUE, offset mutexString
mov [hndMutex], eax
Posted on 2001-10-31 04:36:18 by f0dder