Win32 服务进程和单实例实现

#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")

HANDLE hMutex = CreateMutexA(NULL, true, "XXX_0D0DDD11-5E3F-4287-BB74-7E3D2C7720EF");
 if (hMutex)
 {
  if (GetLastError() == ERROR_ALREADY_EXISTS)
  {
   //std::cerr << "Program already run...\n"
   //	<< "Press any key to exit..." << std::endl;
   //std::cin.get();
   return 1;
  }
 }
 else
 {
   return 1;
 }

posted on 2014-04-11 12:38  Yours风之恋  阅读(188)  评论(0编辑  收藏  举报