Thread: Big Code, Little Problem

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    Big Code, Little Problem

    Sorry to bother you all, but I have a small problem in a large amount of code. All I can say is I think it's a bracket problem. Well, here's the code and the problem (reverse that).

    --------------------Configuration: Password - Win32 Debug--------------------
    Compiling...
    PasswordDlg.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\Password\PasswordDlg.cpp(220) : error C2601: 'OnStaticPassword' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Password\PasswordDlg.cpp(226) : error C2601: 'OnBypass' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Password\PasswordDlg.cpp(251) : error C2601: 'OnSelchangeTab' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Password\PasswordDlg.cpp(259) : error C2601: 'OnOK' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Password\PasswordDlg.cpp(275) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    Password.exe - 5 error(s), 0 warning(s)


    // PasswordDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "Password.h"
    #include "PasswordDlg.h"
    #include <string.h>
    #include <fstream.h>

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

    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App About
    // global variables{
    int count;
    //}

    class CAboutDlg : public CDialog
    {
    public:

    CAboutDlg();

    // Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL

    // Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    virtual void OnOK();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };

    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT

    }

    void CAboutDlg:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CPasswordDlg dialog

    CPasswordDlg::CPasswordDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CPasswordDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CPasswordDlg)
    m_PASSWORD = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }

    void CPasswordDlg:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CPasswordDlg)
    DDX_Text(pDX, IDC_EDIT1, m_PASSWORD);
    DDV_MaxChars(pDX, m_PASSWORD, 15);
    //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CPasswordDlg, CDialog)
    //{{AFX_MSG_MAP(CPasswordDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_STATIC1, OnStaticPassword)
    ON_BN_CLICKED(IDBYPASS, OnBypass)
    ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CPasswordDlg message handlers

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

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }

    // Set the icon for this dialog. The framework does this automatically
    // when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

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

    void CPasswordDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }

    // If you add a minimize button to your dialog, you will need the code below
    // to draw the icon. For MFC applications using the document/view model,
    // this is automatically done for you by the framework.

    void CPasswordDlg::OnPaint()
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

    // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }

    // The system calls this to obtain the cursor to display while the user drags
    // the minimized window.
    HCURSOR CPasswordDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }

    void CPasswordDlg::OnCancel()
    {
    // TODO: Add extra cleanup here


    }

    void CPasswordDlg::OnOK()
    {
    char buffer[50];
    UINT nPreviousState;

    UpdateData();
    ifstream FileReader("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\Password\\password.psw", ios::nocreate);
    FileReader>>buffer;
    if(m_PASSWORD.IsEmpty() == TRUE)
    {
    MessageBox("You haven't entered a password yet!");
    }
    else
    {
    if (!strcmp(m_PASSWORD,buffer))
    {
    MessageBox("PASSWORD ACCEPTED, DAVID","ACCEPTANCE");
    // Re-Enable them... (NOTE: if you don't re-enable them they will stay
    // dis-abled after the program dies...
    SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
    CDialog::OnOK();
    }
    else
    {
    MessageBox("Incorrect","Incorrect");

    }
    }

    void CPasswordDlg::OnStaticPassword()
    {
    // TODO: Add your control notification handler code here

    }

    void CPasswordDlg::OnBypass()
    {
    UINT nPreviousState;
    char string[3];
    ifstream FileReader("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\Password\\bypass.psw", ios::nocreate);
    FileReader>>string;
    if (!strcmpi(string,"yes"))
    {
    MessageBox("Bypass switch on","Bypassed");
    // Re-Enable them... (NOTE: if you don't re-enable them they will stay
    // dis-abled after the program dies...
    SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
    CDialog::OnOK();
    }
    else if (!strcmpi(string,"no"))
    {
    MessageBox("Bypass switch set to off","No Access");
    }
    else
    {
    MessageBox("Could not find bypass switch","NO-CAN-DO");
    }

    }

    void CPasswordDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
    {
    // TODO: Add your control notification handler code here
    // TODO: Add overall tab coding. Check your C++ book for code.

    *pResult = 0;
    }

    void CAboutDlg::OnOK()
    {
    int *counter = new int;
    counter = &count;
    if (*counter < 0)
    {
    counter = 0;
    }
    count++;
    if (*counter > 2)
    {
    CString str;
    str.Format("Why are you looking at this so many times? You've looked at it %d times already!",count);
    MessageBox(str);
    }
    CDialog::OnOK();
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    32
    Okay the first four errors don't seem to be a bracket problem. I don't know C++ so I'm not even going to try and debug the code for ya

    With the four first errors what it sounds like is that you have defined your functions in an illegal manner? I have never seen this error before, so perhaps it is a bracket error. But the last error is definitly a bracket or curly bracket error. You have missed placing one just before the line:

    void CPasswordDlg::OnStaticPassword()

    Perhaps this will fix all your problems? I don't. Just give it a try and see if it works out. I think it's that line anyways. Infact I just double checked it and I am 95% sure that you are missing one there.

    HTH
    cerion
    Use the code Luke.

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    it should fix all your errors - because there's no curly bracket your compiler thinks you're trying to declare those functions inside your other function.

  4. #4
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    void CPasswordDlg:oDataExchange(CDataExchange* pDX)
    I tried to compile your code, but VisualC++ signalled an error:
    "Error 65535 : Smileys not allowed in method declaration"


    Just kidding.
    Btw, you can easily trace your brackets using Ctrl-M (might be different, depends on the key-mapping settings, I use VisualC++2.0 mapping)

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Thanks people. One problem, I fixed the last error, but the other errors were not fixed. I think another bracket many be declaring the functions within another function. I, however, cannot find it.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with compiling code with option -O2
    By koushikyou in forum C Programming
    Replies: 16
    Last Post: 01-07-2009, 06:03 AM
  2. Problem with progress code
    By JFonseka in forum C Programming
    Replies: 13
    Last Post: 04-25-2008, 05:03 PM
  3. Small Problem that could be a big problem
    By sytaylor in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2004, 09:49 AM
  4. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM