Example #1
0
void CSFMClient::Open(DWORD dwAccess, const TCHAR *szMapName)
{
	if (m_iOpenFlag)
		_Destory();

	if (szMapName)
		m_pMapName = _wcsdup(szMapName);
	else m_pMapName = _wcsdup(DEFAULT_MAPNAME);

	m_hFileMap = OpenFileMapping(
		dwAccess,
		TRUE,
		m_pMapName
		);

	if (m_hFileMap)
	{
		m_lpFileMapBuffer = MapViewOfFile(
			m_hFileMap,
			dwAccess,
			0,
			0,
			0
			);
	}

	m_iOpenFlag = 1;
}
Example #2
0
	void _Destory(GeneralListNode* head)
	{
		GeneralListNode* cur = head;
		while (cur)
		{
			GeneralListNode* del = cur;
			cur = cur->_next;
			if (del->_type == SUB)
			{
				_Destory(del->_subLink);
			}
			else
			{
				delete del;
			}
		}
	}
Example #3
0
void CSFMServer::Create(const TCHAR *szFileName, const TCHAR *szMapName, DWORD dwSize)
{
	if (m_iCreateFlag)
		_Destory();

	if (szFileName)
		m_pFileName = _wcsdup(szFileName);
	//else m_pFileName = NULL;

	if (szMapName)
		m_pMapName = _wcsdup(szMapName);
	else m_pMapName = _wcsdup(DEFAULT_MAPNAME);

	if (dwSize > 0)
		m_dwSize = dwSize;
	else m_dwSize = DEFAULT_MAPSIZE;

	if (m_pFileName)
	{
		// file
		m_hFile = CreateFile(
			m_pFileName,
			GENERIC_READ|GENERIC_WRITE,
			FILE_SHARE_READ|FILE_SHARE_WRITE,
			NULL,
			OPEN_ALWAYS,//OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL
			);
	}
	else
	{
		// system
		m_hFile = (HANDLE)0xFFFFFFFF;
	}

	if (m_hFile)
	{
		m_hFileMap = CreateFileMapping(
			m_hFile,
			NULL,
			PAGE_READWRITE,
			0,
			m_dwSize,
			m_pMapName
			);

		//使只有一个CSFMServer对象能操作内存对象
		//if (m_hFileMap != NULL && ERROR_ALREADY_EXISTS == GetLastError())
		//{
		//	CloseHandle(m_hFileMap);
		//	m_hFileMap = NULL;
		//}
	}

	if (m_hFileMap)
	{
		m_lpFileMapBuffer = MapViewOfFile(
			m_hFileMap,
			FILE_MAP_ALL_ACCESS,//FILE_MAP_WRITE|FILE_MAP_READ,
			0,
			0,
			m_dwSize
			);
	}

	m_iCreateFlag = 1;
}
Example #4
0
CSFMServer::~CSFMServer()
{
	_Destory();
}
Example #5
0
CSFMClient::~CSFMClient()
{
	_Destory();
}
Example #6
0
	~GeneralList()
	{
		_Destory(_head);
	}