intelliproject logo

Location: Desktop development - C/C++    License: The Intelliproject Open License (IPOL)

Limit applications to one instance in Visual C++

Posted by Silviu Caragea

How to limit 32-bit applications to one instance in Visual C++

Skill: Intermediate

Posted: 05/10/2008

Views: 606

Rating: 5.00 /5

Popularity: 0.00

Sign Up to vote for this article

Introduction

Sometimes you need to limit your application to a single instance. The most common way is creating a named mutex using CreateMutex, and checking to see if that mutex already existed or not.  If that mutex already exists, it means that another instance application reside in your computer memory so you can kill your current instance.

How to use this code

All you need to do is to create a global instance of the CSingleInstance class before the entry point function. If this is being used in a MFC application, create the instance before the InitInstance() function.

BOOL isAtnotherInstanceRunning() – return TRUE if another instance already exists and FALSE if not.

 

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Silviu Caragea

Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject.

He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy.

His programming experience includes:
- C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL)
- Open Source libraries :CURL & Boost
- HTML, CSS
- Java (SE,ME)
- JavaScript, Ajax, Google Web Toolkit (GWT)
- Php, MySQL
-Oracle, PL SQL
- C# .NET
-Objective C, IPhone SDK, Cocoa

Location: Romania
Ocupation: Software Engineer
Home page: http://www.intelliproject.net

Sign up to post message on the article message board!