Thread: Compiling issue with the OpenGL tutorial by RoD

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    16

    Compiling issue with the OpenGL tutorial by RoD

    I've been trying to follow along with the OpenGl tutorial by RoD and I've gotten to the "First Windows Program" area. I was feeling lazy so I simply copied and pasted it into my compiler to see what it would accomplish and I got these errors:

    Code:
    \Documents and Settings\***\My Documents\Untitled11.cpp C:\Documents and Settings\***\My Documents\C stdafx.h: No such file or directory. 
    C:\Documents and Settings\***\My Documents\Untitled11.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 
    82 C:\Documents and Settings\***\My Documents\Untitled11.cpp [Warning] passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)' 
    90 C:\Documents and Settings\***\My Documents\Untitled11.cpp [Warning] passing NULL used for non-pointer converting 3 of `BOOL PeekMessageA(tagMSG*, HWND__*, UINT, UINT, UINT)'
    90 C:\Documents and Settings\***\My Documents\Untitled11.cpp [Warning] passing NULL used for non-pointer converting 4 of `BOOL PeekMessageA(tagMSG*, HWND__*, UINT, UINT, UINT)'
    Now I'll admit to being new to this programming stuff, but I have done a fair deal of copying and pasting and consider myself quite proficient in it at this point, so the problem must be with the code or the compiler (Dev-C++).

    I tried to contact the author, but you can imagine the problem with that. Any ideas what is going wrong?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>fair deal of copying and pasting and consider myself quite proficient in it at this point<<

    So you no doubt fully appreciate how ultimately futile this is as an approach to learning.

    stdafx.h is an msvc specific header; it's not needed so comment it out or remove its #inclusion.

    The other errors are because the non-numeric NULL (which is a pointer type) is used in place of zero for the parameters of several api function calls in the code. If you program in c++ I'd suggest just using zero for both numeric zero and in place of the NULL pointer, unless you want to make an explicit statement to yourself about what types are involved in the latter case. To fix those particuar errors just replace each instance of NULL in the function call with a zero. If you prefer to use NULL for pointer types, then refer to msdn for the parameter types for each api function in question and just replace the NULLs that are incorrectly used as zero for numeric types.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    16
    Quote Originally Posted by Ken Fitlike
    So you no doubt fully appreciate how ultimately futile this is as an approach to learning.
    Fully. Like I said I simply was lazy and wanted to see what the program accomplished before reading about exactly what each part does. I'll try and decipher your message and then go from there. Thanks.

    Edit: I'm sorry, but I didn't understand the vast majority of that second paragraph. I've done the basic tutorials and understood as much as my mind would allow, but I'm still lost. Maybe I should look into a book or something.
    Last edited by Twitchmokey; 06-25-2006 at 07:28 PM. Reason: addition

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    NULL is not a pointer. NULL is defined as 0.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Twitchmokey
    Edit: I'm sorry, but I didn't understand the vast majority of that second paragraph. I've done the basic tutorials and understood as much as my mind would allow, but I'm still lost. Maybe I should look into a book or something.
    The warnings are telling you that the compiler expects a numeric type as parameters but are being given NULL, which it regards as a pointer type. For the first warning, CreateWindowEx expects a DWORD as the first parameter ie it should be a number and NULL isn't intended to be used as a number but as a pointer value; it's either defined as (void*) 0 or 0 (zero) depending on whether you're compiling c or c++ but its use implies a pointer. The warning tells you that NULL is a pointer and not a number; it's asking you why you are trying to bash a square peg into a round hole(even though it will convert NULL to zero if you choose to ignore the warning, which you shouldn't).

    Likewise, the 3rd and 4th parameters of PeekMessage are numerical types, too, and NULL should never be used where a numeric type is intended or expected, so change them to zero, too.
    Quote Originally Posted by Desolation
    NULL is defined as 0.
    Quote Originally Posted by windef.h
    #ifndef NULL
    #ifdef __cplusplus
    #define NULL 0
    #else
    #define NULL ((void *)0)
    #endif
    #endif
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    I program in C++, that's why I said it was defined as 0. I didn't know about the C version, however.

  7. #7
    Registered User
    Join Date
    Jun 2006
    Posts
    16
    I just can't seem to make this work. I get what you're saying, well, I don't precisely, I don't know why CreatewindowEx expects a number, but I do know the difference between a pointer and a number (I shouldn't be celebrated this victory, should I?). I can go to the lines that have errors and replace NULL with zero, 0 (zero), void*, or void* (0), but all of these seem to make more errors than they fix. I can't imagine what else you meant should be done, as I'm simply replacing NULLs on the problem lines.

    If anything good comes out of this though, it's that I found the goto line function, which should be handy.

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Assuming this page contains the problematic code, then:
    Code:
    hwnd = CreateWindowEx(0,  //extended style
        "MyClass",            //class name
        "A Real Win App",     //app name
        WS_OVERLAPPEDWINDOW | //window style
        WS_VISIBLE |
        WS_SYSMENU,
        100,100,              //x/y coords
        400,400,              //width,height
        NULL,                 //handle to parent
        NULL,                 //handle to menu
        hInstance,            //application instance
        NULL);
    and
    Code:
    PeekMessage(&msg,hwnd,0,0,PM_REMOVE);
    Don't forget to remove the '#include <stdafx.h>' and '#pragma comment(linker, "/subsystem:windows")' lines.

    If, after making those changes, you still get errors/warnings then you should post those errors/warnings just as you did in your original post.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User
    Join Date
    Jun 2006
    Posts
    16
    Well, I have reduced the number of errors, and that's a good start; here are the ones I'm getting now:

    Code:
      
    [Linker error] undefined reference to `SetTextColor@8' 
    [Linker error] undefined reference to `TextOutA@20'
    [Linker error] undefined reference to `GetStockObject@4'  
    ld returned 1 exit status
    Thanks for your help.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You need to build a gui application for any program with 'WinMain' in it, not a console(which uses 'main'). To do this with dev-cpp, go to the project menu -->project options to open the 'project options' dialog and, with the 'general' tab selected, make sure that 'Win32GUI' is selected in the 'type' field. Building as a gui application makes sure that a few of the most common windows libraries are linked, including gdi32, which is required for those api functions giving rise to the errors you have listed.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Registered User
    Join Date
    Jun 2006
    Posts
    16
    That is surely important. The issue now is that everything in the project menu is grayed...or greyed. It's really a matter of personal preference.

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    It seems you didn't create a project in the first place.

    Not to worry, just start again by creating a new project (File menu --> new --> project..., select 'opengl' from the 'multimedia' tab of the 'new project' dialog, which will create a basic project for you including some simple base code in which all the basic settings will already be set. You can use the code provided by the project or just -er- copy and paste the code you've been working on into that file, overwriting what's there.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  13. #13
    Registered User
    Join Date
    Jun 2006
    Posts
    16
    Wow...that was probably the nicest Hello World I've done yet. Well...I didn't do it. I didn't make or understand the program to begin with, nor did I understand many of the changes made to it, but I did learn some things. Best of all, now I can move on with my life and by my life I mean struggling with this programming language I shouldn't have even started with to begin with. I'm an artist you know? I have no business with any of this. Well...thanks for your help. I just hope some of the patience of this forum will hold out for any subsequent issues.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGl & SDL issue
    By Arangol in forum Game Programming
    Replies: 3
    Last Post: 06-18-2006, 09:57 AM
  2. SciTe compiling issue C++
    By tio1225 in forum Tech Board
    Replies: 1
    Last Post: 09-18-2005, 12:56 AM
  3. Tutorial #2 issue
    By Keiyentai in forum C++ Programming
    Replies: 7
    Last Post: 03-21-2005, 02:06 AM
  4. compiling and executing issue with lcc win32
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 12-22-2004, 02:24 PM
  5. OpenGL issue...
    By gcn_zelda in forum Windows Programming
    Replies: 2
    Last Post: 05-02-2004, 10:23 AM