CSingleInstance v1.0
Welcome to CSingleInstance, a freeware MFC class to make your app into a single instance. Limiting your app to single instance is more tricky in Win32 with the removal of the hPrevInstance parameter from WinMain and the introduction of separate address spaces.
There are numerous examples already out there of making your app single instance, but some such as the one I found on www.codeguru.com require knowledge of undocumented or heavy duty MFC.
Other methods such as using FindWindow, FindWindowEx are not 100% bullet proof due to the preemptive Win32 environment.
This class internally uses a memory mapped file (MMF) into which the handle of the main window of your application is stuffed. When a second instance of your app is run, it detects that the memory mapped file exists, gets the window handle of the first instance from the MMF and reactivates it.
Features |
Usage |
History |
API Reference |
Contacting the Author |
V1.0 (29th July 1998)
The API consists of the the two public member functions of the class CSingleInstance
CSingleInstance::PreviousInstanceRunninging
BOOL CSingleInstance::PreviousInstanceRunning()
Return Value
TRUE if a previous instance of this application is running otherwise FALSE.
Remarks
In response to TRUE being sent back the program should call ActivatePreviousInstance and abort prematurely from the current instance of the app.
CSingleInstance::ActivatePreviousInstance
BOOL CSingleInstance::ActivatePreviousInstance()
Remarks
Activates the previous instance of the app as detected in a call to PreviousInstanceRunning.
PJ Naughter
Email: pjn@indigo.ie
Web: http://indigo.ie/~pjn
29th July 1998