Click here to Skip to main content
15,894,410 members
Articles / Programming Languages / C++

A Wrapped Class of Share Memory

Rate me:
Please Sign up or sign in to vote.
3.68/5 (16 votes)
9 Jul 2007CPOL1 min read 206.7K   1.5K   26  
Share information betwwen processes using Memory-Mapped File
#pragma once
#include <string>
using std::string;
/**
* @author Bony.Chen
* @description A wrapped class managing file mapping object 
				for the specified file.It encapsulates some
				basic operations such as Create,Open,MapViewOfFile.
* @mail bonyren@163.com

*/
class MMF
{
public:
	MMF(const string& szMMName);
public:
	virtual ~MMF(void);
public:
	///Create memory mapping file
	bool CreateMapFile();
	///open memory mapping file that has been exist
	bool OpenMapFile();
	///close the handle of memory mapping file
	void CloseMapFile();
	///write data to the memory mapping file
	bool WriteData(const char* szData,int nLen);
	///read data from the memory mapping file
	bool ReadData(string& szData);
private:
	HANDLE m_hMapFile;//<the handle of memory-mapped file
	string m_szMMName;//<the name of memory-mapped file
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
Bony Chen, a senior software engineer, specializes in C++, COM, C#, ASP.net, ISAPI. He has nearly seven years of software development experience, and has successfully developed many influential software products, such as SPES, CSO, QQ (a famous IM tool in China).
And now he is focusing on P2P technology. He aims at being an expert in software development, software consulting, software components and computer science.
If you have any opinions or questions in software area, please contact bonyren@163.com.

Comments and Discussions