Aaron,
I appreciate the mutex code you posted to the list back in June. I've
discovered a fatal flaw in my implementation. Since I don't understand
mutexes, I am hoping you can help.
I'm shipping an app that is compiled in RB 4.53. (I have not got my running
under RB5 yet). I implemented the functions as described below.
When I attempt to launch a second copy of my app, the error dialog shows and
the second application appears to go away. But if I open the task manager
in Windows 2000 and look at the processes tab, that second launch creates a
second process that does not go away. Each time I launch it creates a new
(for my app a 16MB) process.
Does this happen in your apps? Any ideas how to kill the process?
Thanks,
Keith DeLong
> multiple instances under Windows (and getting Win32 command line)
> From: "Aaron Ballman" <aaron at realsoftware dot com>
> Date: Thu, 19 Jun 2003 15:27:16 -0500
>
> Question Two: not allowing multiple launches
>
> I've always used mutexes for this, since that it what their main purpose is.
>
> There are two methods I make in my App class, and one property.
>
> mutex as Integer is a protected property of the app class and
> TestMutex() and CloseMutex() are both Subs in the app class.
>
> Sub TestMutex()
> #if TargetWin32
> Declare Function CreateMutexA Lib "Kernel32" (ignore as Integer,
> initialOwner as Boolean, name as CString) as Integer
> Declare Function GetLastError Lib "Kernel32" () as Integer
>
> mutex = CreateMutexA(0, true, "MY APPLICATION MUTEX")
>
> if GetLastError = 183 then // ERROR_ALREADY_EXISTS
> MsgBox "You cannot have more than one copy running!"
> Quit
> End
>
> #endif
> End Sub
>
> Sub CloseMutex()
> #if TargetWin32
> Declare Function CloseHandle Lib "Kernel32" (handle as Integer) as Boolean
>
> call CloseHandle(mutex)
> #endif
> End Sub
>
> Then in App.Open I put a call to TestMutex and in App.Close I put a
> call to CloseMutex.
>
> Works like a charm. If you want an example project, I can hand it over to
> you.
---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
.
|