Article View: borland.public.cppbuilder.nativeapi
Article #4373Re: Mutex troubles?
From: Nate Lockwood
Date: Fri, 24 Feb 2006 21:03
Date: Fri, 24 Feb 2006 21:03
24 lines
1733 bytes
1733 bytes
Bruce Salzman wrote:
> You *should* get the handle to the existing mutex. You have to call
> GetLastError() after CreateMutex() to see if it returns
> ERROR_ALREADY_EXISTS.
Thanks, I got that thought after I posted and changed my code to that
below. The first instance is detected but the message doesn't get through.
Nate
HANDLE CheckForInstance(const UINT WM_MYMSG)
{
SetLastError(0) ;
char * m_Name = "USDA.FS.FireScience.GooleEarthTool";
HANDLE m_Handle = CreateMutex(NULL, false, m_Name);
if(m_Handle != NULL)
if(GetLastError() != ERROR_ALREADY_EXISTS)
return m_Handle; // this is the first instance
PostMessage(HWND_BROADCAST, WM_MYMSG, NULL, NULL);
return NULL; // NULL handle
}
Technical Details
Message-ID:
<43ff748a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43ff726e$1@newsgroups.borland.com> <43ff7389$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7b6bdf1fac3d7d96,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 24 Feb 2006 13:03:09 -0800 From: Nate Lockwood <RNLockwoodREMOVE@attglobal.net> User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Mutex troubles? References: <43ff726e$1@newsgroups.borland.com> <43ff7389$1@newsgroups.borland.com> In-Reply-To: <43ff7389$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.234.59.217 Message-ID: <43ff748a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1140814986 69.234.59.217 (24 Feb 2006 13:03:06 -0700) Lines: 25 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail