Article View: borland.public.cppbuilder.nativeapi
Article #7744Re: Mutex not working
From: Jarkko Halme
Date: Thu, 23 Dec 2004 21:06
Date: Thu, 23 Dec 2004 21:06
46 lines
2041 bytes
2041 bytes
"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;
>}
>--------------------------------------------------
I forgot to write that above does not prevent multiple instances of my program running and the question is why doesn't it work?
Thanks in advance
Jarkko
Technical Details
Message-ID:
<41cb335e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!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: <41cb335e$1@newsgroups.borland.com> Date: 23 Dec 2004 13:06:38 -0800 X-Trace: newsgroups.borland.com 1103835998 207.105.83.66 (23 Dec 2004 13:06:38 -0800) Lines: 46 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail