65.9K
CodeProject is changing. Read more.
Home

Single Instance Checker

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.45/5 (10 votes)

Apr 18, 2002

viewsIcon

96929

downloadIcon

1194

Only 1 instance of your application can run in the same time

Introduction

If you want your application have just only instance is run in the same time, you only download and use it.

Step 1: Add file "LimitSingleInstance.h" to your project. This file is written by Microsoft. :-)

Step 2: Run UUIDGEN.EXE to get ID. This tool is written by Micorosft :-)

Step 3: Declare a variable

CLimitSingleInstance g_SingleInstanceObj(TEXT("{ID get from UUIDGEN}"));

for ex: CLimitSingleInstance g_SingleInstanceObj(TEXT("{addb6c1d-d98d-40f4-8041-0eb6b8bc884c}"));

Step 4: InitInstance()

Only add this line to check instance and make sure only 1 instance can run.

if (g_SingleInstanceObj.IsAnotherInstanceRunning()) return FALSE;

VERY and VERY SIMPLE.

I get this information and "LimitSingleInstance.h" from KnowledgeBase of Mirosoft site.