单例控制
来源:互联网 发布:网店美工招聘 编辑:程序博客网 时间:2024/06/06 09:07
#ifndef LimitSingleInstance_H#define LimitSingleInstance_H#include <windows.h> //This code is from Q243953 in case you lose the article and wonder//where this code came from.class CLimitSingleInstance{protected: DWORD m_dwLastError; HANDLE m_hMutex;public: CLimitSingleInstance(TCHAR *strMutexName) { //Make sure that you use a name that is unique for this application otherwise //two apps may think they are the same if they are using same name for //3rd parm to CreateMutex m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early m_dwLastError = GetLastError(); //save for use later... } ~CLimitSingleInstance() { if (m_hMutex) //Do not forget to close handles. { CloseHandle(m_hMutex); //Do as late as possible. m_hMutex = NULL; //Good habit to be in. } } BOOL IsAnotherInstanceRunning() { return (ERROR_ALREADY_EXISTS == m_dwLastError); }};#endif
1.mutex用于单例,添加"Global\"是否存在的应用程序在一台计算机上只有一个实例将保证。这可应用于终端服务正在运行或不。
参照:http://support.microsoft.com/kb/243953/zh-cn
- 单例控制
- 单例模式实现mdi窗体控制
- c++中的单例模式对象的释放控制
- 通过ExecutorService实现单例的同步访问控制
- 经典的单例模式c3p0来控制数据库连接池
- C++单例模式对象的控制释放分析
- C++单例模式如何进行释放控制
- 控制CheckBox实现单选
- 控制血糖的餐单
- UITableViewCell 中的单选控制
- C# 单实例运行控制
- jQuery控制 checkbox单选
- js控制checkbox单选
- if单选控制结构
- 什么是单例模式?C++中单例模式对象的释放控制分析
- 28.VC(custom)-控制一个程序只能有一个进程(单例随手代码)
- C++设计模式 --单例模式(简单的实现和对象释放的控制)
- 编码素养问题收集1:基于名称映射的单例模式的并发控制
- 第一章 WCF简介
- 使用SSH框架实现用户登录验证
- 解决scrollview与listview冲突问题
- Apache 1.3 动态共享目标(DSO) 支持
- 私有云的反对者们注意啦!
- 单例控制
- C#如何从文本文件读取信息并使用ArrayList类向用户显示该信息
- 调用WB.ExecWB控件的方法
- Winxp成功编译wireshark-1.4.0的详细步骤
- ArcGIS API for Silverlight开发入门(0):为什么要用Silverlight API?
- 最简单的Ogre系列之五——AABB场景查询
- Struts2+Spring+Hibernate搭建全解!
- 模态对话框与非模态对话的几种销毁方法与区别
- get()与load()的区别