g_hEvent = CreateEvent(NULL, FALSE, FALSE, "instance");
if(NULL != g_hEvent)
{      
                // 如果先前有一个实例, 结束此实例
if(ERROR_ALREADY_EXISTS == GetLastError()) 
{
cout << "Only instance can run!" << endl;
CloseHandle(g_hEvent);         // 问题就在这里
return 0;
}
}
SetEvent(g_hEvent); // set event signaled上段代码中CloseHandle(g_hEvent);是否可以?照msdn所说:If the named event object existed before the function call, the function returns a handle to the existing object,也就是运行第二个实例的时候,g_hEvent的值就是先前存在的对象句柄(这两个实例的句柄有什么关系?是否是同一个?),那么这里调用CloseHandle(g_hEvent);是不是将先前的事件句柄给关闭了.
比如程序为1.exe,那么我先后两次运行1.exe,产生2个实例,第二个实例运行时,会运行CloseHandle(g_hEvent),这个是不是将第一次运行打开的g_hEvent给关闭了?还是两个实例都有各自的g_hEvent,互不相关?