Article View: borland.public.cppbuilder.nativeapi
Article #7748Re: Mutex not working
From: Jarkko Halme
Date: Sat, 25 Dec 2004 10:07
Date: Sat, 25 Dec 2004 10:07
44 lines
1957 bytes
1957 bytes
Thanks guys and Merry Christmas
"Jarkko Halme" <jjhalme@kotiposti.net> wrote:
>
>Hello There
>I am trying to prevent several instances of my program running. I am using C++ Builder v5 and OS is XP. My main looks like below:
>
>-----------------------------------------
>WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
>{
> HANDLE mutex;
>
> try
> {
> const char mutexname[]="program";
> mutex=OpenMutex(0,false,mutexname);
>
> //If mutex does not exist = program is not running
> if (mutex==NULL)
> {
> mutex=CreateMutex(NULL, true,mutexname);
> }
> //mutex exists = program is aleady running
> else
> {
> ShowMessage("Program is already running");
> return 0;
> }
>
> Application->Initialize();
> Application->Title = "program";
> Application->CreateForm(__classid(TForm1), &Form1);
> Application->Run();
> }
> catch (Exception &exception)
> {
> Application->ShowException(&exception);
> }
> ReleaseMutex(mutex);
> return 0;
>}
>--------------------------------------------------
Technical Details
Message-ID:
<41cd3bde$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41cb32b8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5146b811ec878b88 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Jarkko Halme" <jjhalme@kotiposti.net> Sender: "Jarkko Halme" <jjhalme@kotiposti.net> Reply-To: "Jarkko Halme" <jjhalme@kotiposti.net> Subject: Re: Mutex not working Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 81.197.23.214 References: <41cb32b8$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <41cd3bde$1@newsgroups.borland.com> Date: 25 Dec 2004 02:07:26 -0800 X-Trace: newsgroups.borland.com 1103969246 207.105.83.66 (25 Dec 2004 02:07:26 -0800) Lines: 45 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail