包括了一些VC编程实例

源代码在线查看: singleinstance.cpp

软件大小: 5330 K
上传用户: enterjqk
关键词: 编程实例
下载地址: 免注册下载 普通下载 VIP

相关代码

				#include "stdafx.h"
				#include "SingleInstance.h"
				
				//***********************************************
				CSingleInstance::CSingleInstance() : m_hMutex(NULL)
				{
				}
				
				//***********************************************
				CSingleInstance::~CSingleInstance()
				{
					if(m_hMutex != NULL)
					{
						ReleaseMutex(m_hMutex);
						CloseHandle(m_hMutex);
					}
				}
				
				//***********************************************
				bool CSingleInstance::Create(LPCTSTR szMutexName)
				{
					_ASSERTE(szMutexName);
					_ASSERTE(lstrlen(szMutexName));
				
					bool bSuccess = false;
				
					try
					{
						// First get the handle to the mutex
						m_hMutex = CreateMutex(NULL, FALSE, szMutexName);
						if(m_hMutex != NULL)
						{
							// Test the state of the mutex
							// If the state is signaled, we successfully opened the mutex
							if(WaitForSingleObject(m_hMutex, 0) == WAIT_OBJECT_0)
								bSuccess = true;
						}
					}
					catch(...) {}
				
					return bSuccess;
				}
							

相关资源