您的位置:首页 > 其它

调用CreateMutex创建一个有名的互斥器对象

2007-07-27 15:51 387 查看
void NameMutexExample (void) {

HANDLE hMutex;

TCHAR szMsg[100];

hMutex = CreateMutex (

NULL, //No security descriptor

FALSE, //Mutex object not owned

TEXT("NameOfMutexObject")); //Object name

if (NULL == hMutex) {

//Your code to deal with the error goes here.

//Here is one example of what might be done.

wsprintf (szMsg, TEXT("CreateMutex error: %d."), GetLastError ());

MessageBox (NULL, szMsg, TEXT("Error"), MB_OK);

else {

//Not an error -- deal with success

if ( ERROR_ALREDAY_EXISTS == GetLastError ())

MessageBox (NULL, TEXT("CreateMutex opened existing mutex."),

TEXT("Results"),MB_OK);

else

MessageBox (NULL, TEXT("CreateMutex created new mutex."),

TEXT("Result"), MB_OK);

}

} //End of NamedMutexExamle code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐