Click here to Skip to main content
15,911,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question5Queens/5Knights on 8x8 board Pin
Ramper8-Nov-07 15:12
Ramper8-Nov-07 15:12 
AnswerRe: 5Queens/5Knights on 8x8 board Pin
Luc Pattyn8-Nov-07 17:47
sitebuilderLuc Pattyn8-Nov-07 17:47 
AnswerRe: 5Queens/5Knights on 8x8 board Pin
David Crow9-Nov-07 4:32
David Crow9-Nov-07 4:32 
QuestionMatrix Multiplication Pin
7.3DIESEL8-Nov-07 13:57
7.3DIESEL8-Nov-07 13:57 
AnswerRe: Matrix Multiplication Pin
Nelek8-Nov-07 21:47
protectorNelek8-Nov-07 21:47 
QuestionRDTSC Pin
hxhl958-Nov-07 11:37
hxhl958-Nov-07 11:37 
AnswerRe: RDTSC Pin
Mark Salsbery8-Nov-07 12:37
Mark Salsbery8-Nov-07 12:37 
Questionvariable solution compiles, but I can't get at value: [modified] Pin
e40s8-Nov-07 11:01
e40s8-Nov-07 11:01 
I've written into some Code Project sample code a solution generously offered to me by a fellow poster for an adaptation to the code I had wanted to make. I had asked the board if there was a way to get at the value inside a variable called strContent here inside of OnDataReady (and one aspect of the solution involved renaming it to m_strContent, the way it's now shown here in this CMemMapCppClientDlg.cpp snip):

LRESULT CMemMapCppClientDlg::OnDataReady(WPARAM, LPARAM) <br />
{<br />
	HANDLE hMapFile = NULL;<br />
	PVOID pView = NULL;<br />
<br />
	hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, m_pszMemMapFileName);<br />
	if(hMapFile == NULL) {<br />
		MessageBox("Can not open file mapping");<br />
		return 0;<br />
	}<br />
<br />
	pView = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);<br />
	if(pView == NULL) {<br />
		MessageBox("Can map view of file");<br />
		CloseHandle(hMapFile);<br />
		return 0;<br />
	}<br />
<br />
	LPSTR szContent = reinterpret_cast<LPSTR>(pView);<br />
	int nLen = strlen(szContent);<br />
	while(nLen > 0) {<br />
		m_strContent += *szContent++;<br />
		--nLen;<br />
	}<br />
	m_strContent += '\0';<br />
	m_strContent.Replace("\n", "\r\n");<br />
<br />
	if(pView) UnmapViewOfFile(pView);<br />
	if(hMapFile) CloseHandle(hMapFile);<br />
<br />
	return 0;<br />
}<br />
<br />
CString CMemMapCppClientDlg::GetContent()<br />
{<br />
  return m_strContent;<br />
}





Another part of the solution involved adding the ::GetContent() function, shown there immediately above.

Then the appropriate changes were shown to me for the header, here:

// MemMapCppClientDlg.h : header file<br />
//<br />
<br />
#if !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)<br />
#define AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CMemMapCppClientDlg dialog<br />
<br />
class CMemMapCppClientDlg : public CDialog<br />
{<br />
// Construction<br />
public:<br />
	static UINT UWM_DATA_READY;<br />
	CMemMapCppClientDlg(CWnd* pParent = NULL);	// standard constructor<br />
    CString GetContent();<br />
<br />
// Dialog Data<br />
	enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };<br />
	// ClassWizard generated virtual function overrides<br />
	protected:<br />
<br />
// Implementation<br />
protected:<br />
	// Generated message map functions<br />
	//{{AFX_MSG(CMemMapCppClientDlg)<br />
	virtual BOOL OnInitDialog();<br />
//[leave the dialog]	afx_msg void CMemMapCppClientDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos);<br />
	afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);<br />
	DECLARE_MESSAGE_MAP()<br />
    CString m_strContent; <br />
<br />
private:<br />
	//enum { m_dwMemFileSize = 2 * 1024 };<br />
	LPCTSTR m_pszMemMapFileName;<br />
};<br />
<br />
	#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")<br />
<br />
//{{AFX_INSERT_LOCATION}}<br />
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.<br />
<br />
#endif // !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)





And, lastly, here is the MemMapCppClient.cpp that contains the call to GetContent():

// MemMapCppClient.cpp : Defines the class behaviors for the application.<br />
//<br />
...<br />
<br />
VARIANT _stdcall SumOneToArray(VARIANT sourceArray)<br />
{<br />
CMemMapCppClientDlg dlg;<br />
CString strContent = dlg.GetContent();<br />
MessageBox(NULL, _T(strContent), _T("Like this:"), MB_OK);<br />
//MessageBox(NULL, _T("Hey."), _T("Like this:"), MB_OK);<br />
<br />
//check if Array is a Range object<br />
if(sourceArray.vt==VT_DISPATCH)<br />
sourceArray = CheckExcelArray(sourceArray);<br />
<br />
long ncols, nrows, i, j;<br />
<br />
//get the number columns and rows<br />
ncols=(sourceArray.parray)->rgsabound[0].cElements;<br />
nrows=(sourceArray.parray)->rgsabound[1].cElements;<br />
<br />
...<br />
}<br />
...





I've gone and stuck the...

CMemMapCppClientDlg dlg;<br />
CString strContent = dlg.GetContent();<br />
MessageBox(NULL, _T(strContent), _T("Like this:"), MB_OK);


...inside the top of one of the functions. The project won't compile if I put those statements anywhere else in the function, like in the middle. I get "initialization" errors.

The question is this: Even when all of this compiles perfectly, and my program works great--even the MessageBox gets displayed on cue--no content is there in the MessageBox. Never in any incarnation of a successful compile do I get content within the MessageBox. The prog always works perfectly otherwise.

(I know for a fact content is otherwise available in m_strContent over in the MemMapCppClient.cpp because if I put the MessageBox over there, I get m_strContent just fine.)

I botched this somehow. How can I get a value into the MessageBox inside of CMemMapCppClientApp?

Thanks again for all your help.






-- modified at 18:45 Thursday 8th November, 2007
AnswerRe: variable solution compiles, but I can't get at value: Pin
Llasus8-Nov-07 12:53
Llasus8-Nov-07 12:53 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 4:30
e40s9-Nov-07 4:30 
AnswerOfftopic Pin
Nelek8-Nov-07 21:39
protectorNelek8-Nov-07 21:39 
GeneralRe: Offtopic Pin
e40s9-Nov-07 5:14
e40s9-Nov-07 5:14 
QuestionRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 4:39
David Crow9-Nov-07 4:39 
AnswerRe: variable solution compiles, but I can't get at value: [modified] Pin
e40s9-Nov-07 5:02
e40s9-Nov-07 5:02 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 5:34
David Crow9-Nov-07 5:34 
GeneralRe: variable solution compiles, but I can't get at value: [modified] Pin
e40s9-Nov-07 6:03
e40s9-Nov-07 6:03 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 6:20
David Crow9-Nov-07 6:20 
GeneralRe: variable solution compiles, but I can't get at value: [modified] Pin
e40s9-Nov-07 6:36
e40s9-Nov-07 6:36 
GeneralRe: variable solution compiles, but I can't get at value: Pin
David Crow9-Nov-07 6:40
David Crow9-Nov-07 6:40 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 6:45
e40s9-Nov-07 6:45 
GeneralRe: variable solution compiles, but I can't get at value: Pin
e40s9-Nov-07 6:47
e40s9-Nov-07 6:47 
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 

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.