🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Mutexes

#8891
From: Remy Lebeau (TeamB)
Date: Fri, 27 Aug 2004 19:52
45 lines
1968 bytes
"JoeBlack" <no.one@no.where> wrote in message
news:412f0c57@newsgroups.borland.com...

>         // the mutex does not work, it always starts the app

You aren't checking to see why OpenMutex() may return NULL, and you aren't
checking CreateMutex() for any errors at all.

Use this code instead:

    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
        HANDLE mutex = CreateMutex(NULL, TRUE, "Millenium.mutex");
        if( mutex == NULL )
        {
            MessageBox(NULL, ("Could not create the mutex: " +
SysErrorMessage(GetLastError())).c_str(), "Error", MB_OK);
            return 0;
        }

        if( GetLastError() == ERROR_ALREADY_EXISTS )
        {
            MessageBox(0, "This application is already running.\n"
                "You may only run one instance at any one time", "Error",
MB_OK);
        }
        else
        {
            try
            {
                //...
            }
            catch (Exception &exception)
            {
                //...
            }
        }

        CloseHandle(mutex);
        return 0;
    }


Gambit
Technical Details
Message-ID: <412f9097$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <412f0c57@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,c6c07f2e33548814
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: <412f0c57@newsgroups.borland.com>
Subject: Re: Mutexes
Date: Fri, 27 Aug 2004 12:52:10 -0700
Lines: 47
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: <412f9097$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1093636247 68.69.17.41 (27 Aug 2004 12:50:47 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail