Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Stopping multiple app instances

This topic is 6447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Assuming Visual C++/Windows

// at the start of your program, put this once, in one file

// with the other global variables.

#pragma data_seg( "SHARESEC" )
volatile bool g_bAlreadyLoaded = false;
#pragma comment( linker, "/SECTION:SHARESEC,RWS" )
#pragma data_seg()

int WINAPI WinMain( HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode )
// if application already running, show an error

// and exit with -1 return code

if (g_bAlreadyLoaded)
MyError( "Application is already running!!" );
return -1;
g_bAlreadyLoaded = true;

... do rest of application here ...

The #pragmas tell the compiler/linker that the variables in the block of memory between them should be shared between all instances of the exe (usually each time its loaded, the globals get re-initialised for each instance).

The volatile is to prevent the compiler from trying to optimise the variable or turn it into a constant or anything else which may stop it working in the shared section.

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
In VB that''s simple:

if app.previnstance=true then
msgbox app.name & " is already running"
end if

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!