cant get file to compile

Pages: 12
i am trying to get this program to run but it keeps coming up with some errors
here is the program link to download if you need a reference
http://www.relisoft.com/win32/watcher.html

if you what the errors let me know
ok? guess i should try something else,ummm...

i am tring to run this program but it wont compile. it says that one variable isnt declared and another traces all the way back to a file called "backward_warning.h" where a deprecated tag wont let the file run. i dont get what the .h file does but this is the code for it
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _BACKWARD_BACKWARD_WARNING_H
#define _BACKWARD_BACKWARD_WARNING_H 1

#ifdef __DEPRECATED // this line here!!!
#warning This file includes at least one deprecated or antiquated header. \
Please consider using one of the 32 headers found in section 17.4.1.2 of the \
C++ standard. Examples include substituting the <X> header for the <X.h> \
header for C++ includes, or <iostream> instead of the deprecated header \
<iostream.h>. To disable this warning use -Wno-deprecated.
#endif

#endif 

then the code for the actual program is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "main.h"
#include <new.h>

int PASCAL WinMain
    (HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
    if (!strlen (cmdParam))
    {
        MessageBox (0, "Please, specify folder to watch", "Folder Watcher", MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    char className [] = "Folder Watcher";
    _set_new_handler(&NewHandler);       // this is the variable it said was undeclared

    BOOL isError = FALSE;
    try
    {
        WindowClass winClass (WndProc, className, hInst);
        winClass.Register ();

        Window win (cmdParam, className, hInst);
        
        // Add "About ..." to the system menu
        HMENU hSysMenu = GetSystemMenu (win, FALSE);
        AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL);
        AppendMenu (hSysMenu, MF_STRING, IDM_ABOUT, "About ...");
        // Disable Restore item
        EnableMenuItem (hSysMenu, 0, MF_BYPOSITION | MF_GRAYED);
        win.Show (SW_SHOWMINNOACTIVE);
    }
    catch ( WinException e )
    {
        e.Display ();
        isError = TRUE;
    }
    catch (...)
    {
        MessageBox (0, "Unknown", "Exception", MB_ICONEXCLAMATION | MB_OK);
        isError = TRUE;
    }

    if (isError)
        return 0;

    // The main message loop
    MSG  msg;
    int status;
    while ((status = GetMessage (&msg, 0, 0, 0)) != 0)
    {
        if (status == -1)
            return -1;
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return msg.wParam;
}            


let me know what you think, thanks...
alright so i it seems that any active object project wont compile in Dev C++. anyone heard of a problem like this and/or know how to fix it?
What is the error message?
1
2
3
4
5
6
7 C:\Dev-Cpp\include\c++\3.4.2\backward\new.h:33,               from C:\Users\Kyle\Desktop\watcher\main.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/new.h:33,               from C:\Users\Kyle\Desktop\watcher\main.cpp 

32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 

19 C:\Users\Kyle\Desktop\watcher\main.cpp `_set_new_handler' undeclared (first use this function) 
 
You have to #include <new> , not new.h. Also, that function is declared in std namespace so you need tp put this line into your ode:
using std::set_new_handler; or using namespace std; and finally, function name is set_new_handler (without underscore).
ok i made the changes but still has errors
1
2
3
20 C:\Users\Kyle\Desktop\watcher\main.cpp invalid conversion from `int (*)(size_t)' to `void (*)()' 

20 C:\Users\Kyle\Desktop\watcher\main.cpp   initializing argument 1 of `void (* std::set_new_handler(void (*)()))()'  

I think you are using set_new_handler in a wrong way. Here's a working example:
1
2
3
4
5
6
7
8
9
10
11
12
void handler()
{

    cout <<"\aError"<<endl;
    exit(0);
}

int main()
{
   set_new_handler(handler);
    int *p=new int [-1]; // memory allocation is impossible, calling handler()
}

Hope this helps.
well this isnt my program. got it from an online tutorial and it already had all these errors. dont really understand what the code means which is why i want to get it running.

not sure why it wont work,lol
closed account (S6k9GNh0)
The NewHandler identifier passed isn't implemented. He's just giving an example.
Last edited on
so the file is missing a line after the set_new_handler command?
i just have to find what it needs to be?
Just comment out the line with set_new_handler.
ok now these are the errors...
1
2
3
4
5
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 

  [Linker error] undefined reference to `_Z7WndProcP6HWND__jjl@16' 

32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h ld returned 1 exit status  

Still using new.h?

The linker error is , the linker cannot find function WndProc (that you've used).
ok almost there al i have left is the linker error and i have <new> not <new.h> right now
Have you defined WndProc and presented it to the compiler/linker?
not sure, like i said i got this from an online tutorial so i have no idea where everything is. i will try to look. should the declaration or WinProc be a class or in a class?
is this it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
LRESULT CALLBACK WndProc
    (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static Controller * pCtrl;

    switch (message)
    {
    case WM_CREATE:
        try
        {
            pCtrl = new Controller (hwnd, (CREATESTRUCT *) lParam);
        }
        catch (WinException e)
        {
            e.Display ();
            return -1;
        }
        catch (...)
        {
            MessageBox (hwnd, "Unknown Error", "Initialization", 
                MB_ICONEXCLAMATION | MB_OK);
            return -1;
        }
        return 0;
    case WM_FOLDER_CHANGE:
        pCtrl->OnFolderChange (hwnd, (char const *) lParam);
        return 0;
    case WM_SYSCOMMAND:
        if (pCtrl->SysCommand (hwnd, LOWORD (wParam)))
            return 0;
        break;
    case WM_DESTROY:
        delete pCtrl;
        return 0;
    }
    return DefWindowProc (hwnd, message, wParam, lParam);
}
Just a note, I've had a lot of issues with Dev-Cpp because it is out of production. Installing wxDev-Cpp found here: http://wxdsgn.sourceforge.net/ fixed a lot of my problems particularly when writing for the Windows API.

Also I'm concerned about this comment from the OP:

"well this isnt my program. got it from an online tutorial and it already had all these errors. dont really understand what the code means which is why i want to get it running."

If you see something like this:

1
2
3
4
5
6
int main()
{
   system("format C:";
return 0;
}


Would you execute it?
Last edited on
Pages: 12