PDA

Click to See Complete Forum and Search --> : Weird Structure


pskyboy
Nov 2nd, 2001, 01:05 PM
Hey Guys

I have a structure i defined myself which contains a string and a DWORD.

I have declared an instance of this in the header of a class and then i have functions in my class that write to this public variable. Well anyway when you try and read data out in another function the variable is empty.

Has anyone got any ideas

Peter

parksie
Nov 2nd, 2001, 01:11 PM
Your code?

kedaman
Nov 2nd, 2001, 01:11 PM
You got any code for the class and the functions?

parksie
Nov 2nd, 2001, 01:12 PM
Beat ya ;)

kedaman
Nov 2nd, 2001, 01:15 PM
Damnation parksie:o

pskyboy
Nov 2nd, 2001, 02:02 PM
//This is the header file

struct CountSign
{
TCHAR sCountSigners[STRING_LENGTH];
DWORD dwSignerSigned;

};

class CViewSigners : public CDialog
{
// Construction
public:
CViewSigners(CWnd* pParent = NULL); // standard constructor

void AddSignerToDisplay(TCHAR *psSignerName);
void AddCounterSignerToDisplay(TCHAR *psCountSignerName, DWORD dwIndexOfSigCountSigned);

// Dialog Data
//{{AFX_DATA(CViewSigners)
enum { IDD = IDD_SIGNER_DISPLAY };
CTreeCtrl m_tSignersView;
//}}AFX_DATA


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CViewSigners)
public:
virtual int DoModal();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

CImageList m_imageList;

// Generated message map functions
//{{AFX_MSG(CViewSigners)
virtual BOOL OnInitDialog();
virtual void OnCancel();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

private:

TCHAR sSigners[STRING_LENGTH][MAX_SIGNERS];
//TCHAR sCountSigners[STRING_LENGTH][MAX_SIGNERS];

CountSign cCountSigners[MAX_SIGNERS];

UINT uiNumberOfSigners;
UINT uiNumberOfCountSigners;
};


//This is the bit that writes the data into the structure

void CViewSigners::AddCounterSignerToDisplay(TCHAR *psCountSignerName, DWORD dwIndexOfSigCountSigned)
{
if(uiNumberOfCountSigners == MAX_SIGNERS)
{

TCHAR *psErrorMessage;
TCHAR *psErrorTitle;

psErrorMessage = new TCHAR[STRING_LENGTH];
psErrorTitle = new TCHAR[STRING_LENGTH];

LoadString(_Module.GetModuleInstance(), IDS_MAX_CERTS, psErrorMessage, STRING_LENGTH);
LoadString(_Module.GetModuleInstance(), IDS_CERTERROR_TITLE, psErrorTitle, STRING_LENGTH);

MessageBox(psErrorMessage, psErrorTitle, MB_OK | MB_ICONWARNING);

delete[] psErrorMessage;
delete[] psErrorTitle;
}
else
{
strcpy(&cCountSigners[uiNumberOfCountSigners].sCountSigners[0], psCountSignerName);

cCountSigners[uiNumberOfCountSigners].dwSignerSigned = dwIndexOfSigCountSigned;

AfxMessageBox(cCountSigners[uiNumberOfCountSigners].sCountSigners);
char sTest[10];
_ultoa( cCountSigners[uiNumberOfCountSigners].dwSignerSigned ,sTest, 10);
AfxMessageBox(sTest);

uiNumberOfCountSigners++;
}

}


//This is the bit thats ment to read it out

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


HTREEITEM hItem[MAX_SIGNERS];
m_imageList.Create(IDB_SIGNER_TREE, 14, 1, RGB(255,0,0));
m_tSignersView.SetImageList(&m_imageList, TVSIL_NORMAL);

CViewSigners::SetWindowText("Signers");

//m_stSignersTitle = _T("File Signed By");
//UpdateData(FALSE);

TCHAR sTempCertName[STRING_LENGTH];

for(int i = 0; i < uiNumberOfSigners; i++)
{
hItem[i] = m_tSignersView.InsertItem(&sSigners[i][0], 0, 0);
}

for(int u = 0; u < uiNumberOfCountSigners; u++)
{
char sTest[10];
_ultoa( cCountSigners[u].dwSignerSigned ,sTest, 10);
AfxMessageBox(sTest);

AfxMessageBox(cCountSigners[i].sCountSigners);

strcpy(&sTempCertName[0], cCountSigners[i].sCountSigners);


AfxMessageBox(sTempCertName);

m_tSignersView.InsertItem(&sTempCertName[0], 1, 1, hItem[cCountSigners[i].dwSignerSigned]);

_strset(sTempCertName, NULL);
}







//hItem = m_tSignersView.InsertItem("Test", 0, 0);
//m_tSignersView.InsertItem("Test", 1, 1, hItem);
// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

jim mcnamara
Nov 2nd, 2001, 02:53 PM
MFC-looking code is hard to read like this. At least for me.

Do you know about CODE & /CODE [code in brackets] around the C++ source you paste up?


Thanks.

abdul
Nov 2nd, 2001, 03:17 PM
//This is the header file

struct CountSign
{
TCHAR sCountSigners[STRING_LENGTH];
DWORD dwSignerSigned;

};

class CViewSigners : public CDialog
{
// Construction
public:
CViewSigners(CWnd* pParent = NULL); // standard constructor

void AddSignerToDisplay(TCHAR *psSignerName);
void AddCounterSignerToDisplay(TCHAR *psCountSignerName, DWORD dwIndexOfSigCountSigned);

// Dialog Data
//{{AFX_DATA(CViewSigners)
enum { IDD = IDD_SIGNER_DISPLAY };
CTreeCtrl m_tSignersView;
//}}AFX_DATA


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CViewSigners)
public:
virtual int DoModal();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

CImageList m_imageList;

// Generated message map functions
//{{AFX_MSG(CViewSigners)
virtual BOOL OnInitDialog();
virtual void OnCancel();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

private:

TCHAR sSigners[STRING_LENGTH][MAX_SIGNERS];
//TCHAR sCountSigners[STRING_LENGTH][MAX_SIGNERS];

CountSign cCountSigners[MAX_SIGNERS];

UINT uiNumberOfSigners;
UINT uiNumberOfCountSigners;
};


//This is the bit that writes the data into the structure

void CViewSigners::AddCounterSignerToDisplay(TCHAR *psCountSignerName, DWORD dwIndexOfSigCountSigned)
{
if(uiNumberOfCountSigners == MAX_SIGNERS)
{

TCHAR *psErrorMessage;
TCHAR *psErrorTitle;

psErrorMessage = new TCHAR[STRING_LENGTH];
psErrorTitle = new TCHAR[STRING_LENGTH];

LoadString(_Module.GetModuleInstance(), IDS_MAX_CERTS, psErrorMessage, STRING_LENGTH);
LoadString(_Module.GetModuleInstance(), IDS_CERTERROR_TITLE, psErrorTitle, STRING_LENGTH);

MessageBox(psErrorMessage, psErrorTitle, MB_OK | MB_ICONWARNING);

delete[] psErrorMessage;
delete[] psErrorTitle;
}
else
{
strcpy(&cCountSigners[uiNumberOfCountSigners].sCountSigners[0], psCountSignerName);

cCountSigners[uiNumberOfCountSigners].dwSignerSigned = dwIndexOfSigCountSigned;

AfxMessageBox(cCountSigners[uiNumberOfCountSigners].sCountSigners);
char sTest[10];
_ultoa( cCountSigners[uiNumberOfCountSigners].dwSignerSigned ,sTest, 10);
AfxMessageBox(sTest);

uiNumberOfCountSigners++;
}

}


//This is the bit thats ment to read it out

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


HTREEITEM hItem[MAX_SIGNERS];
m_imageList.Create(IDB_SIGNER_TREE, 14, 1, RGB(255,0,0));
m_tSignersView.SetImageList(&m_imageList, TVSIL_NORMAL);

CViewSigners::SetWindowText("Signers");

//m_stSignersTitle = _T("File Signed By");
//UpdateData(FALSE);

TCHAR sTempCertName[STRING_LENGTH];

for(int i = 0; i < uiNumberOfSigners; i++)
{
hItem[i] = m_tSignersView.InsertItem(&sSigners[i][0], 0, 0);
}

for(int u = 0; u < uiNumberOfCountSigners; u++)
{
char sTest[10];
_ultoa( cCountSigners[u].dwSignerSigned ,sTest, 10);
AfxMessageBox(sTest);

AfxMessageBox(cCountSigners[i].sCountSigners);

strcpy(&sTempCertName[0], cCountSigners[i].sCountSigners);


AfxMessageBox(sTempCertName);

m_tSignersView.InsertItem(&sTempCertName[0], 1, 1, hItem[cCountSigners[i].dwSignerSigned]);

_strset(sTempCertName, NULL);
}







//hItem = m_tSignersView.InsertItem("Test", 0, 0);
//m_tSignersView.InsertItem("Test", 1, 1, hItem);
// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

parksie
Nov 2nd, 2001, 03:40 PM
At least indent it first, I'm normally inclined not to bother even trying to read it if it's unindented.

And also it's MFC so...