Hi,
I need to write an application that will never run in more than one instance.
Printable View
Hi,
I need to write an application that will never run in more than one instance.
Follow the link below and you'll find how to use shared instances.
http://www.codeguru.com/win32/previnst.shtml
If you add also a shared static member of type HWND in which to keep the handler of the main window of the one and only instance, or even the HINSTANCE, you have everything you need.
Hi ....
Just check for a Named Mutex object, and create one if not exist (ie. first instance).
Hope this will help you
bye
Regards...
Rajan K
#pragma data_seg("Shared")
LONG g_lUsageCount = -1;
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
BOOL fFirstInstance=(InterlockedIncrement(&g_lUsageCount) == 0);
if (fFirstInstance)
{
}
InterlockedDecrement(&g_lUsageCount);
return 1;
}