Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Handling second instance works in IDE but not when compiled

9 views
Skip to first unread message

-mhd

unread,
Oct 13, 2012, 9:30:34 PM10/13/12
to
Normally when I detect a running instance of my prog by using a mutex value, I
just kill the second instance but now I also want to bring the first instance up
to normal state if its minimized.


MutexValue = CreateMutex(ByVal 0&, 1, "MyProgMutex")
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
CloseHandle MutexValue
'Search for Window / Get its Handle
lhwnd = FindWindow(vbNullString, "My Prog Caption")
'If Another Window Found
If lhwnd <> 0 Then
'Activate and Show Window
lRtrn = ShowWindow(lhwnd, SW_SHOWRESTORE)
End If
'this instance exits sub main and dies
Exit Sub
End If

Works just great in the IDE as the first instance pops up from minimized state
and the second one dies.

When compiled the second one dies immediately upon launching as intended but the
first one doesn't pop up.

Any ideas?

-mike

Deanna Earley

unread,
Oct 15, 2012, 5:09:31 AM10/15/12
to
Have you checked whether you actually get a valid window handle?
The code above doesn't and exists only on the mutex check, regardless of
whether it found a window or not.

--
Deanna Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

BeeJ

unread,
Oct 17, 2012, 3:24:52 PM10/17/12
to
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
0 new messages