Click here to Skip to main content
16,005,149 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 6:52
David Crow9-Nov-07 6:52 
GeneralRe: variable solution compiles, but I can't get at value: [modified] Pin
e40s9-Nov-07 7:04
e40s9-Nov-07 7:04 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 7:11
David Crow9-Nov-07 7:11 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 7:23
e40s9-Nov-07 7:23 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 7:28
David Crow9-Nov-07 7:28 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 8:15
e40s9-Nov-07 8:15 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 8:27
David Crow9-Nov-07 8:27 
GeneralRe: variable solution compiles, but I can't get at value: [modified] Pin
e40s9-Nov-07 8:39
e40s9-Nov-07 8:39 
It compiles, but I'm not getting anywhere. I'm so lost about following the instructions, I'm going to have to show the code. Here's the whole MemMapCppClientDlg.cpp:

// MemMapCppClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MemMapCppClient.h"
#include "MemMapCppClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

UINT CMemMapCppClientDlg::UWM_DATA_READY = RegisterWindowMessage(UWM_DATA_READY_MSG); 
/////////////////////////////////////////////////////////////////////////////
// CMemMapCppClientDlg dialog

CMemMapCppClientDlg::CMemMapCppClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMemMapCppClientDlg::IDD, pParent)
{
	m_pszMemMapFileName = _T("Mem_Map_File-{70122C30-0239-4f98-9D21-36885C8A8121}");
}
CString CMemMapCppClientDlg::m_strContent = "";

BEGIN_MESSAGE_MAP(CMemMapCppClientDlg, CDialog)
//[leave the dialog]	ON_WM_WINDOWPOSCHANGING()
	ON_REGISTERED_MESSAGE(UWM_DATA_READY, OnDataReady)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemMapCppClientDlg message handlers

BOOL CMemMapCppClientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

LRESULT CMemMapCppClientDlg::OnDataReady(WPARAM, LPARAM) 
{
	HANDLE hMapFile = NULL;
	PVOID pView = NULL;

	hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, m_pszMemMapFileName);
	if(hMapFile == NULL) {
		MessageBox("Can not open file mapping");
		return 0;
	}

	pView = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
	if(pView == NULL) {
		MessageBox("Can map view of file");
		CloseHandle(hMapFile);
		return 0;
	}

	LPSTR szContent = reinterpret_cast<LPSTR>(pView);
	int nLen = strlen(szContent);
	CString m_strContent;
	while(nLen > 0) {
		m_strContent += *szContent++;
		--nLen;
	}
	m_strContent += '\0';
	m_strContent.Replace("\n", "\r\n");
////	m_edit.SetWindowText(m_strContent);
    MessageBox(m_strContent);

	if(pView) UnmapViewOfFile(pView);
	if(hMapFile) CloseHandle(hMapFile);

	return 0;
}

CString CMemMapCppClientDlg::GetContent()
{
//    MessageBox(m_strContent, _T("Forget this."));
	return m_strContent;
}


Here's the MemMapCppClientDlg.h:

// MemMapCppClientDlg.h : header file
//

#if !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)
#define AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_

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

/////////////////////////////////////////////////////////////////////////////
// CMemMapCppClientDlg dialog

class CMemMapCppClientDlg : public CDialog
{
// Construction
public:
	static UINT UWM_DATA_READY;
	CMemMapCppClientDlg(CWnd* pParent = NULL);	// standard constructor
	static CString GetContent();
//	CString GetContent();

// Dialog Data
	enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };
	// ClassWizard generated virtual function overrides
	protected:

// Implementation
protected:
	// Generated message map functions
	//{{AFX_MSG(CMemMapCppClientDlg)
	virtual BOOL OnInitDialog();
//[leave the dialog]	afx_msg void CMemMapCppClientDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos);
	afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
	static CString m_strContent;
//	CString m_strContent;

private:
	//enum { m_dwMemFileSize = 2 * 1024 };
	LPCTSTR m_pszMemMapFileName;
};

	#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")

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

#endif // !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)


It compiles, but I followed the directions wrong. Nothing's showing up in the message box.
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 10:06
e40s9-Nov-07 10:06 
QuestionRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 10:15
David Crow9-Nov-07 10:15 
AnswerRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 13:01
e40s9-Nov-07 13:01 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 14:51
David Crow9-Nov-07 14:51 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s10-Nov-07 16:23
e40s10-Nov-07 16:23 
AnswerRe: variable solution compiles, but I can't get at value: Pin
Bram van Kampen10-Nov-07 15:02
Bram van Kampen10-Nov-07 15:02 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s10-Nov-07 16:26
e40s10-Nov-07 16:26 
QuestionDisplaying Graph Controls values in a grid. Pin
pod_9998-Nov-07 10:11
pod_9998-Nov-07 10:11 
JokeRe: Displaying Graph Controls values in a grid. Pin
shpid3r8-Nov-07 10:18
shpid3r8-Nov-07 10:18 
AnswerRe: Displaying Graph Controls values in a grid. Pin
Llasus8-Nov-07 12:56
Llasus8-Nov-07 12:56 
GeneralRe: Displaying Graph Controls values in a grid. Pin
pod_9999-Nov-07 0:16
pod_9999-Nov-07 0:16 
AnswerRe: Displaying Graph Controls values in a grid. Pin
Nelek8-Nov-07 21:36
protectorNelek8-Nov-07 21:36 
GeneralRe: Displaying Graph Controls values in a grid. Pin
pod_9999-Nov-07 0:15
pod_9999-Nov-07 0:15 
QuestionOT: Linux ELF Executable Checksum Algorithm Pin
Jeffrey Walton8-Nov-07 9:14
Jeffrey Walton8-Nov-07 9:14 
AnswerRe: OT: Linux ELF Executable Checksum Algorithm Pin
Randor 8-Nov-07 10:23
professional Randor 8-Nov-07 10:23 
GeneralRe: OT: Linux ELF Executable Checksum Algorithm Pin
Jeffrey Walton8-Nov-07 10:48
Jeffrey Walton8-Nov-07 10:48 
QuestionBitBlt w/ ROP codes in GDI+ Pin
Force Code8-Nov-07 8:00
Force Code8-Nov-07 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.