在客服端//InitInstance函数里添加一段防止多个客户端运行的代码如何第一次就返回ERROR_ALREADY.
在客服端//InitInstance函数里添加一段防止多个客户端运行的代码怎么第一次就返回ERROR_ALREADY.....?
与服务器的CreateMutex创建的名字是不相同的呀
------解决方案--------------------
再换个名字试试。_T("client2")
与服务器的CreateMutex创建的名字是不相同的呀
- C/C++ code
bool bFound = false; m_hMutexOneInstantance=CreateMutex(NULL,TRUE,_T("PreventSecondInstance2")); if(GetLastError()==ERROR_ALREADY_EXISTS) bFound=TRUE; if(m_hMutexOneInstantance) ReleaseMutex(m_hMutexOneInstantance); if (bFound==TRUE) { ::AfxMessageBox("已经有一个程序在运行"); return false; }
------解决方案--------------------
再换个名字试试。_T("client2")