|
-
December 9th, 2003, 11:32 AM
#1
single app instance - debug mode only?
In the InitInstance method of my App class, I have this code to check for a single instance of my application. I know there might be better ways of doing this, but this suffices for me, or does it?
//create a mutex to keep this app a single instance app
//don't worry about return HANDLE because it's auto reclaimed by OS
//on process termination.
CString mutexError = "";
if (!CreateMutex(NULL, TRUE, "MYAPPTITLE INSTANTIATED"))
{
mutexError = "Unexpected ERROR: MyAppTitle - CreateMutex FAILED !";
AfxMessageBox(mutexError, MB_ICONEXCLAMATION);
return FALSE;
}//end if
if (ERROR_ALREADY_EXISTS == ::GetLastError())
{
CWnd *pWndPrev, *pWndChild;
CString sWinName("MyAppTitle");
if (pWndPrev = CWnd::FindWindow(NULL,sWinName))
{
//if so, does it have any popups?
pWndChild = pWndPrev->GetLastActivePopup();
//if iconic, restore the main window
if (pWndPrev->IsIconic())
{
pWndPrev->ShowWindow(SW_RESTORE);
}//end if
//bring the main window or its popup to the foreground
pWndChild->SetForegroundWindow();
}//end if
return FALSE;
}//end if
Anyway, this code seems to work, but only in Debug mode. When I run debug mode of my application, and then run another instance (double-click the debug executable and/or the C++ developer environment debug), I see another instance startup in Windows Taskmanager, then it goes away.
But in release mode, this code doesn't seem to work? It just creates an instance every time I run in release mode. Any ideas as to why it wouldn't work in release mode, but will work in debug mode?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|