Click here to Skip to main content
15,895,799 members
Articles / Desktop Programming / MFC

Shared Memory with IPC with threads

Rate me:
Please Sign up or sign in to vote.
3.32/5 (18 votes)
4 Oct 2004CPOL2 min read 126.5K   4.2K   45  
Shared memory as used along with threads to communicate between processes.
// OneAtaTimeDlg.h : header file
//

#if !defined(AFX_ONEATATIMEDLG_H__6616245C_8DC3_45E4_B8BF_BA997155948F__INCLUDED_)
#define AFX_ONEATATIMEDLG_H__6616245C_8DC3_45E4_B8BF_BA997155948F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// COneAtaTimeDlg dialog
#define KILL_APP WM_USER+10
#define RECV_MESSAGE WM_USER+20
#define CHILD_START WM_USER+30

struct KSharedMemory
{
	DWORD processID;
	BOOL childAck;
	char data[1000];
	UINT dataSize;

};

UINT StartProbing(LPVOID lParam);


class COneAtaTimeDlg : public CDialog
{
// Construction
public:
	void OnChildStart();
	void OnRecvMessage();
	void OnKillApp();
	COneAtaTimeDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(COneAtaTimeDlg)
	enum { IDD = IDD_ONEATATIME_DIALOG };
	CListBox	m_recvlist;
	CString	m_status;
	CString	m_message;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COneAtaTimeDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(COneAtaTimeDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnButtonKill();
	afx_msg void OnButtonSend();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	KSharedMemory *kShMem;
	DWORD kProcessId; // Process ID
	HANDLE kMap; // Shared Memory
	HANDLE kMutex; // The Synchronization Object
	BOOL kParentOrChild; // Identify the Process as Parent or Child.

	


};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ONEATATIMEDLG_H__6616245C_8DC3_45E4_B8BF_BA997155948F__INCLUDED_)

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
Technical Lead
India India
I am a personality from Trivandrum , a green peaceful place in Kerala, South India.
I have been an enthusiast of Windows programming when I started creating simple windows when I learnt VC++ in LCC in Trivandrum. From then on its all about Windows in my flesh and blood.
My career graph moves like this:
1. I started working as a C/C++ programmer in a company in Trivandrum where I learnt the ABCs of Software Industry. I worked with them for about 1 year. I could not contine since I was in contract for 1 year.
2. Then I joined another organization in Trivandrum who gave me challenges to love. They made me mad about VC++ and Windows.
I was mad about Embedded Systems which made me, Myself = Embedded Systems + VC++.
3. Software Engineer in a telecom company in Hyderabad, Andhra Pradesh, S.India.
4. Currently working with a telecom company in Bangalore.
I totally, so, have experience of about 4.5 years.

Comments and Discussions