Article View: borland.public.cppbuilder.nativeapi
Article #9991Re: Implementation of run once
From: Daniele Borini
Date: Fri, 28 May 2004 09:41
Date: Fri, 28 May 2004 09:41
45 lines
2306 bytes
2306 bytes
That's very good, simple but very effective
10X a lot!!
JD ha scritto:
> "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:
<40b70945@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!news.octanews.net!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40b5cc3f@newsgroups.borland.com> <2hmrmlFes454U1@uni-berlin.de> <40b640b9$1@newsgroups.borland.com> <40b701d7$2@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 Date: Fri, 28 May 2004 11:41:19 +0200 From: Daniele Borini <borini@infinito.it> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.6) Gecko/20040113 X-Accept-Language: it, en, en-us MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Implementation of run once References: <40b5cc3f@newsgroups.borland.com> <2hmrmlFes454U1@uni-berlin.de> <40b640b9$1@newsgroups.borland.com> <40b701d7$2@newsgroups.borland.com> In-Reply-To: <40b701d7$2@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 62.94.68.184 Message-ID: <40b70945@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1085737285 62.94.68.184 (28 May 2004 02:41:25 -0700) Lines: 45 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!news.octanews.net!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail