🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Mutex not working

#7746
From: Remy Lebeau (TeamB)
Date: Thu, 23 Dec 2004 21:41
39 lines
2178 bytes
"Jarkko Halme" <jjhalme@kotiposti.net> wrote in message
news:41cb32b8$1@newsgroups.borland.com...

> 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:

Try this code instead:

    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
        const char mutexname[]="program";
        HANDLE mutex = CreateMutex(NULL, TRUE, mutexname);
        if( mutex )
        {
            if( GetLastError() != ERROR_ALREADY_EXISTS )
            {
                try
                {
                    Application->Initialize();
                    Application->Title = "program";
                    Application->CreateForm(__classid(TForm1), &Form1);
                    Application->Run();
                }
                catch (Exception &exception)
                {
                    Application->ShowException(&exception);
                }
            }
            else
                ShowMessage("Program is already running");

            CloseHandle(mutex);
        }
        return 0;
    }


Gambit
Technical Details
Message-ID: <41cb3b46$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41cb32b8$1@newsgroups.borland.com>
Subject: Re: Mutex not working
Date: Thu, 23 Dec 2004 13:41:27 -0800
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41cb3b46$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1103838022 68.69.17.41 (23 Dec 2004 13:40:22 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail