2014年3月21日13:50:47
1、使用VS2008创建一个预编译头的控制台项目。
2、源文件内容:
#include "stdafx.h"
#include <windows.h>
#include<iostream>
using namespace std;
int main( void )
{
HANDLE hMutex=CreateMutex(NULL,TRUE,L"CenterTransMutex");
if(NULL == hMutex)
{
printf("CreateMutex error: %d\n", GetLastError());
}
else if(GetLastError() == ERROR_ALREADY_EXISTS)
{
//释放资源
CloseHandle(hMutex);//或结束进程
printf("已经存在\n");
}else
{
printf("一切正常\n");
}
char ch;
cin>>ch;
return 0;
}