🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Mutex not working

#7742
From: Jarkko Halme
Date: Thu, 23 Dec 2004 21:03
39 lines
1745 bytes
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: <41cb32b8$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-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5146b811ec878b88,start
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: Mutex not working
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 81.197.23.214     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41cb32b8$1@newsgroups.borland.com>
Date: 23 Dec 2004 13:03:52 -0800
X-Trace: newsgroups.borland.com 1103835832 207.105.83.66 (23 Dec 2004 13:03:52 -0800)
Lines: 39
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