BOOL CRemoteSlaveApp::InitInstance()
{
/* 创建一个不被调用线程拥有的名为"RemoteSlave"的互斥对象
Creates or opens a named or unnamed mutex(互斥) object
HANDLE WINAPI CreateMutex(
__in_opt LPSECURITY_ATTRIBUTES lpMutexAttributes,
//A pointer to a SECURITY_ATTRIBUTES structure. If this parameter is
NULL, the handle cannot be inherited by child processes.
__in BOOL bInitialOwner,
//If this value is TRUE and the caller created the mutex, the calling
thread obtains initial(最初的,开始的) ownership of the mutex object. Otherwise,
the calling thread does not obtain ownership of the mutex.
__in_opt LPCTSTR lpName
//The name of the mutex object. The name is limited to MAX_PATH
characters. Name comparison is case sensitive.
);*/
m_hMutextSelf = CreateMutex(NULL,FALSE,"RemoteSlave");
/* 判断是否返回了同名互斥对象的地址*/
if ( ERROR_ALREADY_EXISTS==GetLastError() )
{
AfxMessageBox("不能创建第二个程序实例");
return FALSE; //App初始化失败,不能运行实例
}
}//使用这个函数可以使应用程序只能运行一个实例
CreateMutex()
最新推荐文章于 2022-11-28 00:43:38 发布