🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #903

About the mutex...

#903
From: Robert Huang
Date: Mon, 07 Jan 2008 01:18
42 lines
2101 bytes
Hi, all.
I have a question about the mutex.
I want to execute program-A by B, so I place the code in program-B like 
this:


//---------------------------------------------------------------------------
void __fastcall TBForm::ButtonExeClick(TObject *Sender)
{
    HANDLE TargetMutex = OpenMutex(SYNCHRONIZE, false, "Program-A");
    if(TargetMutex == NULL)
        WinExec(ExeATitle.c_str(), SW_SHOW);
    else
        ShowMessage("Already in running!!");
}
//---------------------------------------------------------------------------


And in program-A will be like this:


HANDLE Mutex;
//---------------------------------------------------------------------------
__fastcall TAForm::TAForm(TComponent* Owner)
        : TForm(Owner)
{
    Mutex = CreateMutex(NULL, false, "Program-A");
}
//---------------------------------------------------------------------------
void __fastcall TAForm::FormClose(TObject *Sender, TCloseAction &Action)
{
    ReleaseMutex(Mutex);
    Action = caFree;
}
//---------------------------------------------------------------------------


When A is running, the message "Already in running!!" will appear.
But when A is terminated, the message will still appear.
How do I fix the problem?

Thx:) 
Technical Details
Message-ID: <47817e00@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,34037fef0fe917a3,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Robert Huang" <remmurds.bbs@ptt.cc>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: About the mutex...
Date: Mon, 7 Jan 2008 09:18:52 +0800
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 140.130.34.204
Message-ID: <47817e00@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1199668736 140.130.34.204 (6 Jan 2008 17:18:56 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail