|
Whoa! How'd you do that?
I'll pull it and see what happens.
|
|
|
|
|
So how do I get around this?
|
|
|
|
|
One way is to make the member variable static . This means that GetContent() will also need to be static .
Your next question (regarding scope) can be answered here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Okay, I changed it to this:
#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
class CMemMapCppClientDlg : public CDialog
{
public:
static UINT UWM_DATA_READY;
CMemMapCppClientDlg(CWnd* pParent = NULL);
static CString GetContent();
enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };
protected:
protected:
virtual BOOL OnInitDialog();
afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
static CString m_strContent;
private:
LPCTSTR m_pszMemMapFileName;
};
#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")
#endif // !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)
Fascinating. (I mean that sincerely.) Well, the first thing it did was change the argument disposition of MessageBox inside of GetContent(), so I commented that MessageBox line out there.
Attempted a recompile.
The errors:
1>MemMapCppClientDlg.obj : error LNK2001: unresolved external symbol "protected: static class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > CMemMapCppClientDlg::m_strContent" (?m_strContent@CMemMapCppClientDlg@@1V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@A)
1>c:\experimental sample\Debug\MFC_DLL_03.dll : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\experimental sample\MFC_DLL_03\Debug\BuildLog.htm"
-- modified at 13:12 Friday 9th November, 2007
|
|
|
|
|
You have not initialized m_strContent . Static data members of classes must be initialized at file scope.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The link was informative. (For the future, especially about their inability to access non-static class member data using the member-selection operators mentioned. Learning more every day.)
What I tried:
#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
class CMemMapCppClientDlg : public CDialog
{
public:
static UINT UWM_DATA_READY;
CMemMapCppClientDlg(CWnd* pParent = NULL);
static CString CMemMapCppClientDlg::GetContent();
enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };
protected:
protected:
virtual BOOL OnInitDialog();
afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
static CString CMemMapCppClientDlg::m_strContent;
private:
LPCTSTR m_pszMemMapFileName;
};
#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")
#endif // !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)
Darn. Same errors. (Afterward I even tried adding scope resolution to some of the statements on the .cpp. Nothing changed for the better so I took those off.)
|
|
|
|
|
e40s wrote: static CString CMemMapCppClientDlg::m_strContent;
Remove CMemMapCppClientDlg from the declaration. Add the following after CMemMapCppClientDlg 's constructor definition:
CString CMemMapCppClientDlg::m_strContent = "";
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm confused. There's a constructor in MemMapCppClientDlg.cpp. Do I involve the .cpp in the changes, or is just the MemMapCppClientDlg.h involved?
|
|
|
|
|
e40s wrote: Do I involve the .cpp in the changes...
Yes, since you have to do the initialization at file scope.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
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:
#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::CMemMapCppClientDlg(CWnd* pParent )
: CDialog(CMemMapCppClientDlg::IDD, pParent)
{
m_pszMemMapFileName = _T("Mem_Map_File-{70122C30-0239-4f98-9D21-36885C8A8121}");
}
CString CMemMapCppClientDlg::m_strContent = "";
BEGIN_MESSAGE_MAP(CMemMapCppClientDlg, CDialog)
ON_REGISTERED_MESSAGE(UWM_DATA_READY, OnDataReady)
END_MESSAGE_MAP()
BOOL CMemMapCppClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}
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");
MessageBox(m_strContent);
if(pView) UnmapViewOfFile(pView);
if(hMapFile) CloseHandle(hMapFile);
return 0;
}
CString CMemMapCppClientDlg::GetContent()
{
return m_strContent;
}
Here's the MemMapCppClientDlg.h:
#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
class CMemMapCppClientDlg : public CDialog
{
public:
static UINT UWM_DATA_READY;
CMemMapCppClientDlg(CWnd* pParent = NULL);
static CString GetContent();
enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };
protected:
protected:
virtual BOOL OnInitDialog();
afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
static CString m_strContent;
private:
LPCTSTR m_pszMemMapFileName;
};
#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")
#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.
|
|
|
|
|
Knowing that a static asssignment can make this work is a lot further along than where I was yesterday (which is a lot farther than where I was the days and and weeks before that.)
I'm sorry I couldn't follow the instructions. My fault. I don't know if my changes to the code are right or wrong. But thanks for the guidance.
|
|
|
|
|
e40s wrote: Nothing's showing up in the message box.
It's probably because you are not modifying CMemMapCppClientDlg::m_strContent , but are modifying m_strContent that is local to OnDataReady() instead. Do you concur?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I don't understand. Are you saying you observe that's what I'm currently doing, and I shouldn't?
Or are you saying that's what I'm not currently doing?
Isn't m_strContect local to OnDataReady?
Where have I written something where I shouldn't? Where should I write something?
|
|
|
|
|
e40s wrote: Isn't m_strContect local to OnDataReady?
Yes, it has such a local variable that gets destroyed when OnDataReady() goes out of scope. Remove that one and you should be good to go.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
David, I really want to thank you for your considerable help and patience and time expended in teaching me how to do this. I'm away from my machine at the moment, but I'd like to test this out as soon as I can reestablish my work in a few days. I'm looking forward to seeing it work.
Thanks again.
|
|
|
|
|
e40s wrote: VARIANT _stdcall SumOneToArray(VARIANT sourceArray)
{
CMemMapCppClientDlg dlg;
CString strContent = dlg.GetContent();
MessageBox(NULL, _T(strContent), _T("Like this:"), MB_OK);
You declare a NEW instance of the CMemMapCppClientDlg! Another instance may have ran, but this one definitely has not! So, m_strContent is still empty!
As a consequence MessageBox(...) will display the empty string. Nothing Strange about that.( why not use AfxMessageBox(...)? )
If you want to share m_strContent between different instances, make it static! Be aware of other side effects though if you do this.
BTW Do not use the _T() Macro on a variable, only on quoted text.
Hope this helps you along
Bram van Kampen
|
|
|
|
|
Bram, thank you for this; the more posters who confirm this direction means I can be that much more comfortable this is the standard and state of the art.
|
|
|
|
|
Hi there,
I'm using an MFC graph control to display multiple lines from a stored results file. Each line has a corresponding Y axis & colour.
Is it possible to drag a vertical line across the chart (using OnLButtonDown?) which would then dynamically display the intersecting values in a grid control, along with the corresponding Y axis name & line colour?
Cheers.
PS. This is my 1st post to Code Project so I apologise if it's a bit vague.
ADVAthanksNCE
|
|
|
|
|
ADVAthanksNCE is so great
Hope someone will know how to help you
Cheers
|
|
|
|
|
Can you give me details about the MFC graph control that you are using? It is possible to get that as long as you have complete access to the graph control.
|
|
|
|
|
Hi, The graph control is an ocx (COleControlModule) and I do have full access to it.
At the moment, I use a CDialog to drop the basic line chart into.
To be specific, what I want to do is:
Enhance my basic line graph to:
1. Add a mouse-moveable vertical line originating from the x-axis.
2. Display the values at the points where the lines on the graph intersect the vertical line.
3. Use a grid to display each value with it's associated line colour/type & name.
4. Add/remove lines (& relevant y-axes) to the graph & grid.
Thanks.
|
|
|
|
|
If you want to drag a line of your graph control, you will need to be more specifical and post some code to let the others know about the situation.
If you just want to have a vertical line moving... you can make it easily with the DC, MoveTo and LineTo...
Explain a bit more about what you really need and... if you are new in forum... I recommend you to read this[^]
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi, Apologies, I'll be more specific. What I want to do is:
Enhance my basic line graph to:
1. Add a mouse-moveable vertical line originating from the x-axis.
2. Display the values at the points where the lines on the graph intersect the vertical line.
3. Use a grid to display each value with it's associated line colour/type & name.
4. Add/remove lines (& relevant y-axes) to the graph & grid.
The graph control is an ocx (COleControlModule) and I have full access to it.
At the moment, I use a CDialog to drop the basic line chart into.
Thanks.
|
|
|
|
|
Hi All,
I am hoping someone can lend assistance for the following. I did not receive any responses in the 'General Discussion' area. I recently submitted an article wich grafts compiled executable code on Windows. See Grafting Compiled Code[^]
What I would like to demonstrate next is the grafting of Linux code into a Windows executable. For a donor, I was thinking it would be appropriate to stay with the Checksum algorithm. So the ELF checksum seems like a good candidate.
For this, I have questions:
1) Does ELF use a checksum (or hash)
2) What Linux function is called to perform this?
3) In which lib is the function located?
Thanks,
Jeff
|
|
|
|
|
Hello Jeff,
Executable and Linking Format uses a hash.
unsigned long ElfHash(unsigned char* c)
{
unsigned long hash = 0;
unsigned long x = 0;
while (*c)
{
hash = (hash << 4 ) + *c++;
if(x = hash & 0xF0000000)
{
hash ^= x >> 24;
}
hash &= ~x;
}
return hash;
}
This project is great for researching ELF format:
http://sourceforge.net/projects/elfio/[^]
|
|
|
|