Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / Win32

How to avoid multiple instances of your Windows application

Rate me:
Please Sign up or sign in to vote.
4.40/5 (5 votes)
27 Sep 2010CPOL 11.2K   1  
I tend to use boost::interprocess::named_mutex for the same thing. The equivalent code is something like:using boost::interprocess;const char *application_name = "Application Name";int main()try{ struct named_mutex_killer { ~named_mutex_killer() {...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
3 Feb 2011Menuki
This solution works in Windows environment under Visual Studio.I don't know if there is a Linux equivalent.I use a counter common for all processes.#pragma data_seg("counter") // counter common for all processesLONG gs_nCtApp = -1; #pragma data_seg()#pragma comment(linker,...
Please Sign up or sign in to vote.
27 Sep 2010bleedingfingers 3 alternatives  
I want to share a simple class I use for this purpose. The class operates on kernel objects.
Please Sign up or sign in to vote.
27 Jan 2011Malli_S
Solution II used to use following simple way to manage the single instance of the app.//Usually I append the UID to the application name to achieve the unique object name.TCHAR szAppName[] = _T("Application_Name_999e7ba3-e8fc-4c21-985b-ab11f39ce759");HANDLE hMutex =...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I've been programming since 1985 - starting with Fortran 77, then moving onto assembler, C and C++ in about 1991. I also know enough Java and Python to read code but you probably wouldn't want me writing it.

I've worked in a wide variety of application areas - defense, banking, games and security with the longest stints being in security. I also seem to end up programming devices far too often. This time I'm programming terahertz band body scanners.

Comments and Discussions