Hi all,

After searching information about how one can create only one instance of a program I write the following code:
*****************************
#include "stdafx.h"
#include <errno.h>
#include <Windows.h>

int main(int argc, char* argv[])
{
printf("Hello World!\n");

HANDLE hMutex = CreateMutex (0,FALSE,"HelloWorld");
WaitForSingleObject(hMutex, INFINITE);

long error = GetLastError();

if(error == ERROR_ALREADY_EXISTS)
{
::MessageBox(NULL, "Already Exists", __FILE__, MB_OK);
ExitProcess(0);
}

ReleaseMutex(hMutex);
CloseHandle(hMutex);


return 0;
}

****************************

But I don't get one instance of my HelloWorld application. Through Task manager I can see that there exits more than one instance of my program.
When I debug and find the variable
hMutex holds value "0x00000098" i.e error ERROR_TOO_MANY_MUXWAITERS

and method GetLastError() always return 0.

I never gets in "if statement".
What is going wrong and what I need to change?
Better if you can send me a small code solving my problem.

thanks in advance

regards
/rsasalm