Article View: borland.public.cppbuilder.nativeapi
Article #9990Re: Implementation of run once
From: JD
Date: Fri, 28 May 2004 09:09
Date: Fri, 28 May 2004 09:09
40 lines
1856 bytes
1856 bytes
"Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote:
>
>> ReleaseMutex(handle);
>
>You should be using CloseHandle() instead.
From: http://www.bcbdev.com/faqs/faq74.htm
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// Attempt to create a mutex. If the mutex already existed,
// GetLastError will return ERROR_ALREADY_EXISTS
HANDLE hInstanceMutex = ::CreateMutex(NULL,TRUE, "PROJECT1");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
if(hInstanceMutex)
CloseHandle(hInstanceMutex);
return 0;
}
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
ReleaseMutex(hInstanceMutex);
CloseHandle(hInstanceMutex);
return 0;
}
You can see that last few lines does both. Comments?
~ JD
Technical Details
Message-ID:
<40b701d7$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40b5cc3f@newsgroups.borland.com> <2hmrmlFes454U1@uni-berlin.de> <40b640b9$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,91ebf45a6fbd8e57 X-Google-Attributes: gid10cc67,public From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Implementation of run once Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.174.233.106 References: <40b5cc3f@newsgroups.borland.com> <2hmrmlFes454U1@uni-berlin.de> <40b640b9$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <40b701d7$2@newsgroups.borland.com> Date: 28 May 2004 02:09:43 -0700 X-Trace: newsgroups.borland.com 1085735383 207.105.83.66 (28 May 2004 02:09:43 -0700) Lines: 41 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail