Results 1 to 9 of 9

Thread: Weird Structure

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94

    Weird Structure

    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
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Your code?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You got any code for the class and the functions?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Beat ya
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Damnation parksie
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94
    //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
    }
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  7. #7
    jim mcnamara
    Guest
    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.

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    PHP Code:
    //This is the header file 

    struct CountSign 

    TCHAR sCountSigners[STRING_LENGTH]; 
    DWORD dwSignerSigned

    }; 

    class 
    CViewSigners : public CDialog 

    // Construction 
    public: 
    CViewSigners(CWndpParent NULL); // standard constructor 

    void AddSignerToDisplay(TCHAR *psSignerName); 
    void AddCounterSignerToDisplay(TCHAR *psCountSignerNameDWORD 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(CDataExchangepDX); // 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 *psCountSignerNameDWORD dwIndexOfSigCountSigned

    if(
    uiNumberOfCountSigners == MAX_SIGNERS


    TCHAR *psErrorMessage
    TCHAR *psErrorTitle

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

    LoadString(_Module.GetModuleInstance(), IDS_MAX_CERTSpsErrorMessageSTRING_LENGTH); 
    LoadString(_Module.GetModuleInstance(), IDS_CERTERROR_TITLEpsErrorTitleSTRING_LENGTH); 

    MessageBox(psErrorMessagepsErrorTitleMB_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]; 
    _ultoacCountSigners[uiNumberOfCountSigners].dwSignerSigned ,sTest10); 
    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_TREE141RGB(255,0,0)); 
    m_tSignersView.SetImageList(&m_imageListTVSIL_NORMAL); 

    CViewSigners::SetWindowText("Signers"); 

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

    TCHAR sTempCertName[STRING_LENGTH]; 

    for(
    int i 0uiNumberOfSignersi++) 

    hItem[i] = m_tSignersView.InsertItem(&sSigners[i][0], 00); 


    for(
    int u 0uiNumberOfCountSignersu++) 

    char sTest[10]; 
    _ultoacCountSigners[u].dwSignerSigned ,sTest10); 
    AfxMessageBox(sTest); 

    AfxMessageBox(cCountSigners[i].sCountSigners); 

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


    AfxMessageBox(sTempCertName); 

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

    _strset(sTempCertNameNULL); 








    //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 

    Baaaaaaaaah

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width